[Python-checkins] r73717 - python/trunk/Lib/test/test_unittest.py
benjamin.peterson
python-checkins at python.org
Wed Jul 1 01:30:12 CEST 2009
Author: benjamin.peterson
Date: Wed Jul 1 01:30:12 2009
New Revision: 73717
Log:
use assert* methods in test_unittest
Modified:
python/trunk/Lib/test/test_unittest.py
Modified: python/trunk/Lib/test/test_unittest.py
==============================================================================
--- python/trunk/Lib/test/test_unittest.py (original)
+++ python/trunk/Lib/test/test_unittest.py Wed Jul 1 01:30:12 2009
@@ -78,8 +78,8 @@
# Check for a valid __ne__ implementation
def test_ne(self):
for obj_1, obj_2 in self.ne_pairs:
- self.failIfEqual(obj_1, obj_2)
- self.failIfEqual(obj_2, obj_1)
+ self.assertNotEqual(obj_1, obj_2)
+ self.assertNotEqual(obj_2, obj_1)
class TestHashing(object):
"""Used as a mixin for TestCase"""
@@ -181,10 +181,10 @@
loader = unittest.TestLoader()
# This has to be false for the test to succeed
- self.failIf('runTest'.startswith(loader.testMethodPrefix))
+ self.assertFalse('runTest'.startswith(loader.testMethodPrefix))
suite = loader.loadTestsFromTestCase(Foo)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [Foo('runTest')])
################################################################
@@ -203,7 +203,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromModule(m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
expected = [loader.suiteClass([MyTestCase('test')])]
self.assertEqual(list(suite), expected)
@@ -216,7 +216,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromModule(m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [])
# "This method searches `module` for classes derived from TestCase"
@@ -230,7 +230,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromModule(m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [loader.suiteClass()])
@@ -466,7 +466,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromName('testcase_1', m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [MyTestCase('test')])
# "The specifier name is a ``dotted name'' that may resolve either to
@@ -482,7 +482,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromName('testsuite', m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [MyTestCase('test')])
@@ -497,7 +497,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromName('testcase_1.test', m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [MyTestCase('test')])
@@ -536,7 +536,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromName('return_TestSuite', m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [testcase_1, testcase_2])
# "The specifier name is a ``dotted name'' that may resolve ... to
@@ -550,7 +550,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromName('return_TestCase', m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [testcase_1])
# "The specifier name is a ``dotted name'' that may resolve ... to
@@ -589,11 +589,11 @@
try:
suite = loader.loadTestsFromName(module_name)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [])
# audioop should now be loaded, thanks to loadTestsFromName()
- self.failUnless(module_name in sys.modules)
+ self.assertTrue(module_name in sys.modules)
finally:
if module_name in sys.modules:
del sys.modules[module_name]
@@ -612,7 +612,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames([])
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [])
# "Similar to loadTestsFromName(), but takes a sequence of names rather
@@ -627,7 +627,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames([], unittest)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [])
# "The specifier name is a ``dotted name'' that may resolve either to
@@ -828,7 +828,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames(['testcase_1'], m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
expected = loader.suiteClass([MyTestCase('test')])
self.assertEqual(list(suite), [expected])
@@ -844,7 +844,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames(['testsuite'], m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [m.testsuite])
@@ -859,7 +859,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames(['testcase_1.test'], m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
ref_suite = unittest.TestSuite([MyTestCase('test')])
self.assertEqual(list(suite), [ref_suite])
@@ -896,7 +896,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames(['return_TestSuite'], m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
expected = unittest.TestSuite([testcase_1, testcase_2])
self.assertEqual(list(suite), [expected])
@@ -912,7 +912,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames(['return_TestCase'], m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
ref_suite = unittest.TestSuite([testcase_1])
self.assertEqual(list(suite), [ref_suite])
@@ -936,7 +936,7 @@
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames(['Foo.foo'], m)
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
ref_suite = unittest.TestSuite([testcase_1])
self.assertEqual(list(suite), [ref_suite])
@@ -977,11 +977,11 @@
try:
suite = loader.loadTestsFromNames([module_name])
- self.failUnless(isinstance(suite, loader.suiteClass))
+ self.assertTrue(isinstance(suite, loader.suiteClass))
self.assertEqual(list(suite), [unittest.TestSuite()])
# audioop should now be loaded, thanks to loadTestsFromName()
- self.failUnless(module_name in sys.modules)
+ self.assertTrue(module_name in sys.modules)
finally:
if module_name in sys.modules:
del sys.modules[module_name]
@@ -1156,7 +1156,7 @@
# "The default value is 'test'"
def test_testMethodPrefix__default_value(self):
loader = unittest.TestLoader()
- self.failUnless(loader.testMethodPrefix == 'test')
+ self.assertTrue(loader.testMethodPrefix == 'test')
################################################################
### /Tests for TestLoader.testMethodPrefix
@@ -1255,7 +1255,7 @@
# "The default value is the built-in cmp() function"
def test_sortTestMethodsUsing__default_value(self):
loader = unittest.TestLoader()
- self.failUnless(loader.sortTestMethodsUsing is cmp)
+ self.assertTrue(loader.sortTestMethodsUsing is cmp)
# "it can be set to None to disable the sort."
#
@@ -1342,7 +1342,7 @@
# "The default value is the TestSuite class"
def test_suiteClass__default_value(self):
loader = unittest.TestLoader()
- self.failUnless(loader.suiteClass is unittest.TestSuite)
+ self.assertTrue(loader.suiteClass is unittest.TestSuite)
################################################################
### /Tests for TestLoader.suiteClass
@@ -1755,7 +1755,7 @@
def test_id(self):
test = unittest.FunctionTestCase(lambda: None)
- self.failUnless(isinstance(test.id(), basestring))
+ self.assertTrue(isinstance(test.id(), basestring))
# "Returns a one-line description of the test, or None if no description
# has been provided. The default implementation of this method returns
@@ -1787,7 +1787,7 @@
def test_init(self):
result = unittest.TestResult()
- self.failUnless(result.wasSuccessful())
+ self.assertTrue(result.wasSuccessful())
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.failures), 0)
self.assertEqual(result.testsRun, 0)
@@ -1816,7 +1816,7 @@
result.startTest(test)
- self.failUnless(result.wasSuccessful())
+ self.assertTrue(result.wasSuccessful())
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.failures), 0)
self.assertEqual(result.testsRun, 1)
@@ -1837,7 +1837,7 @@
result.startTest(test)
- self.failUnless(result.wasSuccessful())
+ self.assertTrue(result.wasSuccessful())
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.failures), 0)
self.assertEqual(result.testsRun, 1)
@@ -1846,7 +1846,7 @@
result.stopTest(test)
# Same tests as above; make sure nothing has changed
- self.failUnless(result.wasSuccessful())
+ self.assertTrue(result.wasSuccessful())
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.failures), 0)
self.assertEqual(result.testsRun, 1)
@@ -1890,7 +1890,7 @@
result.addSuccess(test)
result.stopTest(test)
- self.failUnless(result.wasSuccessful())
+ self.assertTrue(result.wasSuccessful())
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.failures), 0)
self.assertEqual(result.testsRun, 1)
@@ -1935,15 +1935,15 @@
result.addFailure(test, exc_info_tuple)
result.stopTest(test)
- self.failIf(result.wasSuccessful())
+ self.assertFalse(result.wasSuccessful())
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.failures), 1)
self.assertEqual(result.testsRun, 1)
self.assertEqual(result.shouldStop, False)
test_case, formatted_exc = result.failures[0]
- self.failUnless(test_case is test)
- self.failUnless(isinstance(formatted_exc, str))
+ self.assertTrue(test_case is test)
+ self.assertTrue(isinstance(formatted_exc, str))
# "addError(test, err)"
# ...
@@ -1985,15 +1985,15 @@
result.addError(test, exc_info_tuple)
result.stopTest(test)
- self.failIf(result.wasSuccessful())
+ self.assertFalse(result.wasSuccessful())
self.assertEqual(len(result.errors), 1)
self.assertEqual(len(result.failures), 0)
self.assertEqual(result.testsRun, 1)
self.assertEqual(result.shouldStop, False)
test_case, formatted_exc = result.errors[0]
- self.failUnless(test_case is test)
- self.failUnless(isinstance(formatted_exc, str))
+ self.assertTrue(test_case is test)
+ self.assertTrue(isinstance(formatted_exc, str))
### Support code for Test_TestCase
################################################################
@@ -2307,7 +2307,7 @@
def test(self):
pass
- self.failUnless(Foo('test').failureException is AssertionError)
+ self.assertTrue(Foo('test').failureException is AssertionError)
# "This class attribute gives the exception raised by the test() method.
# If a test framework needs to use a specialized exception, possibly to
@@ -2325,7 +2325,7 @@
failureException = RuntimeError
- self.failUnless(Foo('test').failureException is RuntimeError)
+ self.assertTrue(Foo('test').failureException is RuntimeError)
Foo('test').run(result)
@@ -2348,7 +2348,7 @@
failureException = RuntimeError
- self.failUnless(Foo('test').failureException is RuntimeError)
+ self.assertTrue(Foo('test').failureException is RuntimeError)
Foo('test').run(result)
@@ -2384,7 +2384,7 @@
def runTest(self):
pass
- self.failUnless(isinstance(Foo().id(), basestring))
+ self.assertTrue(isinstance(Foo().id(), basestring))
# "If result is omitted or None, a temporary result object is created
# and used, but is not made available to the caller. As TestCase owns the
@@ -2955,23 +2955,23 @@
class Test_Assertions(TestCase):
def test_AlmostEqual(self):
- self.failUnlessAlmostEqual(1.00000001, 1.0)
- self.failIfAlmostEqual(1.0000001, 1.0)
+ self.assertAlmostEqual(1.00000001, 1.0)
+ self.assertNotAlmostEqual(1.0000001, 1.0)
self.assertRaises(self.failureException,
- self.failUnlessAlmostEqual, 1.0000001, 1.0)
+ self.assertAlmostEqual, 1.0000001, 1.0)
self.assertRaises(self.failureException,
- self.failIfAlmostEqual, 1.00000001, 1.0)
+ self.assertNotAlmostEqual, 1.00000001, 1.0)
- self.failUnlessAlmostEqual(1.1, 1.0, places=0)
+ self.assertAlmostEqual(1.1, 1.0, places=0)
self.assertRaises(self.failureException,
- self.failUnlessAlmostEqual, 1.1, 1.0, places=1)
+ self.assertAlmostEqual, 1.1, 1.0, places=1)
- self.failUnlessAlmostEqual(0, .1+.1j, places=0)
- self.failIfAlmostEqual(0, .1+.1j, places=1)
+ self.assertAlmostEqual(0, .1+.1j, places=0)
+ self.assertNotAlmostEqual(0, .1+.1j, places=1)
self.assertRaises(self.failureException,
- self.failUnlessAlmostEqual, 0, .1+.1j, places=1)
+ self.assertAlmostEqual, 0, .1+.1j, places=1)
self.assertRaises(self.failureException,
- self.failIfAlmostEqual, 0, .1+.1j, places=0)
+ self.assertNotAlmostEqual, 0, .1+.1j, places=0)
def test_assertRaises(self):
def _raise(e):
More information about the Python-checkins
mailing list