summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/tests
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-03-23 03:29:23 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-03-23 03:29:23 (GMT)
commit5fbccff11869d8de54a736e0073ee3a93ff52fdf (patch)
tree4ffc1f02e29c2e3232ed11562edf8599bad7f3a6 /Lib/lib2to3/tests
parentce057d3cbb953f1c3ff119cdae2f1162c4606905 (diff)
downloadcpython-5fbccff11869d8de54a736e0073ee3a93ff52fdf.zip
cpython-5fbccff11869d8de54a736e0073ee3a93ff52fdf.tar.gz
cpython-5fbccff11869d8de54a736e0073ee3a93ff52fdf.tar.bz2
Merged revisions 79327 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r79327 | benjamin.peterson | 2010-03-22 22:22:05 -0500 (Mon, 22 Mar 2010) | 54 lines Merged revisions 79306,79311,79325 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ................ r79306 | benjamin.peterson | 2010-03-22 17:40:06 -0500 (Mon, 22 Mar 2010) | 21 lines Merged revisions 79077,79137,79304-79305 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r79077 | benjamin.peterson | 2010-03-18 18:05:29 -0500 (Thu, 18 Mar 2010) | 1 line port detect_encoding improvements from py3k ........ r79137 | benjamin.peterson | 2010-03-20 11:12:53 -0500 (Sat, 20 Mar 2010) | 1 line add a fixer for setting sys.exitfunc #2356 ........ r79304 | benjamin.peterson | 2010-03-22 17:20:22 -0500 (Mon, 22 Mar 2010) | 1 line fix test_parser when it's run in a path with spaces #7666 ........ r79305 | benjamin.peterson | 2010-03-22 17:27:07 -0500 (Mon, 22 Mar 2010) | 1 line normalize whitespace ........ ................ r79311 | benjamin.peterson | 2010-03-22 17:54:42 -0500 (Mon, 22 Mar 2010) | 9 lines Merged revisions 79309 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r79309 | benjamin.peterson | 2010-03-22 17:50:47 -0500 (Mon, 22 Mar 2010) | 1 line pass correct symbol in ........ ................ r79325 | benjamin.peterson | 2010-03-22 22:03:55 -0500 (Mon, 22 Mar 2010) | 13 lines Merged revisions 79313,79324 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r79313 | benjamin.peterson | 2010-03-22 17:59:57 -0500 (Mon, 22 Mar 2010) | 1 line another case where a symbol is needed ........ r79324 | benjamin.peterson | 2010-03-22 21:59:47 -0500 (Mon, 22 Mar 2010) | 1 line use unicode literals ........ ................ ................
Diffstat (limited to 'Lib/lib2to3/tests')
-rw-r--r--Lib/lib2to3/tests/test_fixers.py88
-rw-r--r--Lib/lib2to3/tests/test_parser.py3
2 files changed, 90 insertions, 1 deletions
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py
index a92f14a..b28c35f 100644
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -4285,3 +4285,91 @@ class Test_operator(FixerTestCase):
def test_bare_sequenceIncludes(self):
s = "sequenceIncludes(x, y)"
self.warns_unchanged(s, "You should use operator.contains here.")
+
+
+class Test_exitfunc(FixerTestCase):
+
+ fixer = "exitfunc"
+
+ def test_simple(self):
+ b = """
+ import sys
+ sys.exitfunc = my_atexit
+ """
+ a = """
+ import sys
+ import atexit
+ atexit.register(my_atexit)
+ """
+ self.check(b, a)
+
+ def test_names_import(self):
+ b = """
+ import sys, crumbs
+ sys.exitfunc = my_func
+ """
+ a = """
+ import sys, crumbs, atexit
+ atexit.register(my_func)
+ """
+ self.check(b, a)
+
+ def test_complex_expression(self):
+ b = """
+ import sys
+ sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
+ """
+ a = """
+ import sys
+ import atexit
+ atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
+ """
+ self.check(b, a)
+
+ def test_comments(self):
+ b = """
+ import sys # Foo
+ sys.exitfunc = f # Blah
+ """
+ a = """
+ import sys
+ import atexit # Foo
+ atexit.register(f) # Blah
+ """
+ self.check(b, a)
+
+ b = """
+ import apples, sys, crumbs, larry # Pleasant comments
+ sys.exitfunc = func
+ """
+ a = """
+ import apples, sys, crumbs, larry, atexit # Pleasant comments
+ atexit.register(func)
+ """
+ self.check(b, a)
+
+ def test_in_a_function(self):
+ b = """
+ import sys
+ def f():
+ sys.exitfunc = func
+ """
+ a = """
+ import sys
+ import atexit
+ def f():
+ atexit.register(func)
+ """
+ self.check(b, a)
+
+ def test_no_sys_import(self):
+ b = """sys.exitfunc = f"""
+ a = """atexit.register(f)"""
+ msg = ("Can't find sys import; Please add an atexit import at the "
+ "top of your file.")
+ self.warns(b, a, msg)
+
+
+ def test_unchanged(self):
+ s = """f(sys.exitfunc)"""
+ self.unchanged(s)
diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py
index 15b109e9..06f3227 100644
--- a/Lib/lib2to3/tests/test_parser.py
+++ b/Lib/lib2to3/tests/test_parser.py
@@ -206,6 +206,7 @@ def diff(fn, result):
finally:
f.close()
try:
- return os.system("diff -u %r @" % fn)
+ fn = fn.replace('"', '\\"')
+ return os.system('diff -u "%s" @' % fn)
finally:
os.remove("@")