Commit 9788e860 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #19594: Use specific asserts in unittest tests.

parent 52bbeacb
...@@ -293,7 +293,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): ...@@ -293,7 +293,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
def test(self): def test(self):
pass pass
self.assertTrue(Foo('test').failureException is AssertionError) self.assertIs(Foo('test').failureException, AssertionError)
# "This class attribute gives the exception raised by the test() method. # "This class attribute gives the exception raised by the test() method.
# If a test framework needs to use a specialized exception, possibly to # If a test framework needs to use a specialized exception, possibly to
...@@ -311,7 +311,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): ...@@ -311,7 +311,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
failureException = RuntimeError failureException = RuntimeError
self.assertTrue(Foo('test').failureException is RuntimeError) self.assertIs(Foo('test').failureException, RuntimeError)
Foo('test').run(result) Foo('test').run(result)
...@@ -334,7 +334,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): ...@@ -334,7 +334,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
failureException = RuntimeError failureException = RuntimeError
self.assertTrue(Foo('test').failureException is RuntimeError) self.assertIs(Foo('test').failureException, RuntimeError)
Foo('test').run(result) Foo('test').run(result)
...@@ -607,7 +607,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): ...@@ -607,7 +607,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg = e.args[0] msg = e.args[0]
else: else:
self.fail('assertSequenceEqual did not fail.') self.fail('assertSequenceEqual did not fail.')
self.assertTrue(len(msg) < len(diff)) self.assertLess(len(msg), len(diff))
self.assertIn(omitted, msg) self.assertIn(omitted, msg)
self.maxDiff = len(diff) * 2 self.maxDiff = len(diff) * 2
...@@ -617,7 +617,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): ...@@ -617,7 +617,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg = e.args[0] msg = e.args[0]
else: else:
self.fail('assertSequenceEqual did not fail.') self.fail('assertSequenceEqual did not fail.')
self.assertTrue(len(msg) > len(diff)) self.assertGreater(len(msg), len(diff))
self.assertNotIn(omitted, msg) self.assertNotIn(omitted, msg)
self.maxDiff = None self.maxDiff = None
...@@ -627,7 +627,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): ...@@ -627,7 +627,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg = e.args[0] msg = e.args[0]
else: else:
self.fail('assertSequenceEqual did not fail.') self.fail('assertSequenceEqual did not fail.')
self.assertTrue(len(msg) > len(diff)) self.assertGreater(len(msg), len(diff))
self.assertNotIn(omitted, msg) self.assertNotIn(omitted, msg)
def testTruncateMessage(self): def testTruncateMessage(self):
......
...@@ -1279,7 +1279,7 @@ class Test_TestLoader(unittest.TestCase): ...@@ -1279,7 +1279,7 @@ class Test_TestLoader(unittest.TestCase):
# "The default value is the TestSuite class" # "The default value is the TestSuite class"
def test_suiteClass__default_value(self): def test_suiteClass__default_value(self):
loader = unittest.TestLoader() loader = unittest.TestLoader()
self.assertTrue(loader.suiteClass is unittest.TestSuite) self.assertIs(loader.suiteClass, unittest.TestSuite)
# Make sure the dotted name resolution works even if the actual # Make sure the dotted name resolution works even if the actual
# function doesn't have the same name as is used to find it. # function doesn't have the same name as is used to find it.
......
...@@ -176,7 +176,7 @@ class Test_TestResult(unittest.TestCase): ...@@ -176,7 +176,7 @@ class Test_TestResult(unittest.TestCase):
self.assertEqual(result.shouldStop, False) self.assertEqual(result.shouldStop, False)
test_case, formatted_exc = result.failures[0] test_case, formatted_exc = result.failures[0]
self.assertTrue(test_case is test) self.assertIs(test_case, test)
self.assertIsInstance(formatted_exc, str) self.assertIsInstance(formatted_exc, str)
# "addError(test, err)" # "addError(test, err)"
...@@ -224,7 +224,7 @@ class Test_TestResult(unittest.TestCase): ...@@ -224,7 +224,7 @@ class Test_TestResult(unittest.TestCase):
self.assertEqual(result.shouldStop, False) self.assertEqual(result.shouldStop, False)
test_case, formatted_exc = result.errors[0] test_case, formatted_exc = result.errors[0]
self.assertTrue(test_case is test) self.assertIs(test_case, test)
self.assertIsInstance(formatted_exc, str) self.assertIsInstance(formatted_exc, str)
def testGetDescriptionWithoutDocstring(self): def testGetDescriptionWithoutDocstring(self):
......
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