summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-07-01 01:15:26 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-07-01 01:15:26 (GMT)
commit731371268e62608725267f127e228f777153fe49 (patch)
treeb9c9b81ca4018b5ada303a1f7acbc4a2e2cad771 /Lib/lib2to3
parent41a28734b41610c91cf3013b4af8ac490c94c801 (diff)
downloadcpython-731371268e62608725267f127e228f777153fe49.zip
cpython-731371268e62608725267f127e228f777153fe49.tar.gz
cpython-731371268e62608725267f127e228f777153fe49.tar.bz2
Merged revisions 73727 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r73727 | benjamin.peterson | 2009-06-30 20:06:56 -0500 (Tue, 30 Jun 2009) | 28 lines Merged revisions 73725 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ................ r73725 | benjamin.peterson | 2009-06-30 19:49:09 -0500 (Tue, 30 Jun 2009) | 21 lines Merged revisions 73379,73388,73507,73722 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r73379 | benjamin.peterson | 2009-06-11 18:06:21 -0500 (Thu, 11 Jun 2009) | 1 line use a real conditional expresion ........ r73388 | benjamin.peterson | 2009-06-12 09:44:29 -0500 (Fri, 12 Jun 2009) | 1 line fix typo in last fix ........ r73507 | benjamin.peterson | 2009-06-22 13:32:04 -0500 (Mon, 22 Jun 2009) | 1 line remove svn:executable property ........ r73722 | benjamin.peterson | 2009-06-30 19:44:30 -0500 (Tue, 30 Jun 2009) | 1 line replace fail* with assert* ........ ................ ................
Diffstat (limited to 'Lib/lib2to3')
-rw-r--r--Lib/lib2to3/fixes/fix_dict.py2
-rw-r--r--[-rwxr-xr-x]Lib/lib2to3/refactor.py0
-rwxr-xr-xLib/lib2to3/tests/test_fixers.py12
-rwxr-xr-xLib/lib2to3/tests/test_pytree.py58
-rw-r--r--Lib/lib2to3/tests/test_util.py294
5 files changed, 183 insertions, 183 deletions
diff --git a/Lib/lib2to3/fixes/fix_dict.py b/Lib/lib2to3/fixes/fix_dict.py
index ce973fd..7c37fad 100644
--- a/Lib/lib2to3/fixes/fix_dict.py
+++ b/Lib/lib2to3/fixes/fix_dict.py
@@ -66,7 +66,7 @@ class FixDict(fixer_base.BaseFix):
new = pytree.Node(syms.power, args)
if not special:
new.prefix = ""
- new = Call(Name(isiter and "iter" or "list"), [new])
+ new = Call(Name("iter" if isiter else "list"), [new])
if tail:
new = pytree.Node(syms.power, [new] + tail)
new.prefix = node.prefix
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index c5398c8..c5398c8 100755..100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py
index 2f87fb2..c0f1e37 100755
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -32,20 +32,20 @@ class FixerTestCase(support.TestCase):
before = support.reformat(before)
after = support.reformat(after)
tree = self.refactor.refactor_string(before, self.filename)
- self.failUnlessEqual(after, str(tree))
+ self.assertEqual(after, str(tree))
return tree
def check(self, before, after, ignore_warnings=False):
tree = self._check(before, after)
- self.failUnless(tree.was_changed)
+ self.assertTrue(tree.was_changed)
if not ignore_warnings:
- self.failUnlessEqual(self.fixer_log, [])
+ self.assertEqual(self.fixer_log, [])
def warns(self, before, after, message, unchanged=False):
tree = self._check(before, after)
- self.failUnless(message in "".join(self.fixer_log))
+ self.assertTrue(message in "".join(self.fixer_log))
if not unchanged:
- self.failUnless(tree.was_changed)
+ self.assertTrue(tree.was_changed)
def warns_unchanged(self, before, message):
self.warns(before, before, message, unchanged=True)
@@ -53,7 +53,7 @@ class FixerTestCase(support.TestCase):
def unchanged(self, before, ignore_warnings=False):
self._check(before, before)
if not ignore_warnings:
- self.failUnlessEqual(self.fixer_log, [])
+ self.assertEqual(self.fixer_log, [])
def assert_runs_after(self, *names):
fixes = [self.fixer]
diff --git a/Lib/lib2to3/tests/test_pytree.py b/Lib/lib2to3/tests/test_pytree.py
index 83a9b18..a162aae 100755
--- a/Lib/lib2to3/tests/test_pytree.py
+++ b/Lib/lib2to3/tests/test_pytree.py
@@ -81,10 +81,10 @@ class TestNodes(support.TestCase):
def test_leaf_prefix(self):
l1 = pytree.Leaf(100, "foo")
self.assertEqual(l1.prefix, "")
- self.failIf(l1.was_changed)
+ self.assertFalse(l1.was_changed)
l1.prefix = " ##\n\n"
self.assertEqual(l1.prefix, " ##\n\n")
- self.failUnless(l1.was_changed)
+ self.assertTrue(l1.was_changed)
def test_node(self):
l1 = pytree.Leaf(100, "foo")
@@ -154,13 +154,13 @@ class TestNodes(support.TestCase):
l3 = pytree.Leaf(100, "bar")
n1 = pytree.Node(1000, [l1, l2, l3])
self.assertEqual(n1.children, [l1, l2, l3])
- self.failUnless(isinstance(n1.children, list))
- self.failIf(n1.was_changed)
+ self.assertTrue(isinstance(n1.children, list))
+ self.assertFalse(n1.was_changed)
l2new = pytree.Leaf(100, "-")
l2.replace(l2new)
self.assertEqual(n1.children, [l1, l2new, l3])
- self.failUnless(isinstance(n1.children, list))
- self.failUnless(n1.was_changed)
+ self.assertTrue(isinstance(n1.children, list))
+ self.assertTrue(n1.was_changed)
def test_replace_with_list(self):
l1 = pytree.Leaf(100, "foo")
@@ -170,7 +170,7 @@ class TestNodes(support.TestCase):
l2.replace([pytree.Leaf(100, "*"), pytree.Leaf(100, "*")])
self.assertEqual(str(n1), "foo**bar")
- self.failUnless(isinstance(n1.children, list))
+ self.assertTrue(isinstance(n1.children, list))
def test_post_order(self):
l1 = pytree.Leaf(100, "foo")
@@ -186,34 +186,34 @@ class TestNodes(support.TestCase):
def test_changed(self):
l1 = pytree.Leaf(100, "f")
- self.failIf(l1.was_changed)
+ self.assertFalse(l1.was_changed)
l1.changed()
- self.failUnless(l1.was_changed)
+ self.assertTrue(l1.was_changed)
l1 = pytree.Leaf(100, "f")
n1 = pytree.Node(1000, [l1])
- self.failIf(n1.was_changed)
+ self.assertFalse(n1.was_changed)
n1.changed()
- self.failUnless(n1.was_changed)
+ self.assertTrue(n1.was_changed)
l1 = pytree.Leaf(100, "foo")
l2 = pytree.Leaf(100, "+")
l3 = pytree.Leaf(100, "bar")
n1 = pytree.Node(1000, [l1, l2, l3])
n2 = pytree.Node(1000, [n1])
- self.failIf(l1.was_changed)
- self.failIf(n1.was_changed)
- self.failIf(n2.was_changed)
+ self.assertFalse(l1.was_changed)
+ self.assertFalse(n1.was_changed)
+ self.assertFalse(n2.was_changed)
n1.changed()
- self.failUnless(n1.was_changed)
- self.failUnless(n2.was_changed)
- self.failIf(l1.was_changed)
+ self.assertTrue(n1.was_changed)
+ self.assertTrue(n2.was_changed)
+ self.assertFalse(l1.was_changed)
def test_leaf_constructor_prefix(self):
for prefix in ("xyz_", ""):
l1 = pytree.Leaf(100, "self", prefix=prefix)
- self.failUnless(str(l1), prefix + "self")
+ self.assertTrue(str(l1), prefix + "self")
self.assertEqual(l1.prefix, prefix)
def test_node_constructor_prefix(self):
@@ -221,7 +221,7 @@ class TestNodes(support.TestCase):
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.assertTrue(str(n1), prefix + "self_foo")
self.assertEqual(n1.prefix, prefix)
self.assertEqual(l1.prefix, prefix)
self.assertEqual(l2.prefix, "_")
@@ -237,8 +237,8 @@ class TestNodes(support.TestCase):
self.assertEqual(l1.parent, n1)
self.assertEqual(n1.parent, None)
self.assertEqual(n2.parent, None)
- self.failIf(n1.was_changed)
- self.failUnless(n2.was_changed)
+ self.assertFalse(n1.was_changed)
+ self.assertTrue(n2.was_changed)
self.assertEqual(l2.remove(), 1)
self.assertEqual(l1.remove(), 0)
@@ -246,8 +246,8 @@ class TestNodes(support.TestCase):
self.assertEqual(l1.parent, None)
self.assertEqual(n1.parent, None)
self.assertEqual(n2.parent, None)
- self.failUnless(n1.was_changed)
- self.failUnless(n2.was_changed)
+ self.assertTrue(n1.was_changed)
+ self.assertTrue(n2.was_changed)
def test_remove_parentless(self):
n1 = pytree.Node(1000, [])
@@ -316,7 +316,7 @@ class TestNodes(support.TestCase):
n2 = pytree.Node(1000, [])
p1 = pytree.Node(1000, [n1, n2])
- self.failUnless(n1.next_sibling is n2)
+ self.assertTrue(n1.next_sibling is n2)
self.assertEqual(n2.next_sibling, None)
self.assertEqual(p1.next_sibling, None)
@@ -325,7 +325,7 @@ class TestNodes(support.TestCase):
l2 = pytree.Leaf(100, "b")
p1 = pytree.Node(1000, [l1, l2])
- self.failUnless(l1.next_sibling is l2)
+ self.assertTrue(l1.next_sibling is l2)
self.assertEqual(l2.next_sibling, None)
self.assertEqual(p1.next_sibling, None)
@@ -334,7 +334,7 @@ class TestNodes(support.TestCase):
n2 = pytree.Node(1000, [])
p1 = pytree.Node(1000, [n1, n2])
- self.failUnless(n2.prev_sibling is n1)
+ self.assertTrue(n2.prev_sibling is n1)
self.assertEqual(n1.prev_sibling, None)
self.assertEqual(p1.prev_sibling, None)
@@ -343,7 +343,7 @@ class TestNodes(support.TestCase):
l2 = pytree.Leaf(100, "b")
p1 = pytree.Node(1000, [l1, l2])
- self.failUnless(l2.prev_sibling is l1)
+ self.assertTrue(l2.prev_sibling is l1)
self.assertEqual(l1.prev_sibling, None)
self.assertEqual(p1.prev_sibling, None)
@@ -416,7 +416,7 @@ class TestPatterns(support.TestCase):
r = {}
self.assertTrue(pw.match_seq([l1, l3], r))
self.assertEqual(r, {"pl": l3, "pw": [l1, l3]})
- self.assert_(r["pl"] is l3)
+ self.assertTrue(r["pl"] is l3)
r = {}
def test_generate_matches(self):
@@ -459,5 +459,5 @@ class TestPatterns(support.TestCase):
l3 = pytree.Leaf(8, ")")
node = pytree.Node(331, [l1, l2, l3])
r = {}
- self.assert_(pattern.match(node, r))
+ self.assertTrue(pattern.match(node, r))
self.assertEqual(r["args"], [l2])
diff --git a/Lib/lib2to3/tests/test_util.py b/Lib/lib2to3/tests/test_util.py
index 1de7a83..ef3256d 100644
--- a/Lib/lib2to3/tests/test_util.py
+++ b/Lib/lib2to3/tests/test_util.py
@@ -33,15 +33,15 @@ class Test_is_tuple(support.TestCase):
return fixer_util.is_tuple(parse(string, strip_levels=2))
def test_valid(self):
- self.failUnless(self.is_tuple("(a, b)"))
- self.failUnless(self.is_tuple("(a, (b, c))"))
- self.failUnless(self.is_tuple("((a, (b, c)),)"))
- self.failUnless(self.is_tuple("(a,)"))
- self.failUnless(self.is_tuple("()"))
+ self.assertTrue(self.is_tuple("(a, b)"))
+ self.assertTrue(self.is_tuple("(a, (b, c))"))
+ self.assertTrue(self.is_tuple("((a, (b, c)),)"))
+ self.assertTrue(self.is_tuple("(a,)"))
+ self.assertTrue(self.is_tuple("()"))
def test_invalid(self):
- self.failIf(self.is_tuple("(a)"))
- self.failIf(self.is_tuple("('foo') % (b, c)"))
+ self.assertFalse(self.is_tuple("(a)"))
+ self.assertFalse(self.is_tuple("('foo') % (b, c)"))
class Test_is_list(support.TestCase):
@@ -49,14 +49,14 @@ class Test_is_list(support.TestCase):
return fixer_util.is_list(parse(string, strip_levels=2))
def test_valid(self):
- self.failUnless(self.is_list("[]"))
- self.failUnless(self.is_list("[a]"))
- self.failUnless(self.is_list("[a, b]"))
- self.failUnless(self.is_list("[a, [b, c]]"))
- self.failUnless(self.is_list("[[a, [b, c]],]"))
+ self.assertTrue(self.is_list("[]"))
+ self.assertTrue(self.is_list("[a]"))
+ self.assertTrue(self.is_list("[a, b]"))
+ self.assertTrue(self.is_list("[a, [b, c]]"))
+ self.assertTrue(self.is_list("[[a, [b, c]],]"))
def test_invalid(self):
- self.failIf(self.is_list("[]+[]"))
+ self.assertFalse(self.is_list("[]+[]"))
class Test_Attr(MacroTestCase):
@@ -102,9 +102,9 @@ class Test_does_tree_import(support.TestCase):
(None, "a", "import b, c, d"))
for package, name, import_ in failing_tests:
n = self.does_tree_import(package, name, import_ + "\n" + string)
- self.failIf(n)
+ self.assertFalse(n)
n = self.does_tree_import(package, name, string + "\n" + import_)
- self.failIf(n)
+ self.assertFalse(n)
passing_tests = (("a", "a", "from a import a"),
("x", "a", "from x import a"),
@@ -115,9 +115,9 @@ class Test_does_tree_import(support.TestCase):
(None, "a", "import b, c, a, d"))
for package, name, import_ in passing_tests:
n = self.does_tree_import(package, name, import_ + "\n" + string)
- self.failUnless(n)
+ self.assertTrue(n)
n = self.does_tree_import(package, name, string + "\n" + import_)
- self.failUnless(n)
+ self.assertTrue(n)
def test_in_function(self):
self.try_with("def foo():\n\tbar.baz()\n\tstart=3")
@@ -127,226 +127,226 @@ class Test_find_binding(support.TestCase):
return fixer_util.find_binding(name, parse(string), package)
def test_simple_assignment(self):
- self.failUnless(self.find_binding("a", "a = b"))
- self.failUnless(self.find_binding("a", "a = [b, c, d]"))
- self.failUnless(self.find_binding("a", "a = foo()"))
- self.failUnless(self.find_binding("a", "a = foo().foo.foo[6][foo]"))
- self.failIf(self.find_binding("a", "foo = a"))
- self.failIf(self.find_binding("a", "foo = (a, b, c)"))
+ self.assertTrue(self.find_binding("a", "a = b"))
+ self.assertTrue(self.find_binding("a", "a = [b, c, d]"))
+ self.assertTrue(self.find_binding("a", "a = foo()"))
+ self.assertTrue(self.find_binding("a", "a = foo().foo.foo[6][foo]"))
+ self.assertFalse(self.find_binding("a", "foo = a"))
+ self.assertFalse(self.find_binding("a", "foo = (a, b, c)"))
def test_tuple_assignment(self):
- self.failUnless(self.find_binding("a", "(a,) = b"))
- self.failUnless(self.find_binding("a", "(a, b, c) = [b, c, d]"))
- self.failUnless(self.find_binding("a", "(c, (d, a), b) = foo()"))
- self.failUnless(self.find_binding("a", "(a, b) = foo().foo[6][foo]"))
- self.failIf(self.find_binding("a", "(foo, b) = (b, a)"))
- self.failIf(self.find_binding("a", "(foo, (b, c)) = (a, b, c)"))
+ self.assertTrue(self.find_binding("a", "(a,) = b"))
+ self.assertTrue(self.find_binding("a", "(a, b, c) = [b, c, d]"))
+ self.assertTrue(self.find_binding("a", "(c, (d, a), b) = foo()"))
+ self.assertTrue(self.find_binding("a", "(a, b) = foo().foo[6][foo]"))
+ self.assertFalse(self.find_binding("a", "(foo, b) = (b, a)"))
+ self.assertFalse(self.find_binding("a", "(foo, (b, c)) = (a, b, c)"))
def test_list_assignment(self):
- self.failUnless(self.find_binding("a", "[a] = b"))
- self.failUnless(self.find_binding("a", "[a, b, c] = [b, c, d]"))
- self.failUnless(self.find_binding("a", "[c, [d, a], b] = foo()"))
- self.failUnless(self.find_binding("a", "[a, b] = foo().foo[a][foo]"))
- self.failIf(self.find_binding("a", "[foo, b] = (b, a)"))
- self.failIf(self.find_binding("a", "[foo, [b, c]] = (a, b, c)"))
+ self.assertTrue(self.find_binding("a", "[a] = b"))
+ self.assertTrue(self.find_binding("a", "[a, b, c] = [b, c, d]"))
+ self.assertTrue(self.find_binding("a", "[c, [d, a], b] = foo()"))
+ self.assertTrue(self.find_binding("a", "[a, b] = foo().foo[a][foo]"))
+ self.assertFalse(self.find_binding("a", "[foo, b] = (b, a)"))
+ self.assertFalse(self.find_binding("a", "[foo, [b, c]] = (a, b, c)"))
def test_invalid_assignments(self):
- self.failIf(self.find_binding("a", "foo.a = 5"))
- self.failIf(self.find_binding("a", "foo[a] = 5"))
- self.failIf(self.find_binding("a", "foo(a) = 5"))
- self.failIf(self.find_binding("a", "foo(a, b) = 5"))
+ self.assertFalse(self.find_binding("a", "foo.a = 5"))
+ self.assertFalse(self.find_binding("a", "foo[a] = 5"))
+ self.assertFalse(self.find_binding("a", "foo(a) = 5"))
+ self.assertFalse(self.find_binding("a", "foo(a, b) = 5"))
def test_simple_import(self):
- self.failUnless(self.find_binding("a", "import a"))
- self.failUnless(self.find_binding("a", "import b, c, a, d"))
- self.failIf(self.find_binding("a", "import b"))
- self.failIf(self.find_binding("a", "import b, c, d"))
+ self.assertTrue(self.find_binding("a", "import a"))
+ self.assertTrue(self.find_binding("a", "import b, c, a, d"))
+ self.assertFalse(self.find_binding("a", "import b"))
+ self.assertFalse(self.find_binding("a", "import b, c, d"))
def test_from_import(self):
- self.failUnless(self.find_binding("a", "from x import a"))
- self.failUnless(self.find_binding("a", "from a import a"))
- self.failUnless(self.find_binding("a", "from x import b, c, a, d"))
- self.failUnless(self.find_binding("a", "from x.b import a"))
- self.failUnless(self.find_binding("a", "from x.b import b, c, a, d"))
- self.failIf(self.find_binding("a", "from a import b"))
- self.failIf(self.find_binding("a", "from a.d import b"))
- self.failIf(self.find_binding("a", "from d.a import b"))
+ self.assertTrue(self.find_binding("a", "from x import a"))
+ self.assertTrue(self.find_binding("a", "from a import a"))
+ self.assertTrue(self.find_binding("a", "from x import b, c, a, d"))
+ self.assertTrue(self.find_binding("a", "from x.b import a"))
+ self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d"))
+ self.assertFalse(self.find_binding("a", "from a import b"))
+ self.assertFalse(self.find_binding("a", "from a.d import b"))
+ self.assertFalse(self.find_binding("a", "from d.a import b"))
def test_import_as(self):
- self.failUnless(self.find_binding("a", "import b as a"))
- self.failUnless(self.find_binding("a", "import b as a, c, a as f, d"))
- self.failIf(self.find_binding("a", "import a as f"))
- self.failIf(self.find_binding("a", "import b, c as f, d as e"))
+ self.assertTrue(self.find_binding("a", "import b as a"))
+ self.assertTrue(self.find_binding("a", "import b as a, c, a as f, d"))
+ self.assertFalse(self.find_binding("a", "import a as f"))
+ self.assertFalse(self.find_binding("a", "import b, c as f, d as e"))
def test_from_import_as(self):
- self.failUnless(self.find_binding("a", "from x import b as a"))
- self.failUnless(self.find_binding("a", "from x import g as a, d as b"))
- self.failUnless(self.find_binding("a", "from x.b import t as a"))
- self.failUnless(self.find_binding("a", "from x.b import g as a, d"))
- self.failIf(self.find_binding("a", "from a import b as t"))
- self.failIf(self.find_binding("a", "from a.d import b as t"))
- self.failIf(self.find_binding("a", "from d.a import b as t"))
+ self.assertTrue(self.find_binding("a", "from x import b as a"))
+ self.assertTrue(self.find_binding("a", "from x import g as a, d as b"))
+ self.assertTrue(self.find_binding("a", "from x.b import t as a"))
+ self.assertTrue(self.find_binding("a", "from x.b import g as a, d"))
+ self.assertFalse(self.find_binding("a", "from a import b as t"))
+ self.assertFalse(self.find_binding("a", "from a.d import b as t"))
+ self.assertFalse(self.find_binding("a", "from d.a import b as t"))
def test_simple_import_with_package(self):
- self.failUnless(self.find_binding("b", "import b"))
- self.failUnless(self.find_binding("b", "import b, c, d"))
- self.failIf(self.find_binding("b", "import b", "b"))
- self.failIf(self.find_binding("b", "import b, c, d", "c"))
+ self.assertTrue(self.find_binding("b", "import b"))
+ self.assertTrue(self.find_binding("b", "import b, c, d"))
+ self.assertFalse(self.find_binding("b", "import b", "b"))
+ self.assertFalse(self.find_binding("b", "import b, c, d", "c"))
def test_from_import_with_package(self):
- self.failUnless(self.find_binding("a", "from x import a", "x"))
- self.failUnless(self.find_binding("a", "from a import a", "a"))
- self.failUnless(self.find_binding("a", "from x import *", "x"))
- self.failUnless(self.find_binding("a", "from x import b, c, a, d", "x"))
- self.failUnless(self.find_binding("a", "from x.b import a", "x.b"))
- self.failUnless(self.find_binding("a", "from x.b import *", "x.b"))
- self.failUnless(self.find_binding("a", "from x.b import b, c, a, d", "x.b"))
- self.failIf(self.find_binding("a", "from a import b", "a"))
- self.failIf(self.find_binding("a", "from a.d import b", "a.d"))
- self.failIf(self.find_binding("a", "from d.a import b", "a.d"))
- self.failIf(self.find_binding("a", "from x.y import *", "a.b"))
+ self.assertTrue(self.find_binding("a", "from x import a", "x"))
+ self.assertTrue(self.find_binding("a", "from a import a", "a"))
+ self.assertTrue(self.find_binding("a", "from x import *", "x"))
+ self.assertTrue(self.find_binding("a", "from x import b, c, a, d", "x"))
+ self.assertTrue(self.find_binding("a", "from x.b import a", "x.b"))
+ self.assertTrue(self.find_binding("a", "from x.b import *", "x.b"))
+ self.assertTrue(self.find_binding("a", "from x.b import b, c, a, d", "x.b"))
+ self.assertFalse(self.find_binding("a", "from a import b", "a"))
+ self.assertFalse(self.find_binding("a", "from a.d import b", "a.d"))
+ self.assertFalse(self.find_binding("a", "from d.a import b", "a.d"))
+ self.assertFalse(self.find_binding("a", "from x.y import *", "a.b"))
def test_import_as_with_package(self):
- self.failIf(self.find_binding("a", "import b.c as a", "b.c"))
- self.failIf(self.find_binding("a", "import a as f", "f"))
- self.failIf(self.find_binding("a", "import a as f", "a"))
+ self.assertFalse(self.find_binding("a", "import b.c as a", "b.c"))
+ self.assertFalse(self.find_binding("a", "import a as f", "f"))
+ self.assertFalse(self.find_binding("a", "import a as f", "a"))
def test_from_import_as_with_package(self):
# Because it would take a lot of special-case code in the fixers
# to deal with from foo import bar as baz, we'll simply always
# fail if there is an "from ... import ... as ..."
- self.failIf(self.find_binding("a", "from x import b as a", "x"))
- self.failIf(self.find_binding("a", "from x import g as a, d as b", "x"))
- self.failIf(self.find_binding("a", "from x.b import t as a", "x.b"))
- self.failIf(self.find_binding("a", "from x.b import g as a, d", "x.b"))
- self.failIf(self.find_binding("a", "from a import b as t", "a"))
- self.failIf(self.find_binding("a", "from a import b as t", "b"))
- self.failIf(self.find_binding("a", "from a import b as t", "t"))
+ self.assertFalse(self.find_binding("a", "from x import b as a", "x"))
+ self.assertFalse(self.find_binding("a", "from x import g as a, d as b", "x"))
+ self.assertFalse(self.find_binding("a", "from x.b import t as a", "x.b"))
+ self.assertFalse(self.find_binding("a", "from x.b import g as a, d", "x.b"))
+ self.assertFalse(self.find_binding("a", "from a import b as t", "a"))
+ self.assertFalse(self.find_binding("a", "from a import b as t", "b"))
+ self.assertFalse(self.find_binding("a", "from a import b as t", "t"))
def test_function_def(self):
- self.failUnless(self.find_binding("a", "def a(): pass"))
- self.failUnless(self.find_binding("a", "def a(b, c, d): pass"))
- self.failUnless(self.find_binding("a", "def a(): b = 7"))
- self.failIf(self.find_binding("a", "def d(b, (c, a), e): pass"))
- self.failIf(self.find_binding("a", "def d(a=7): pass"))
- self.failIf(self.find_binding("a", "def d(a): pass"))
- self.failIf(self.find_binding("a", "def d(): a = 7"))
+ self.assertTrue(self.find_binding("a", "def a(): pass"))
+ self.assertTrue(self.find_binding("a", "def a(b, c, d): pass"))
+ self.assertTrue(self.find_binding("a", "def a(): b = 7"))
+ self.assertFalse(self.find_binding("a", "def d(b, (c, a), e): pass"))
+ self.assertFalse(self.find_binding("a", "def d(a=7): pass"))
+ self.assertFalse(self.find_binding("a", "def d(a): pass"))
+ self.assertFalse(self.find_binding("a", "def d(): a = 7"))
s = """
def d():
def a():
pass"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
def test_class_def(self):
- self.failUnless(self.find_binding("a", "class a: pass"))
- self.failUnless(self.find_binding("a", "class a(): pass"))
- self.failUnless(self.find_binding("a", "class a(b): pass"))
- self.failUnless(self.find_binding("a", "class a(b, c=8): pass"))
- self.failIf(self.find_binding("a", "class d: pass"))
- self.failIf(self.find_binding("a", "class d(a): pass"))
- self.failIf(self.find_binding("a", "class d(b, a=7): pass"))
- self.failIf(self.find_binding("a", "class d(b, *a): pass"))
- self.failIf(self.find_binding("a", "class d(b, **a): pass"))
- self.failIf(self.find_binding("a", "class d: a = 7"))
+ self.assertTrue(self.find_binding("a", "class a: pass"))
+ self.assertTrue(self.find_binding("a", "class a(): pass"))
+ self.assertTrue(self.find_binding("a", "class a(b): pass"))
+ self.assertTrue(self.find_binding("a", "class a(b, c=8): pass"))
+ self.assertFalse(self.find_binding("a", "class d: pass"))
+ self.assertFalse(self.find_binding("a", "class d(a): pass"))
+ self.assertFalse(self.find_binding("a", "class d(b, a=7): pass"))
+ self.assertFalse(self.find_binding("a", "class d(b, *a): pass"))
+ self.assertFalse(self.find_binding("a", "class d(b, **a): pass"))
+ self.assertFalse(self.find_binding("a", "class d: a = 7"))
s = """
class d():
class a():
pass"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
def test_for(self):
- self.failUnless(self.find_binding("a", "for a in r: pass"))
- self.failUnless(self.find_binding("a", "for a, b in r: pass"))
- self.failUnless(self.find_binding("a", "for (a, b) in r: pass"))
- self.failUnless(self.find_binding("a", "for c, (a,) in r: pass"))
- self.failUnless(self.find_binding("a", "for c, (a, b) in r: pass"))
- self.failUnless(self.find_binding("a", "for c in r: a = c"))
- self.failIf(self.find_binding("a", "for c in a: pass"))
+ self.assertTrue(self.find_binding("a", "for a in r: pass"))
+ self.assertTrue(self.find_binding("a", "for a, b in r: pass"))
+ self.assertTrue(self.find_binding("a", "for (a, b) in r: pass"))
+ self.assertTrue(self.find_binding("a", "for c, (a,) in r: pass"))
+ self.assertTrue(self.find_binding("a", "for c, (a, b) in r: pass"))
+ self.assertTrue(self.find_binding("a", "for c in r: a = c"))
+ self.assertFalse(self.find_binding("a", "for c in a: pass"))
def test_for_nested(self):
s = """
for b in r:
for a in b:
pass"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
for b in r:
for a, c in b:
pass"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
for b in r:
for (a, c) in b:
pass"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
for b in r:
for (a,) in b:
pass"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
for b in r:
for c, (a, d) in b:
pass"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
for b in r:
for c in b:
a = 7"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
for b in r:
for c in b:
d = a"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
s = """
for b in r:
for c in a:
d = 7"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
def test_if(self):
- self.failUnless(self.find_binding("a", "if b in r: a = c"))
- self.failIf(self.find_binding("a", "if a in r: d = e"))
+ self.assertTrue(self.find_binding("a", "if b in r: a = c"))
+ self.assertFalse(self.find_binding("a", "if a in r: d = e"))
def test_if_nested(self):
s = """
if b in r:
if c in d:
a = c"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
if b in r:
if c in d:
c = a"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
def test_while(self):
- self.failUnless(self.find_binding("a", "while b in r: a = c"))
- self.failIf(self.find_binding("a", "while a in r: d = e"))
+ self.assertTrue(self.find_binding("a", "while b in r: a = c"))
+ self.assertFalse(self.find_binding("a", "while a in r: d = e"))
def test_while_nested(self):
s = """
while b in r:
while c in d:
a = c"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
while b in r:
while c in d:
c = a"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
def test_try_except(self):
s = """
@@ -354,14 +354,14 @@ class Test_find_binding(support.TestCase):
a = 6
except:
b = 8"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
b = 8
except:
a = 6"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
@@ -370,14 +370,14 @@ class Test_find_binding(support.TestCase):
pass
except:
a = 6"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
b = 8
except:
b = 6"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
def test_try_except_nested(self):
s = """
@@ -388,7 +388,7 @@ class Test_find_binding(support.TestCase):
pass
except:
b = 8"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
@@ -398,7 +398,7 @@ class Test_find_binding(support.TestCase):
a = 6
except:
pass"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
@@ -408,7 +408,7 @@ class Test_find_binding(support.TestCase):
pass
except:
a = 6"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
@@ -420,7 +420,7 @@ class Test_find_binding(support.TestCase):
a = 6
except:
pass"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
@@ -432,14 +432,14 @@ class Test_find_binding(support.TestCase):
pass
except:
a = 6"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
b = 8
except:
b = 6"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
s = """
try:
@@ -454,7 +454,7 @@ class Test_find_binding(support.TestCase):
t = 8
except:
o = y"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
def test_try_except_finally(self):
s = """
@@ -464,21 +464,21 @@ class Test_find_binding(support.TestCase):
b = 8
finally:
a = 9"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
b = 8
finally:
a = 6"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
b = 8
finally:
b = 6"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
s = """
try:
@@ -487,7 +487,7 @@ class Test_find_binding(support.TestCase):
b = 9
finally:
b = 6"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
def test_try_except_finally_nested(self):
s = """
@@ -502,7 +502,7 @@ class Test_find_binding(support.TestCase):
b = 9
finally:
c = 9"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
@@ -512,7 +512,7 @@ class Test_find_binding(support.TestCase):
pass
finally:
a = 6"""
- self.failUnless(self.find_binding("a", s))
+ self.assertTrue(self.find_binding("a", s))
s = """
try:
@@ -522,7 +522,7 @@ class Test_find_binding(support.TestCase):
b = 6
finally:
b = 7"""
- self.failIf(self.find_binding("a", s))
+ self.assertFalse(self.find_binding("a", s))
class Test_touch_import(support.TestCase):