diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-06-11 23:47:38 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-06-11 23:47:38 (GMT) |
commit | 2c3ac6b8757f8fc1dacf6aeaa9a9518d8729d52b (patch) | |
tree | 2c6d71a04c615fc456ec8de0287cd37c4ac7f977 /Lib/lib2to3/tests | |
parent | be40db07c61030d1855a0d173eb30645968d6586 (diff) | |
download | cpython-2c3ac6b8757f8fc1dacf6aeaa9a9518d8729d52b.zip cpython-2c3ac6b8757f8fc1dacf6aeaa9a9518d8729d52b.tar.gz cpython-2c3ac6b8757f8fc1dacf6aeaa9a9518d8729d52b.tar.bz2 |
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
Diffstat (limited to 'Lib/lib2to3/tests')
-rw-r--r-- | Lib/lib2to3/tests/data/different_encoding.py | 3 | ||||
-rw-r--r-- | Lib/lib2to3/tests/data/fixers/myfixes/fix_parrot.py | 2 | ||||
-rw-r--r-- | Lib/lib2to3/tests/data/py2_test_grammar.py | 22 | ||||
-rw-r--r-- | Lib/lib2to3/tests/data/py3_test_grammar.py | 20 | ||||
-rwxr-xr-x | Lib/lib2to3/tests/pytree_idempotency.py | 2 | ||||
-rw-r--r-- | Lib/lib2to3/tests/support.py | 6 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_all_fixers.py | 13 | ||||
-rwxr-xr-x | Lib/lib2to3/tests/test_fixers.py | 100 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_parser.py | 9 | ||||
-rwxr-xr-x | Lib/lib2to3/tests/test_pytree.py | 127 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_util.py | 7 |
11 files changed, 195 insertions, 116 deletions
diff --git a/Lib/lib2to3/tests/data/different_encoding.py b/Lib/lib2to3/tests/data/different_encoding.py index 4bb82bd..888f51f 100644 --- a/Lib/lib2to3/tests/data/different_encoding.py +++ b/Lib/lib2to3/tests/data/different_encoding.py @@ -1,4 +1,3 @@ #!/usr/bin/env python # -*- coding: iso-8859-1 -*- -print(u'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ') - +print u'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ' diff --git a/Lib/lib2to3/tests/data/fixers/myfixes/fix_parrot.py b/Lib/lib2to3/tests/data/fixers/myfixes/fix_parrot.py index 6bd2f49..6db79ad 100644 --- a/Lib/lib2to3/tests/data/fixers/myfixes/fix_parrot.py +++ b/Lib/lib2to3/tests/data/fixers/myfixes/fix_parrot.py @@ -10,4 +10,4 @@ class FixParrot(BaseFix): def transform(self, node, results): name = results["name"] - name.replace(Name("cheese", name.get_prefix())) + name.replace(Name("cheese", name.prefix)) diff --git a/Lib/lib2to3/tests/data/py2_test_grammar.py b/Lib/lib2to3/tests/data/py2_test_grammar.py index dc794e2..17f9f4c 100644 --- a/Lib/lib2to3/tests/data/py2_test_grammar.py +++ b/Lib/lib2to3/tests/data/py2_test_grammar.py @@ -1,5 +1,3 @@ -# Python 2's Lib/test/test_grammar.py (r66189) - # Python test set -- part 1, grammar. # This just tests whether the parser accepts them all. @@ -922,6 +920,26 @@ hello world self.assertEqual([x for x, in [(4,), (5,), (6,)]], [4, 5, 6]) self.assertEqual(list(x for x, in [(7,), (8,), (9,)]), [7, 8, 9]) + def test_with_statement(self): + class manager(object): + def __enter__(self): + return (1, 2) + def __exit__(self, *args): + pass + + with manager(): + pass + with manager() as x: + pass + with manager() as (x, y): + pass + with manager(), manager(): + pass + with manager() as x, manager() as y: + pass + with manager() as x, manager(): + pass + def testIfElseExpr(self): # Test ifelse expressions in various cases def _checkeval(msg, ret): diff --git a/Lib/lib2to3/tests/data/py3_test_grammar.py b/Lib/lib2to3/tests/data/py3_test_grammar.py index eadf1db..977f0b8 100644 --- a/Lib/lib2to3/tests/data/py3_test_grammar.py +++ b/Lib/lib2to3/tests/data/py3_test_grammar.py @@ -868,6 +868,26 @@ class GrammarTests(unittest.TestCase): self.assertEqual([x for x, in [(4,), (5,), (6,)]], [4, 5, 6]) self.assertEqual(list(x for x, in [(7,), (8,), (9,)]), [7, 8, 9]) + def test_with_statement(self): + class manager(object): + def __enter__(self): + return (1, 2) + def __exit__(self, *args): + pass + + with manager(): + pass + with manager() as x: + pass + with manager() as (x, y): + pass + with manager(), manager(): + pass + with manager() as x, manager() as y: + pass + with manager() as x, manager(): + pass + def testIfElseExpr(self): # Test ifelse expressions in various cases def _checkeval(msg, ret): diff --git a/Lib/lib2to3/tests/pytree_idempotency.py b/Lib/lib2to3/tests/pytree_idempotency.py index 3f3ab92..414eb4d 100755 --- a/Lib/lib2to3/tests/pytree_idempotency.py +++ b/Lib/lib2to3/tests/pytree_idempotency.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.5 +#!/usr/bin/env python # Copyright 2006 Google, Inc. All Rights Reserved. # Licensed to PSF under a Contributor Agreement. diff --git a/Lib/lib2to3/tests/support.py b/Lib/lib2to3/tests/support.py index 8b8468c..6f2d214 100644 --- a/Lib/lib2to3/tests/support.py +++ b/Lib/lib2to3/tests/support.py @@ -30,7 +30,7 @@ def run_all_tests(test_mod=None, tests=None): def reformat(string): return dedent(string) + "\n\n" -def get_refactorer(fixers=None, options=None): +def get_refactorer(fixer_pkg="lib2to3", fixers=None, options=None): """ A convenience function for creating a RefactoringTool for tests. @@ -39,9 +39,9 @@ def get_refactorer(fixers=None, options=None): be passed to the RefactoringTool. """ if fixers is not None: - fixers = ["lib2to3.fixes.fix_" + fix for fix in fixers] + fixers = [fixer_pkg + ".fixes.fix_" + fix for fix in fixers] else: - fixers = refactor.get_fixers_from_package("lib2to3.fixes") + fixers = refactor.get_fixers_from_package(fixer_pkg + ".fixes") options = options or {} return refactor.RefactoringTool(fixers, options, explicit=True) diff --git a/Lib/lib2to3/tests/test_all_fixers.py b/Lib/lib2to3/tests/test_all_fixers.py index 1795ade..8ef222d 100644 --- a/Lib/lib2to3/tests/test_all_fixers.py +++ b/Lib/lib2to3/tests/test_all_fixers.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python2.5 """Tests that run all fixer modules over an input stream. This has been broken out into its own test module because of its @@ -6,18 +5,13 @@ running time. """ # Author: Collin Winter -# Testing imports -try: - from . import support -except ImportError: - import support - # Python imports import unittest # Local imports from .. import pytree from .. import refactor +from . import support class Test_all(support.TestCase): @@ -29,8 +23,3 @@ class Test_all(support.TestCase): for filepath in support.all_project_files(): print("Fixing %s..." % filepath) self.refactor.refactor_file(filepath) - - -if __name__ == "__main__": - import __main__ - support.run_all_tests(__main__) diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py index 5076854..2f87fb2 100755 --- a/Lib/lib2to3/tests/test_fixers.py +++ b/Lib/lib2to3/tests/test_fixers.py @@ -1,12 +1,4 @@ -#!/usr/bin/env python2.5 """ Test suite for the fixer modules """ -# Author: Collin Winter - -# Testing imports -try: - from tests import support -except ImportError: - from . import support # Python imports import os @@ -16,14 +8,19 @@ from operator import itemgetter # Local imports from lib2to3 import pygram, pytree, refactor, fixer_util +from lib2to3.tests import support class FixerTestCase(support.TestCase): - def setUp(self, fix_list=None): + + # Other test cases can subclass this class and replace "fixer_pkg" with + # their own. + def setUp(self, fix_list=None, fixer_pkg="lib2to3", options=None): if fix_list is None: fix_list = [self.fixer] - options = {"print_function" : False} - self.refactor = support.get_refactorer(fix_list, options) + if options is None: + options = {"print_function" : False} + self.refactor = support.get_refactorer(fixer_pkg, fix_list, options) self.fixer_log = [] self.filename = "<string>" @@ -62,7 +59,7 @@ class FixerTestCase(support.TestCase): fixes = [self.fixer] fixes.extend(names) options = {"print_function" : False} - r = support.get_refactorer(fixes, options) + r = support.get_refactorer("lib2to3", fixes, options) (pre, post) = r.get_fixers() n = "fix_" + self.fixer if post and post[-1].__class__.__module__.endswith(n): @@ -419,6 +416,7 @@ class Test_print(FixerTestCase): def test_5(self): b = """print; print whatever;""" a = """print(); print(whatever);""" + self.check(b, a) def test_tuple(self): b = """print (a, b, c)""" @@ -782,6 +780,52 @@ class Test_except(FixerTestCase): pass""" self.check(b, a) + def test_one_line_suites(self): + b = """ + try: raise TypeError + except TypeError, e: + pass + """ + a = """ + try: raise TypeError + except TypeError as e: + pass + """ + self.check(b, a) + b = """ + try: + raise TypeError + except TypeError, e: pass + """ + a = """ + try: + raise TypeError + except TypeError as e: pass + """ + self.check(b, a) + b = """ + try: raise TypeError + except TypeError, e: pass + """ + a = """ + try: raise TypeError + except TypeError as e: pass + """ + self.check(b, a) + b = """ + try: raise TypeError + except TypeError, e: pass + else: function() + finally: done() + """ + a = """ + try: raise TypeError + except TypeError as e: pass + else: function() + finally: done() + """ + self.check(b, a) + # These should not be touched: def test_unchanged_1(self): @@ -2640,11 +2684,29 @@ class Test_renames(FixerTestCase): class Test_unicode(FixerTestCase): fixer = "unicode" + def test_whitespace(self): + b = """unicode( x)""" + a = """str( x)""" + self.check(b, a) + + b = """ unicode(x )""" + a = """ str(x )""" + self.check(b, a) + + b = """ u'h'""" + a = """ 'h'""" + self.check(b, a) + def test_unicode_call(self): b = """unicode(x, y, z)""" a = """str(x, y, z)""" self.check(b, a) + def test_unichr(self): + b = """unichr(u'h')""" + a = """chr('h')""" + self.check(b, a) + def test_unicode_literal_1(self): b = '''u"x"''' a = '''"x"''' @@ -2656,8 +2718,8 @@ class Test_unicode(FixerTestCase): self.check(b, a) def test_unicode_literal_3(self): - b = """UR'''x'''""" - a = """R'''x'''""" + b = """UR'''x''' """ + a = """R'''x''' """ self.check(b, a) class Test_callable(FixerTestCase): @@ -3306,6 +3368,11 @@ class Test_buffer(FixerTestCase): a = """x = memoryview(y)""" self.check(b, a) + def test_slicing(self): + b = """buffer(y)[4:5]""" + a = """memoryview(y)[4:5]""" + self.check(b, a) + class Test_future(FixerTestCase): fixer = "future" @@ -4028,8 +4095,3 @@ class Test_getcwdu(FixerTestCase): b = """os.getcwdu ( )""" a = """os.getcwd ( )""" self.check(b, a) - - -if __name__ == "__main__": - import __main__ - support.run_all_tests(__main__) diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py index 2aa737c..08e7bdc 100644 --- a/Lib/lib2to3/tests/test_parser.py +++ b/Lib/lib2to3/tests/test_parser.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python2.5 """Test suite for 2to3's parser and grammar files. This is the place to add tests for changes to 2to3's grammar, such as those @@ -6,7 +5,6 @@ merging the grammars for Python 2 and 3. In addition to specific tests for parts of the grammar we've changed, we also make sure we can parse the test_grammar.py files from both Python 2 and Python 3. """ -# Author: Collin Winter # Testing imports from . import support @@ -198,7 +196,7 @@ class TestLiterals(GrammarTest): def diff(fn, result): - f = open("@", "w") + f = open("@", "wb") try: f.write(result) finally: @@ -207,8 +205,3 @@ def diff(fn, result): return os.system("diff -u %s @" % fn) finally: os.remove("@") - - -if __name__ == "__main__": - import __main__ - support.run_all_tests(__main__) diff --git a/Lib/lib2to3/tests/test_pytree.py b/Lib/lib2to3/tests/test_pytree.py index 9dc6e07..83a9b18 100755 --- a/Lib/lib2to3/tests/test_pytree.py +++ b/Lib/lib2to3/tests/test_pytree.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python2.5 # Copyright 2006 Google, Inc. All Rights Reserved. # Licensed to PSF under a Contributor Agreement. @@ -10,11 +9,12 @@ more helpful than printing of (the first line of) the docstring, especially when debugging a test. """ +import warnings + # Testing imports from . import support -# Local imports (XXX should become a package) -from .. import pytree +from lib2to3 import pytree try: sorted @@ -28,34 +28,48 @@ class TestNodes(support.TestCase): """Unit tests for nodes (Base, Leaf, Node).""" - def testBaseCantConstruct(self): + def test_deprecated_prefix_methods(self): + l = pytree.Leaf(100, "foo") + with warnings.catch_warnings(record=True) as w: + self.assertEqual(l.get_prefix(), "") + l.set_prefix("hi") + self.assertEqual(l.prefix, "hi") + self.assertEqual(len(w), 2) + for warning in w: + self.assertTrue(warning.category is DeprecationWarning) + self.assertEqual(str(w[0].message), "get_prefix() is deprecated; " \ + "use the prefix property") + self.assertEqual(str(w[1].message), "set_prefix() is deprecated; " \ + "use the prefix property") + + def test_instantiate_base(self): if __debug__: # Test that instantiating Base() raises an AssertionError self.assertRaises(AssertionError, pytree.Base) - def testLeaf(self): + def test_leaf(self): l1 = pytree.Leaf(100, "foo") self.assertEqual(l1.type, 100) self.assertEqual(l1.value, "foo") - def testLeafRepr(self): + def test_leaf_repr(self): l1 = pytree.Leaf(100, "foo") self.assertEqual(repr(l1), "Leaf(100, 'foo')") - def testLeafStr(self): + def test_leaf_str(self): l1 = pytree.Leaf(100, "foo") self.assertEqual(str(l1), "foo") l2 = pytree.Leaf(100, "foo", context=(" ", (10, 1))) self.assertEqual(str(l2), " foo") - def testLeafStrNumericValue(self): + def test_leaf_str_numeric_value(self): # Make sure that the Leaf's value is stringified. Failing to # do this can cause a TypeError in certain situations. l1 = pytree.Leaf(2, 5) - l1.set_prefix("foo_") + l1.prefix = "foo_" self.assertEqual(str(l1), "foo_5") - def testLeafEq(self): + def test_leaf_equality(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "foo", context=(" ", (1, 0))) self.assertEqual(l1, l2) @@ -64,67 +78,67 @@ class TestNodes(support.TestCase): self.assertNotEqual(l1, l3) self.assertNotEqual(l1, l4) - def testLeafPrefix(self): + def test_leaf_prefix(self): l1 = pytree.Leaf(100, "foo") - self.assertEqual(l1.get_prefix(), "") + self.assertEqual(l1.prefix, "") self.failIf(l1.was_changed) - l1.set_prefix(" ##\n\n") - self.assertEqual(l1.get_prefix(), " ##\n\n") + l1.prefix = " ##\n\n" + self.assertEqual(l1.prefix, " ##\n\n") self.failUnless(l1.was_changed) - def testNode(self): + def test_node(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(200, "bar") n1 = pytree.Node(1000, [l1, l2]) self.assertEqual(n1.type, 1000) self.assertEqual(n1.children, [l1, l2]) - def testNodeRepr(self): + def test_node_repr(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "bar", context=(" ", (1, 0))) n1 = pytree.Node(1000, [l1, l2]) self.assertEqual(repr(n1), "Node(1000, [%s, %s])" % (repr(l1), repr(l2))) - def testNodeStr(self): + def test_node_str(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "bar", context=(" ", (1, 0))) n1 = pytree.Node(1000, [l1, l2]) self.assertEqual(str(n1), "foo bar") - def testNodePrefix(self): + def test_node_prefix(self): l1 = pytree.Leaf(100, "foo") - self.assertEqual(l1.get_prefix(), "") + self.assertEqual(l1.prefix, "") n1 = pytree.Node(1000, [l1]) - self.assertEqual(n1.get_prefix(), "") - n1.set_prefix(" ") - self.assertEqual(n1.get_prefix(), " ") - self.assertEqual(l1.get_prefix(), " ") + self.assertEqual(n1.prefix, "") + n1.prefix = " " + self.assertEqual(n1.prefix, " ") + self.assertEqual(l1.prefix, " ") - def testGetSuffix(self): + def test_get_suffix(self): l1 = pytree.Leaf(100, "foo", prefix="a") l2 = pytree.Leaf(100, "bar", prefix="b") n1 = pytree.Node(1000, [l1, l2]) - self.assertEqual(l1.get_suffix(), l2.get_prefix()) + self.assertEqual(l1.get_suffix(), l2.prefix) self.assertEqual(l2.get_suffix(), "") self.assertEqual(n1.get_suffix(), "") l3 = pytree.Leaf(100, "bar", prefix="c") n2 = pytree.Node(1000, [n1, l3]) - self.assertEqual(n1.get_suffix(), l3.get_prefix()) + self.assertEqual(n1.get_suffix(), l3.prefix) self.assertEqual(l3.get_suffix(), "") self.assertEqual(n2.get_suffix(), "") - def testNodeEq(self): + def test_node_equality(self): n1 = pytree.Node(1000, ()) n2 = pytree.Node(1000, [], context=(" ", (1, 0))) self.assertEqual(n1, n2) n3 = pytree.Node(1001, ()) self.assertNotEqual(n1, n3) - def testNodeEqRecursive(self): + def test_node_recursive_equality(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "foo") n1 = pytree.Node(1000, [l1]) @@ -134,7 +148,7 @@ class TestNodes(support.TestCase): n3 = pytree.Node(1000, [l3]) self.assertNotEqual(n1, n3) - def testReplace(self): + def test_replace(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "+") l3 = pytree.Leaf(100, "bar") @@ -148,7 +162,7 @@ class TestNodes(support.TestCase): self.failUnless(isinstance(n1.children, list)) self.failUnless(n1.was_changed) - def testReplaceWithList(self): + def test_replace_with_list(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "+") l3 = pytree.Leaf(100, "bar") @@ -158,34 +172,30 @@ class TestNodes(support.TestCase): self.assertEqual(str(n1), "foo**bar") self.failUnless(isinstance(n1.children, list)) - def testPostOrder(self): + def test_post_order(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "bar") n1 = pytree.Node(1000, [l1, l2]) self.assertEqual(list(n1.post_order()), [l1, l2, n1]) - def testPreOrder(self): + def test_pre_order(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "bar") n1 = pytree.Node(1000, [l1, l2]) self.assertEqual(list(n1.pre_order()), [n1, l1, l2]) - def testChangedLeaf(self): + def test_changed(self): l1 = pytree.Leaf(100, "f") self.failIf(l1.was_changed) - l1.changed() self.failUnless(l1.was_changed) - def testChangedNode(self): l1 = pytree.Leaf(100, "f") n1 = pytree.Node(1000, [l1]) self.failIf(n1.was_changed) - n1.changed() self.failUnless(n1.was_changed) - def testChangedRecursive(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "+") l3 = pytree.Leaf(100, "bar") @@ -200,23 +210,23 @@ class TestNodes(support.TestCase): self.failUnless(n2.was_changed) self.failIf(l1.was_changed) - def testLeafConstructorPrefix(self): + def test_leaf_constructor_prefix(self): for prefix in ("xyz_", ""): l1 = pytree.Leaf(100, "self", prefix=prefix) self.failUnless(str(l1), prefix + "self") - self.assertEqual(l1.get_prefix(), prefix) + self.assertEqual(l1.prefix, prefix) - def testNodeConstructorPrefix(self): + def test_node_constructor_prefix(self): for prefix in ("xyz_", ""): l1 = pytree.Leaf(100, "self") l2 = pytree.Leaf(100, "foo", prefix="_") n1 = pytree.Node(1000, [l1, l2], prefix=prefix) self.failUnless(str(n1), prefix + "self_foo") - self.assertEqual(n1.get_prefix(), prefix) - self.assertEqual(l1.get_prefix(), prefix) - self.assertEqual(l2.get_prefix(), "_") + self.assertEqual(n1.prefix, prefix) + self.assertEqual(l1.prefix, prefix) + self.assertEqual(l2.prefix, "_") - def testRemove(self): + def test_remove(self): l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "foo") n1 = pytree.Node(1000, [l1, l2]) @@ -239,7 +249,7 @@ class TestNodes(support.TestCase): self.failUnless(n1.was_changed) self.failUnless(n2.was_changed) - def testRemoveParentless(self): + def test_remove_parentless(self): n1 = pytree.Node(1000, []) n1.remove() self.assertEqual(n1.parent, None) @@ -248,7 +258,7 @@ class TestNodes(support.TestCase): l1.remove() self.assertEqual(l1.parent, None) - def testNodeSetChild(self): + def test_node_set_child(self): l1 = pytree.Leaf(100, "foo") n1 = pytree.Node(1000, [l1]) @@ -269,7 +279,7 @@ class TestNodes(support.TestCase): # I don't care what it raises, so long as it's an exception self.assertRaises(Exception, n1.set_child, 0, list) - def testNodeInsertChild(self): + def test_node_insert_child(self): l1 = pytree.Leaf(100, "foo") n1 = pytree.Node(1000, [l1]) @@ -285,7 +295,7 @@ class TestNodes(support.TestCase): # I don't care what it raises, so long as it's an exception self.assertRaises(Exception, n1.insert_child, 0, list) - def testNodeAppendChild(self): + def test_node_append_child(self): n1 = pytree.Node(1000, []) l1 = pytree.Leaf(100, "foo") @@ -301,7 +311,7 @@ class TestNodes(support.TestCase): # I don't care what it raises, so long as it's an exception self.assertRaises(Exception, n1.append_child, list) - def testNodeNextSibling(self): + def test_node_next_sibling(self): n1 = pytree.Node(1000, []) n2 = pytree.Node(1000, []) p1 = pytree.Node(1000, [n1, n2]) @@ -310,7 +320,7 @@ class TestNodes(support.TestCase): self.assertEqual(n2.next_sibling, None) self.assertEqual(p1.next_sibling, None) - def testLeafNextSibling(self): + def test_leaf_next_sibling(self): l1 = pytree.Leaf(100, "a") l2 = pytree.Leaf(100, "b") p1 = pytree.Node(1000, [l1, l2]) @@ -319,7 +329,7 @@ class TestNodes(support.TestCase): self.assertEqual(l2.next_sibling, None) self.assertEqual(p1.next_sibling, None) - def testNodePrevSibling(self): + def test_node_prev_sibling(self): n1 = pytree.Node(1000, []) n2 = pytree.Node(1000, []) p1 = pytree.Node(1000, [n1, n2]) @@ -328,7 +338,7 @@ class TestNodes(support.TestCase): self.assertEqual(n1.prev_sibling, None) self.assertEqual(p1.prev_sibling, None) - def testLeafPrevSibling(self): + def test_leaf_prev_sibling(self): l1 = pytree.Leaf(100, "a") l2 = pytree.Leaf(100, "b") p1 = pytree.Node(1000, [l1, l2]) @@ -342,7 +352,7 @@ class TestPatterns(support.TestCase): """Unit tests for tree matching patterns.""" - def testBasicPatterns(self): + def test_basic_patterns(self): # Build a tree l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "bar") @@ -378,7 +388,7 @@ class TestPatterns(support.TestCase): self.assertFalse(pn.match(l2, results=r)) self.assertEqual(r, {}) - def testWildcardPatterns(self): + def test_wildcard(self): # Build a tree for testing l1 = pytree.Leaf(100, "foo") l2 = pytree.Leaf(100, "bar") @@ -409,7 +419,7 @@ class TestPatterns(support.TestCase): self.assert_(r["pl"] is l3) r = {} - def testGenerateMatches(self): + def test_generate_matches(self): la = pytree.Leaf(1, "a") lb = pytree.Leaf(1, "b") lc = pytree.Leaf(1, "c") @@ -439,7 +449,7 @@ class TestPatterns(support.TestCase): for c in "abcdef": self.assertEqual(r["p" + c], pytree.Leaf(1, c)) - def testHasKeyExample(self): + def test_has_key_example(self): pattern = pytree.NodePattern(331, (pytree.LeafPattern(7), pytree.WildcardPattern(name="args"), @@ -451,8 +461,3 @@ class TestPatterns(support.TestCase): r = {} self.assert_(pattern.match(node, r)) self.assertEqual(r["args"], [l2]) - - -if __name__ == "__main__": - import __main__ - support.run_all_tests(__main__) diff --git a/Lib/lib2to3/tests/test_util.py b/Lib/lib2to3/tests/test_util.py index 95b566a..1de7a83 100644 --- a/Lib/lib2to3/tests/test_util.py +++ b/Lib/lib2to3/tests/test_util.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python2.5 """ Test suite for the code in fixes.util """ -# Author: Collin Winter # Testing imports from . import support @@ -552,8 +550,3 @@ class Test_touch_import(support.TestCase): node = parse('bar()') fixer_util.touch_import(None, "cgi", node) self.assertEqual(str(node), 'import cgi\nbar()\n\n') - - -if __name__ == "__main__": - import __main__ - support.run_all_tests(__main__) |