finally:
logging._releaseLock()
- def assertTruelog_lines(self, expected_values, stream=None):
+ def assert_log_lines(self, expected_values, stream=None):
"""Match the collected log lines against the regular expression
self.expected_log_pat, and compare the extracted group values to
the expected_values list of tuples."""
INF.debug(m())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('ERR', 'CRITICAL', '1'),
('ERR', 'ERROR', '2'),
('INF', 'CRITICAL', '3'),
INF_ERR.info(m())
INF_ERR.debug(m())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('INF.ERR', 'CRITICAL', '1'),
('INF.ERR', 'ERROR', '2'),
])
INF_ERR_UNDEF.info(m())
INF_ERR_UNDEF.debug(m())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('INF.UNDEF', 'CRITICAL', '1'),
('INF.UNDEF', 'ERROR', '2'),
('INF.UNDEF', 'WARNING', '3'),
GRANDCHILD.debug(m())
CHILD.debug(m())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('INF.BADPARENT.UNDEF', 'CRITICAL', '1'),
('INF.BADPARENT.UNDEF', 'INFO', '2'),
('INF.BADPARENT', 'CRITICAL', '3'),
spam_eggs_fish.info(self.next_message()) # Good.
spam_bakedbeans.info(self.next_message())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('spam.eggs', 'INFO', '2'),
('spam.eggs.fish', 'INFO', '3'),
])
self.root_logger.setLevel(VERBOSE)
# Levels >= 'Verbose' are good.
self.log_at_all_levels(self.root_logger)
- self.assertTruelog_lines([
+ self.assert_log_lines([
('Verbose', '5'),
('Sociable', '6'),
('Effusive', '7'),
try:
# Levels >= 'Sociable' are good.
self.log_at_all_levels(self.root_logger)
- self.assertTruelog_lines([
+ self.assert_log_lines([
('Sociable', '6'),
('Effusive', '7'),
('Terse', '8'),
('Taciturn', '9'),
('Silent', '10'),
]
- self.assertTruelog_lines(first_lines)
+ self.assert_log_lines(first_lines)
specific_filter = VerySpecificFilter()
self.root_logger.addFilter(specific_filter)
self.log_at_all_levels(self.root_logger)
- self.assertTruelog_lines(first_lines + [
+ self.assert_log_lines(first_lines + [
# Not only 'Garrulous' is still missing, but also 'Sociable'
# and 'Taciturn'
('Boring', '11'),
# The memory handler flushes to its target handler based on specific
# criteria (message count and message level).
self.mem_logger.debug(self.next_message())
- self.assertTruelog_lines([])
+ self.assert_log_lines([])
self.mem_logger.info(self.next_message())
- self.assertTruelog_lines([])
+ self.assert_log_lines([])
# This will flush because the level is >= logging.WARNING
self.mem_logger.warn(self.next_message())
lines = [
('INFO', '2'),
('WARNING', '3'),
]
- self.assertTruelog_lines(lines)
+ self.assert_log_lines(lines)
for n in (4, 14):
for i in range(9):
self.mem_logger.debug(self.next_message())
- self.assertTruelog_lines(lines)
+ self.assert_log_lines(lines)
# This will flush because it's the 10th message since the last
# flush.
self.mem_logger.debug(self.next_message())
lines = lines + [('DEBUG', str(i)) for i in range(n, n + 10)]
- self.assertTruelog_lines(lines)
+ self.assert_log_lines(lines)
self.mem_logger.debug(self.next_message())
- self.assertTruelog_lines(lines)
+ self.assert_log_lines(lines)
class ExceptionFormatter(logging.Formatter):
logger.info(self.next_message())
# Outputs a message
logger.error(self.next_message())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('ERROR', '2'),
], stream=output)
# Original logger output is empty.
- self.assertTruelog_lines([])
+ self.assert_log_lines([])
def test_config1_ok(self, config=config1):
# A config file defining a sub-parser as well.
# Both will output a message
logger.info(self.next_message())
logger.error(self.next_message())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('INFO', '1'),
('ERROR', '2'),
], stream=output)
# Original logger output is empty.
- self.assertTruelog_lines([])
+ self.assert_log_lines([])
def test_config2_failure(self):
# A simple config file which overrides the default settings.
self.assertEquals(output.getvalue(),
"ERROR:root:just testing\nGot a [RuntimeError]\n")
# Original logger output is empty
- self.assertTruelog_lines([])
+ self.assert_log_lines([])
def test_config5_ok(self):
self.test_config1_ok(config=self.config5)
foo.setLevel(logging.DEBUG)
self.root_logger.debug(self.next_message())
foo.debug(self.next_message())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('foo', 'DEBUG', '2'),
])
del foo
# foo has retained its settings.
bar = logging.getLogger("foo")
bar.debug(self.next_message())
- self.assertTruelog_lines([
+ self.assert_log_lines([
('foo', 'DEBUG', '2'),
('foo', 'DEBUG', '3'),
])
# 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"""
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')])
################################################################
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)
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"
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()])
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
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')])
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')])
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
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
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]
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
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
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])
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])
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])
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])
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])
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])
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]
# "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
def test_id(self):
test = unittest.FunctionTestCase(lambda: None)
- self.failUnless(isinstance(test.id(), str))
+ self.assertTrue(isinstance(test.id(), str))
# "Returns a one-line description of the test, or None if no description
# has been provided. The default implementation of this method returns
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)
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)
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)
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)
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)
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)"
# ...
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
################################################################
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
failureException = RuntimeError
- self.failUnless(Foo('test').failureException is RuntimeError)
+ self.assertTrue(Foo('test').failureException is RuntimeError)
Foo('test').run(result)
failureException = RuntimeError
- self.failUnless(Foo('test').failureException is RuntimeError)
+ self.assertTrue(Foo('test').failureException is RuntimeError)
Foo('test').run(result)
def runTest(self):
pass
- self.failUnless(isinstance(Foo().id(), str))
+ self.assertTrue(isinstance(Foo().id(), str))
# "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
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):