Commit 0a89b159 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #19592: Use specific asserts in lib2to3 tests.

parent 01bdeec8
...@@ -41,7 +41,7 @@ class FixerTestCase(support.TestCase): ...@@ -41,7 +41,7 @@ class FixerTestCase(support.TestCase):
def warns(self, before, after, message, unchanged=False): def warns(self, before, after, message, unchanged=False):
tree = self._check(before, after) tree = self._check(before, after)
self.assertTrue(message in "".join(self.fixer_log)) self.assertIn(message, "".join(self.fixer_log))
if not unchanged: if not unchanged:
self.assertTrue(tree.was_changed) self.assertTrue(tree.was_changed)
......
...@@ -59,9 +59,9 @@ class TestMain(unittest.TestCase): ...@@ -59,9 +59,9 @@ class TestMain(unittest.TestCase):
ret = self.run_2to3_capture(["-"], input_stream, out_enc, err) ret = self.run_2to3_capture(["-"], input_stream, out_enc, err)
self.assertEqual(ret, 0) self.assertEqual(ret, 0)
output = out.getvalue() output = out.getvalue()
self.assertTrue("-print 'nothing'" in output) self.assertIn("-print 'nothing'", output)
self.assertTrue("WARNING: couldn't encode <stdin>'s diff for " self.assertIn("WARNING: couldn't encode <stdin>'s diff for "
"your terminal" in err.getvalue()) "your terminal", err.getvalue())
def setup_test_source_trees(self): def setup_test_source_trees(self):
"""Setup a test source tree and output destination tree.""" """Setup a test source tree and output destination tree."""
......
...@@ -165,8 +165,8 @@ class TestParserIdempotency(support.TestCase): ...@@ -165,8 +165,8 @@ class TestParserIdempotency(support.TestCase):
for filepath in support.all_project_files(): for filepath in support.all_project_files():
with open(filepath, "rb") as fp: with open(filepath, "rb") as fp:
encoding = tokenize.detect_encoding(fp.readline)[0] encoding = tokenize.detect_encoding(fp.readline)[0]
self.assertTrue(encoding is not None, self.assertIsNotNone(encoding,
"can't detect encoding for %s" % filepath) "can't detect encoding for %s" % filepath)
with open(filepath, "r") as fp: with open(filepath, "r") as fp:
source = fp.read() source = fp.read()
source = source.decode(encoding) source = source.decode(encoding)
......
...@@ -160,12 +160,12 @@ class TestNodes(support.TestCase): ...@@ -160,12 +160,12 @@ class TestNodes(support.TestCase):
l3 = pytree.Leaf(100, "bar") l3 = pytree.Leaf(100, "bar")
n1 = pytree.Node(1000, [l1, l2, l3]) n1 = pytree.Node(1000, [l1, l2, l3])
self.assertEqual(n1.children, [l1, l2, l3]) self.assertEqual(n1.children, [l1, l2, l3])
self.assertTrue(isinstance(n1.children, list)) self.assertIsInstance(n1.children, list)
self.assertFalse(n1.was_changed) self.assertFalse(n1.was_changed)
l2new = pytree.Leaf(100, "-") l2new = pytree.Leaf(100, "-")
l2.replace(l2new) l2.replace(l2new)
self.assertEqual(n1.children, [l1, l2new, l3]) self.assertEqual(n1.children, [l1, l2new, l3])
self.assertTrue(isinstance(n1.children, list)) self.assertIsInstance(n1.children, list)
self.assertTrue(n1.was_changed) self.assertTrue(n1.was_changed)
def test_replace_with_list(self): def test_replace_with_list(self):
...@@ -176,7 +176,7 @@ class TestNodes(support.TestCase): ...@@ -176,7 +176,7 @@ class TestNodes(support.TestCase):
l2.replace([pytree.Leaf(100, "*"), pytree.Leaf(100, "*")]) l2.replace([pytree.Leaf(100, "*"), pytree.Leaf(100, "*")])
self.assertEqual(str(n1), "foo**bar") self.assertEqual(str(n1), "foo**bar")
self.assertTrue(isinstance(n1.children, list)) self.assertIsInstance(n1.children, list)
def test_leaves(self): def test_leaves(self):
l1 = pytree.Leaf(100, "foo") l1 = pytree.Leaf(100, "foo")
...@@ -347,7 +347,7 @@ class TestNodes(support.TestCase): ...@@ -347,7 +347,7 @@ class TestNodes(support.TestCase):
n2 = pytree.Node(1000, []) n2 = pytree.Node(1000, [])
p1 = pytree.Node(1000, [n1, n2]) p1 = pytree.Node(1000, [n1, n2])
self.assertTrue(n1.next_sibling is n2) self.assertIs(n1.next_sibling, n2)
self.assertEqual(n2.next_sibling, None) self.assertEqual(n2.next_sibling, None)
self.assertEqual(p1.next_sibling, None) self.assertEqual(p1.next_sibling, None)
...@@ -356,7 +356,7 @@ class TestNodes(support.TestCase): ...@@ -356,7 +356,7 @@ class TestNodes(support.TestCase):
l2 = pytree.Leaf(100, "b") l2 = pytree.Leaf(100, "b")
p1 = pytree.Node(1000, [l1, l2]) p1 = pytree.Node(1000, [l1, l2])
self.assertTrue(l1.next_sibling is l2) self.assertIs(l1.next_sibling, l2)
self.assertEqual(l2.next_sibling, None) self.assertEqual(l2.next_sibling, None)
self.assertEqual(p1.next_sibling, None) self.assertEqual(p1.next_sibling, None)
...@@ -365,7 +365,7 @@ class TestNodes(support.TestCase): ...@@ -365,7 +365,7 @@ class TestNodes(support.TestCase):
n2 = pytree.Node(1000, []) n2 = pytree.Node(1000, [])
p1 = pytree.Node(1000, [n1, n2]) p1 = pytree.Node(1000, [n1, n2])
self.assertTrue(n2.prev_sibling is n1) self.assertIs(n2.prev_sibling, n1)
self.assertEqual(n1.prev_sibling, None) self.assertEqual(n1.prev_sibling, None)
self.assertEqual(p1.prev_sibling, None) self.assertEqual(p1.prev_sibling, None)
...@@ -374,7 +374,7 @@ class TestNodes(support.TestCase): ...@@ -374,7 +374,7 @@ class TestNodes(support.TestCase):
l2 = pytree.Leaf(100, "b") l2 = pytree.Leaf(100, "b")
p1 = pytree.Node(1000, [l1, l2]) p1 = pytree.Node(1000, [l1, l2])
self.assertTrue(l2.prev_sibling is l1) self.assertIs(l2.prev_sibling, l1)
self.assertEqual(l1.prev_sibling, None) self.assertEqual(l1.prev_sibling, None)
self.assertEqual(p1.prev_sibling, None) self.assertEqual(p1.prev_sibling, None)
...@@ -447,7 +447,7 @@ class TestPatterns(support.TestCase): ...@@ -447,7 +447,7 @@ class TestPatterns(support.TestCase):
r = {} r = {}
self.assertTrue(pw.match_seq([l1, l3], r)) self.assertTrue(pw.match_seq([l1, l3], r))
self.assertEqual(r, {"pl": l3, "pw": [l1, l3]}) self.assertEqual(r, {"pl": l3, "pw": [l1, l3]})
self.assertTrue(r["pl"] is l3) self.assertIs(r["pl"], l3)
r = {} r = {}
def test_generate_matches(self): def test_generate_matches(self):
......
...@@ -49,9 +49,9 @@ class TestRefactoringTool(unittest.TestCase): ...@@ -49,9 +49,9 @@ class TestRefactoringTool(unittest.TestCase):
def test_print_function_option(self): def test_print_function_option(self):
rt = self.rt({"print_function" : True}) rt = self.rt({"print_function" : True})
self.assertTrue(rt.grammar is pygram.python_grammar_no_print_statement) self.assertIs(rt.grammar, pygram.python_grammar_no_print_statement)
self.assertTrue(rt.driver.grammar is self.assertIs(rt.driver.grammar,
pygram.python_grammar_no_print_statement) pygram.python_grammar_no_print_statement)
def test_write_unchanged_files_option(self): def test_write_unchanged_files_option(self):
rt = self.rt() rt = self.rt()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment