]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19594: Use specific asserts in unittest tests.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 16 Nov 2013 22:14:35 +0000 (00:14 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 16 Nov 2013 22:14:35 +0000 (00:14 +0200)
1  2 
Lib/unittest/test/test_case.py
Lib/unittest/test/test_loader.py
Lib/unittest/test/test_result.py
Lib/unittest/test/testmock/testhelpers.py
Lib/unittest/test/testmock/testmock.py

Simple merge
index b1782a293630717accb13e05fb0376e7406a7172,fcd2e07624500291557db951b1e64abd7012eb64..b62a1b5c541130c92af0be53e43c5a40fdde5045
@@@ -1305,8 -1305,4 +1305,8 @@@ class Test_TestLoader(unittest.TestCase
      # "The default value is the TestSuite class"
      def test_suiteClass__default_value(self):
          loader = unittest.TestLoader()
-         self.assertTrue(loader.suiteClass is unittest.TestSuite)
+         self.assertIs(loader.suiteClass, unittest.TestSuite)
 +
 +
 +if __name__ == "__main__":
 +    unittest.main()
index 6dd9bb0f9e8e1389af74610d7e616ce89b74a5ce,7d40725cf2c6d318dc3f0d992b12b3f4fe08de16..489fe177546add9f790bcc1c5a94a4463292b61b
@@@ -224,43 -224,9 +224,43 @@@ class Test_TestResult(unittest.TestCase
          self.assertEqual(result.shouldStop, False)
  
          test_case, formatted_exc = result.errors[0]
-         self.assertTrue(test_case is test)
+         self.assertIs(test_case, test)
          self.assertIsInstance(formatted_exc, str)
  
 +    def test_addSubTest(self):
 +        class Foo(unittest.TestCase):
 +            def test_1(self):
 +                nonlocal subtest
 +                with self.subTest(foo=1):
 +                    subtest = self._subtest
 +                    try:
 +                        1/0
 +                    except ZeroDivisionError:
 +                        exc_info_tuple = sys.exc_info()
 +                    # Register an error by hand (to check the API)
 +                    result.addSubTest(test, subtest, exc_info_tuple)
 +                    # Now trigger a failure
 +                    self.fail("some recognizable failure")
 +
 +        subtest = None
 +        test = Foo('test_1')
 +        result = unittest.TestResult()
 +
 +        test.run(result)
 +
 +        self.assertFalse(result.wasSuccessful())
 +        self.assertEqual(len(result.errors), 1)
 +        self.assertEqual(len(result.failures), 1)
 +        self.assertEqual(result.testsRun, 1)
 +        self.assertEqual(result.shouldStop, False)
 +
 +        test_case, formatted_exc = result.errors[0]
 +        self.assertIs(test_case, subtest)
 +        self.assertIn("ZeroDivisionError", formatted_exc)
 +        test_case, formatted_exc = result.failures[0]
 +        self.assertIs(test_case, subtest)
 +        self.assertIn("some recognizable failure", formatted_exc)
 +
      def testGetDescriptionWithoutDocstring(self):
          result = unittest.TextTestResult(None, True, 1)
          self.assertEqual(