summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/tests/test_fixers.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-09-13 18:37:09 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-09-13 18:37:09 (GMT)
commit3a2fb1444ac8d8fefe0d83f4f2d680e64d21a2e2 (patch)
tree4e25d1f79339f646d49bd6fd17b6d0e057b7cc74 /Lib/lib2to3/tests/test_fixers.py
parentc575c9064769d37ac9555b7cd2907c25ab030810 (diff)
downloadcpython-3a2fb1444ac8d8fefe0d83f4f2d680e64d21a2e2.zip
cpython-3a2fb1444ac8d8fefe0d83f4f2d680e64d21a2e2.tar.gz
cpython-3a2fb1444ac8d8fefe0d83f4f2d680e64d21a2e2.tar.bz2
Merged revisions 66453 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ................ r66453 | benjamin.peterson | 2008-09-13 12:43:19 -0500 (Sat, 13 Sep 2008) | 24 lines Merged revisions 66191,66418,66438,66445 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r66191 | benjamin.peterson | 2008-09-03 17:00:52 -0500 (Wed, 03 Sep 2008) | 1 line update the Grammar file after recent syntax changes ........ r66418 | benjamin.peterson | 2008-09-12 18:49:48 -0500 (Fri, 12 Sep 2008) | 1 line a trival fix to get a few more print corner cases #2899 ........ r66438 | benjamin.peterson | 2008-09-12 21:32:30 -0500 (Fri, 12 Sep 2008) | 5 lines add Jack Diederich's fixer for metaclass syntax #2366 my contribution to this was adding a few tests and fixing a few bugs I also reviewed it (Jack is a committer) ........ r66445 | benjamin.peterson | 2008-09-13 10:50:00 -0500 (Sat, 13 Sep 2008) | 1 line add a few more tests concerning int literals and weird spacing ........ ................
Diffstat (limited to 'Lib/lib2to3/tests/test_fixers.py')
-rwxr-xr-xLib/lib2to3/tests/test_fixers.py146
1 files changed, 146 insertions, 0 deletions
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py
index eb5a939..91d51cf 100755
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -385,6 +385,16 @@ class Test_print(FixerTestCase):
a = """print()"""
self.check(b, a)
+ def test_4(self):
+ # from bug 3000
+ b = """print whatever; print"""
+ a = """print(whatever); print()"""
+ self.check(b, a)
+
+ def test_5(self):
+ b = """print; print whatever;"""
+ a = """print(); print(whatever);"""
+
def test_tuple(self):
b = """print (a, b, c)"""
a = """print((a, b, c))"""
@@ -2379,6 +2389,15 @@ class Test_numliterals(FixerTestCase):
a = """b = 0x12"""
self.check(b, a)
+ def test_comments_and_spacing(self):
+ b = """b = 0x12L"""
+ a = """b = 0x12"""
+ self.check(b, a)
+
+ b = """b = 0755 # spam"""
+ a = """b = 0o755 # spam"""
+ self.check(b, a)
+
def test_unchanged_int(self):
s = """5"""
self.unchanged(s)
@@ -3430,6 +3449,133 @@ class Test_paren(FixerTestCase):
s = """[i for i in m]"""
self.unchanged(s)
+class Test_metaclass(FixerTestCase):
+
+ fixer = 'metaclass'
+
+ def test_unchanged(self):
+ self.unchanged("class X(): pass")
+ self.unchanged("class X(object): pass")
+ self.unchanged("class X(object1, object2): pass")
+ self.unchanged("class X(object1, object2, object3): pass")
+ self.unchanged("class X(metaclass=Meta): pass")
+ self.unchanged("class X(b, arg=23, metclass=Meta): pass")
+ self.unchanged("class X(b, arg=23, metaclass=Meta, other=42): pass")
+
+ s = """
+ class X:
+ def __metaclass__(self): pass
+ """
+ self.unchanged(s)
+
+ def test_comments(self):
+ b = """
+ class X:
+ # hi
+ __metaclass__ = AppleMeta
+ """
+ a = """
+ class X(metaclass=AppleMeta):
+ # hi
+ pass
+ """
+ self.check(b, a)
+
+ b = """
+ class X:
+ __metaclass__ = Meta
+ # Bedtime!
+ """
+ a = """
+ class X(metaclass=Meta):
+ pass
+ # Bedtime!
+ """
+ self.check(b, a)
+
+ def test_meta(self):
+ # no-parent class, odd body
+ b = """
+ class X():
+ __metaclass__ = Q
+ pass
+ """
+ a = """
+ class X(metaclass=Q):
+ pass
+ """
+ self.check(b, a)
+
+ # one parent class, no body
+ b = """class X(object): __metaclass__ = Q"""
+ a = """class X(object, metaclass=Q): pass"""
+ self.check(b, a)
+
+
+ # one parent, simple body
+ b = """
+ class X(object):
+ __metaclass__ = Meta
+ bar = 7
+ """
+ a = """
+ class X(object, metaclass=Meta):
+ bar = 7
+ """
+ self.check(b, a)
+
+ b = """
+ class X:
+ __metaclass__ = Meta; x = 4; g = 23
+ """
+ a = """
+ class X(metaclass=Meta):
+ x = 4; g = 23
+ """
+ self.check(b, a)
+
+ # one parent, simple body, __metaclass__ last
+ b = """
+ class X(object):
+ bar = 7
+ __metaclass__ = Meta
+ """
+ a = """
+ class X(object, metaclass=Meta):
+ bar = 7
+ """
+ self.check(b, a)
+
+ # redefining __metaclass__
+ b = """
+ class X():
+ __metaclass__ = A
+ __metaclass__ = B
+ bar = 7
+ """
+ a = """
+ class X(metaclass=B):
+ bar = 7
+ """
+ self.check(b, a)
+
+ # multiple inheritance, simple body
+ b = """
+ class X(clsA, clsB):
+ __metaclass__ = Meta
+ bar = 7
+ """
+ a = """
+ class X(clsA, clsB, metaclass=Meta):
+ bar = 7
+ """
+ self.check(b, a)
+
+ # keywords in the class statement
+ b = """class m(a, arg=23): __metaclass__ = Meta"""
+ a = """class m(a, arg=23, metaclass=Meta): pass"""
+ self.check(b, a)
+
if __name__ == "__main__":
import __main__