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/test_pytree.py | |
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/test_pytree.py')
-rwxr-xr-x | Lib/lib2to3/tests/test_pytree.py | 127 |
1 files changed, 66 insertions, 61 deletions
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__) |