diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-12-29 00:44:14 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-12-29 00:44:14 (GMT) |
commit | d56a5d715621502ae33b87096a9ca24130e064f9 (patch) | |
tree | 298f2ca639a5a27194aa8026fa6dc91fb38ead55 /Lib/lib2to3/tests/test_fixers.py | |
parent | 7af837a423040af2472756c2fb9e708e6243ce85 (diff) | |
download | cpython-d56a5d715621502ae33b87096a9ca24130e064f9.zip cpython-d56a5d715621502ae33b87096a9ca24130e064f9.tar.gz cpython-d56a5d715621502ae33b87096a9ca24130e064f9.tar.bz2 |
Merged revisions 77103,77105-77106 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77103 | benjamin.peterson | 2009-12-28 18:06:20 -0600 (Mon, 28 Dec 2009) | 57 lines
Merged revisions 77102 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r77102 | benjamin.peterson | 2009-12-28 17:50:41 -0600 (Mon, 28 Dec 2009) | 50 lines
Merged revisions 76871-76872,77093-77095,77097-77101 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76871 | benjamin.peterson | 2009-12-17 20:49:21 -0600 (Thu, 17 Dec 2009) | 1 line
handle unencodable diffs gracefully #5093
........
r76872 | benjamin.peterson | 2009-12-17 20:51:37 -0600 (Thu, 17 Dec 2009) | 1 line
fix emacs header
........
r77093 | benjamin.peterson | 2009-12-28 14:43:32 -0600 (Mon, 28 Dec 2009) | 7 lines
replace callable(x) with isinstance(x, collections.Callable) #7006
This is a more accurate translation than hasattr(x, '__call__') which failed in
the case that somebody had put __call__ in the instance dictionary.
Patch mostly by Joe Amenta.
........
r77094 | benjamin.peterson | 2009-12-28 14:45:13 -0600 (Mon, 28 Dec 2009) | 2 lines
deuglify imports
........
r77095 | benjamin.peterson | 2009-12-28 14:49:23 -0600 (Mon, 28 Dec 2009) | 1 line
remove unused flag
........
r77097 | benjamin.peterson | 2009-12-28 16:12:13 -0600 (Mon, 28 Dec 2009) | 2 lines
clean up imports and whitespace
........
r77098 | benjamin.peterson | 2009-12-28 16:43:35 -0600 (Mon, 28 Dec 2009) | 1 line
*** empty log message ***
........
r77099 | benjamin.peterson | 2009-12-28 16:45:10 -0600 (Mon, 28 Dec 2009) | 1 line
revert unintended change
........
r77100 | benjamin.peterson | 2009-12-28 16:53:21 -0600 (Mon, 28 Dec 2009) | 1 line
revert unintended changes
........
r77101 | benjamin.peterson | 2009-12-28 17:46:02 -0600 (Mon, 28 Dec 2009) | 1 line
normalize whitespace
........
................
................
r77105 | benjamin.peterson | 2009-12-28 18:37:04 -0600 (Mon, 28 Dec 2009) | 1 line
fix test on py3
................
r77106 | benjamin.peterson | 2009-12-28 18:38:47 -0600 (Mon, 28 Dec 2009) | 9 lines
Merged revisions 77104 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77104 | benjamin.peterson | 2009-12-28 18:09:33 -0600 (Mon, 28 Dec 2009) | 1 line
enable test_main.py
........
................
Diffstat (limited to 'Lib/lib2to3/tests/test_fixers.py')
-rwxr-xr-x | Lib/lib2to3/tests/test_fixers.py | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py index ea361de..2e0092f 100755 --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/lib2to3/tests/test_fixers.py @@ -2725,16 +2725,79 @@ class Test_callable(FixerTestCase): def test_prefix_preservation(self): b = """callable( x)""" - a = """hasattr( x, '__call__')""" + a = """import collections\nisinstance( x, collections.Callable)""" self.check(b, a) b = """if callable(x): pass""" - a = """if hasattr(x, '__call__'): pass""" + a = """import collections +if isinstance(x, collections.Callable): pass""" self.check(b, a) def test_callable_call(self): b = """callable(x)""" - a = """hasattr(x, '__call__')""" + a = """import collections\nisinstance(x, collections.Callable)""" + self.check(b, a) + + def test_global_import(self): + b = """ +def spam(foo): + callable(foo)"""[1:] + a = """ +import collections +def spam(foo): + isinstance(foo, collections.Callable)"""[1:] + self.check(b, a) + + b = """ +import collections +def spam(foo): + callable(foo)"""[1:] + # same output if it was already imported + self.check(b, a) + + b = """ +from collections import * +def spam(foo): + callable(foo)"""[1:] + a = """ +from collections import * +import collections +def spam(foo): + isinstance(foo, collections.Callable)"""[1:] + self.check(b, a) + + b = """ +do_stuff() +do_some_other_stuff() +assert callable(do_stuff)"""[1:] + a = """ +import collections +do_stuff() +do_some_other_stuff() +assert isinstance(do_stuff, collections.Callable)"""[1:] + self.check(b, a) + + b = """ +if isinstance(do_stuff, Callable): + assert callable(do_stuff) + do_stuff(do_stuff) + if not callable(do_stuff): + exit(1) + else: + assert callable(do_stuff) +else: + assert not callable(do_stuff)"""[1:] + a = """ +import collections +if isinstance(do_stuff, Callable): + assert isinstance(do_stuff, collections.Callable) + do_stuff(do_stuff) + if not isinstance(do_stuff, collections.Callable): + exit(1) + else: + assert isinstance(do_stuff, collections.Callable) +else: + assert not isinstance(do_stuff, collections.Callable)"""[1:] self.check(b, a) def test_callable_should_not_change(self): |