Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
unittest.test.test_case.Test_TestCase Class Reference

List of all members.

Public Member Functions

def test_init__no_test_name
 /Set up attributes used by inherited tests
def test_init__test_name__valid
def test_init__test_name__invalid
def test_countTestCases
def test_defaultTestResult
def test_run_call_order__error_in_setUp
def test_run_call_order__error_in_setUp_default_result
def test_run_call_order__error_in_test
def test_run_call_order__error_in_test_default_result
def test_run_call_order__failure_in_test
def test_run_call_order__failure_in_test_default_result
def test_run_call_order__error_in_tearDown
def test_run_call_order__error_in_tearDown_default_result
def test_run_call_order_default_result
def test_failureException__default
def test_failureException__subclassing__explicit_raise
def test_failureException__subclassing__implicit_raise
def test_setUp
def test_tearDown
def test_id
def test_run__uses_defaultTestResult
def testShortDescriptionWithoutDocstring
def testShortDescriptionWithOneLineDocstring
def testShortDescriptionWithMultiLineDocstring
def testAddTypeEqualityFunc
def testAssertIs
def testAssertIsNot
def testAssertIsInstance
def testAssertNotIsInstance
def testAssertIn
def testAssertDictContainsSubset
def testAssertEqual
def testEquality
def testAssertSequenceEqualMaxDiff
def testTruncateMessage
def testAssertDictEqualTruncates
def testAssertMultiLineEqualTruncates
def testAssertEqual_diffThreshold
def testAssertCountEqual
def testAssertSetEqual
def testInequality
def testAssertMultiLineEqual
def testAsertEqualSingleLine
def testAssertIsNone
def testAssertRegex
def testAssertRaisesRegex
def testAssertNotRaisesRegex
def testAssertRaisesRegexMismatch
def testAssertRaisesExcValue
def testAssertWarnsCallable
def testAssertWarnsContext
def testAssertWarnsRegexCallable
def testAssertWarnsRegexContext
def testDeprecatedMethodNames
def testDeprecatedFailMethods
def testDeepcopy
def testPickle
def testKeyboardInterrupt
def testSkippingEverywhere
def testSystemExit

Public Attributes

 maxDiff

Static Public Attributes

list eq_pairs = [(Test.Foo('test1'), Test.Foo('test1'))]
 Set up attributes used by inherited tests.
list ne_pairs

Private Attributes

 _diffThreshold
 _truncateMessage

Detailed Description

Definition at line 47 of file test_case.py.


Member Function Documentation

Definition at line 119 of file test_case.py.

00119 
00120     def test_countTestCases(self):
00121         class Foo(unittest.TestCase):
00122             def test(self): pass
00123 
00124         self.assertEqual(Foo('test').countTestCases(), 1)

Here is the call graph for this function:

Definition at line 129 of file test_case.py.

00129 
00130     def test_defaultTestResult(self):
00131         class Foo(unittest.TestCase):
00132             def runTest(self):
00133                 pass
00134 
00135         result = Foo().defaultTestResult()
00136         self.assertEqual(type(result), unittest.TestResult)

Definition at line 304 of file test_case.py.

00304 
00305     def test_failureException__default(self):
00306         class Foo(unittest.TestCase):
00307             def test(self):
00308                 pass
00309 
00310         self.assertTrue(Foo('test').failureException is AssertionError)

Definition at line 317 of file test_case.py.

00317 
00318     def test_failureException__subclassing__explicit_raise(self):
00319         events = []
00320         result = LoggingResult(events)
00321 
00322         class Foo(unittest.TestCase):
00323             def test(self):
00324                 raise RuntimeError()
00325 
00326             failureException = RuntimeError
00327 
00328         self.assertTrue(Foo('test').failureException is RuntimeError)
00329 
00330 
00331         Foo('test').run(result)
00332         expected = ['startTest', 'addFailure', 'stopTest']
00333         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 340 of file test_case.py.

00340 
00341     def test_failureException__subclassing__implicit_raise(self):
00342         events = []
00343         result = LoggingResult(events)
00344 
00345         class Foo(unittest.TestCase):
00346             def test(self):
00347                 self.fail("foo")
00348 
00349             failureException = RuntimeError
00350 
00351         self.assertTrue(Foo('test').failureException is RuntimeError)
00352 
00353 
00354         Foo('test').run(result)
00355         expected = ['startTest', 'addFailure', 'stopTest']
00356         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 381 of file test_case.py.

00381 
00382     def test_id(self):
00383         class Foo(unittest.TestCase):
00384             def runTest(self):
00385                 pass
00386 
00387         self.assertIsInstance(Foo().id(), str)
00388 

/Set up attributes used by inherited tests

Definition at line 73 of file test_case.py.

00073 
00074     def test_init__no_test_name(self):
00075         class Test(unittest.TestCase):
00076             def runTest(self): raise MyException()
00077             def test(self): pass
00078 
00079         self.assertEqual(Test().id()[-13:], '.Test.runTest')
00080 
00081         # test that TestCase can be instantiated with no args
00082         # primarily for use at the interactive interpreter
00083         test = unittest.TestCase()
00084         test.assertEqual(3, 3)
00085         with test.assertRaises(test.failureException):
00086             test.assertEqual(3, 2)
00087 
00088         with self.assertRaises(AttributeError):
00089             test.run()

Here is the call graph for this function:

Definition at line 105 of file test_case.py.

00105 
00106     def test_init__test_name__invalid(self):
00107         class Test(unittest.TestCase):
00108             def runTest(self): raise MyException()
00109             def test(self): pass
00110 
00111         try:
00112             Test('testfoo')
00113         except ValueError:
00114             pass
00115         else:
00116             self.fail("Failed to raise ValueError")

Here is the call graph for this function:

Definition at line 94 of file test_case.py.

00094 
00095     def test_init__test_name__valid(self):
00096         class Test(unittest.TestCase):
00097             def runTest(self): raise MyException()
00098             def test(self): pass
00099 
00100         self.assertEqual(Test('test').id()[-10:], '.Test.test')

Here is the call graph for this function:

Definition at line 393 of file test_case.py.

00393 
00394     def test_run__uses_defaultTestResult(self):
00395         events = []
00396 
00397         class Foo(unittest.TestCase):
00398             def test(self):
00399                 events.append('test')
00400 
00401             def defaultTestResult(self):
00402                 return LoggingResult(events)
00403 
00404         # Make run() find a result object on its own
00405         Foo('test').run()
00406 
00407         expected = ['startTestRun', 'startTest', 'test', 'addSuccess',
00408             'stopTest', 'stopTestRun']
00409         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 144 of file test_case.py.

00144 
00145     def test_run_call_order__error_in_setUp(self):
00146         events = []
00147         result = LoggingResult(events)
00148 
00149         class Foo(Test.LoggingTestCase):
00150             def setUp(self):
00151                 super(Foo, self).setUp()
00152                 raise RuntimeError('raised by Foo.setUp')
00153 
00154         Foo(events).run(result)
00155         expected = ['startTest', 'setUp', 'addError', 'stopTest']
00156         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 158 of file test_case.py.

00158 
00159     def test_run_call_order__error_in_setUp_default_result(self):
00160         events = []
00161 
00162         class Foo(Test.LoggingTestCase):
00163             def defaultTestResult(self):
00164                 return LoggingResult(self.events)
00165 
00166             def setUp(self):
00167                 super(Foo, self).setUp()
00168                 raise RuntimeError('raised by Foo.setUp')
00169 
00170         Foo(events).run()
00171         expected = ['startTestRun', 'startTest', 'setUp', 'addError',
00172                     'stopTest', 'stopTestRun']
00173         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 257 of file test_case.py.

00257 
00258     def test_run_call_order__error_in_tearDown(self):
00259         events = []
00260         result = LoggingResult(events)
00261 
00262         class Foo(Test.LoggingTestCase):
00263             def tearDown(self):
00264                 super(Foo, self).tearDown()
00265                 raise RuntimeError('raised by Foo.tearDown')
00266 
00267         Foo(events).run(result)
00268         expected = ['startTest', 'setUp', 'test', 'tearDown', 'addError',
00269                     'stopTest']
00270         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 272 of file test_case.py.

00272 
00273     def test_run_call_order__error_in_tearDown_default_result(self):
00274 
00275         class Foo(Test.LoggingTestCase):
00276             def defaultTestResult(self):
00277                 return LoggingResult(self.events)
00278             def tearDown(self):
00279                 super(Foo, self).tearDown()
00280                 raise RuntimeError('raised by Foo.tearDown')
00281 
00282         events = []
00283         Foo(events).run()
00284         expected = ['startTestRun', 'startTest', 'setUp', 'test', 'tearDown',
00285                     'addError', 'stopTest', 'stopTestRun']
00286         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 181 of file test_case.py.

00181 
00182     def test_run_call_order__error_in_test(self):
00183         events = []
00184         result = LoggingResult(events)
00185 
00186         class Foo(Test.LoggingTestCase):
00187             def test(self):
00188                 super(Foo, self).test()
00189                 raise RuntimeError('raised by Foo.test')
00190 
00191         expected = ['startTest', 'setUp', 'test', 'tearDown',
00192                     'addError', 'stopTest']
00193         Foo(events).run(result)
00194         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 197 of file test_case.py.

00197 
00198     def test_run_call_order__error_in_test_default_result(self):
00199         events = []
00200 
00201         class Foo(Test.LoggingTestCase):
00202             def defaultTestResult(self):
00203                 return LoggingResult(self.events)
00204 
00205             def test(self):
00206                 super(Foo, self).test()
00207                 raise RuntimeError('raised by Foo.test')
00208 
00209         expected = ['startTestRun', 'startTest', 'setUp', 'test',
00210                     'tearDown', 'addError', 'stopTest', 'stopTestRun']
00211         Foo(events).run()
00212         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 220 of file test_case.py.

00220 
00221     def test_run_call_order__failure_in_test(self):
00222         events = []
00223         result = LoggingResult(events)
00224 
00225         class Foo(Test.LoggingTestCase):
00226             def test(self):
00227                 super(Foo, self).test()
00228                 self.fail('raised by Foo.test')
00229 
00230         expected = ['startTest', 'setUp', 'test', 'tearDown',
00231                     'addFailure', 'stopTest']
00232         Foo(events).run(result)
00233         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 235 of file test_case.py.

00235 
00236     def test_run_call_order__failure_in_test_default_result(self):
00237 
00238         class Foo(Test.LoggingTestCase):
00239             def defaultTestResult(self):
00240                 return LoggingResult(self.events)
00241             def test(self):
00242                 super(Foo, self).test()
00243                 self.fail('raised by Foo.test')
00244 
00245         expected = ['startTestRun', 'startTest', 'setUp', 'test',
00246                     'tearDown', 'addFailure', 'stopTest', 'stopTestRun']
00247         events = []
00248         Foo(events).run()
00249         self.assertEqual(events, expected)

Here is the call graph for this function:

Definition at line 289 of file test_case.py.

00289 
00290     def test_run_call_order_default_result(self):
00291 
00292         class Foo(unittest.TestCase):
00293             def defaultTestResult(self):
00294                 return ResultWithNoStartTestRunStopTestRun()
00295             def test(self):
00296                 pass
00297 
00298         Foo('test').run()

Definition at line 358 of file test_case.py.

00358 
00359     def test_setUp(self):
00360         class Foo(unittest.TestCase):
00361             def runTest(self):
00362                 pass
00363 
00364         # ... and nothing should happen
00365         Foo().setUp()

Definition at line 367 of file test_case.py.

00367 
00368     def test_tearDown(self):
00369         class Foo(unittest.TestCase):
00370             def runTest(self):
00371                 pass
00372 
00373         # ... and nothing should happen
00374         Foo().tearDown()

Definition at line 435 of file test_case.py.

00435 
00436     def testAddTypeEqualityFunc(self):
00437         class SadSnake(object):
00438             """Dummy class for test_addTypeEqualityFunc."""
00439         s1, s2 = SadSnake(), SadSnake()
00440         self.assertFalse(s1 == s2)
00441         def AllSnakesCreatedEqual(a, b, msg=None):
00442             return type(a) == type(b) == SadSnake
00443         self.addTypeEqualityFunc(SadSnake, AllSnakesCreatedEqual)
00444         self.assertEqual(s1, s2)
00445         # No this doesn't clean up and remove the SadSnake equality func
00446         # from this TestCase instance but since its a local nothing else
00447         # will ever notice that.

Definition at line 918 of file test_case.py.

00918 
00919     def testAsertEqualSingleLine(self):
00920         sample_text = "laden swallows fly slowly"
00921         revised_sample_text = "unladen swallows fly quickly"
00922         sample_text_error = """\
00923 - laden swallows fly slowly
00924 ?                    ^^^^
00925 + unladen swallows fly quickly
00926 ? ++                   ^^^^^
00927 """
00928         try:
00929             self.assertEqual(sample_text, revised_sample_text)
00930         except self.failureException as e:
00931             error = str(e).split('\n', 1)[1]
00932             self.assertTrue(sample_text_error == error)

Here is the call graph for this function:

Definition at line 724 of file test_case.py.

00724 
00725     def testAssertCountEqual(self):
00726         a = object()
00727         self.assertCountEqual([1, 2, 3], [3, 2, 1])
00728         self.assertCountEqual(['foo', 'bar', 'baz'], ['bar', 'baz', 'foo'])
00729         self.assertCountEqual([a, a, 2, 2, 3], (a, 2, 3, a, 2))
00730         self.assertCountEqual([1, "2", "a", "a"], ["a", "2", True, "a"])
00731         self.assertRaises(self.failureException, self.assertCountEqual,
00732                           [1, 2] + [3] * 100, [1] * 100 + [2, 3])
00733         self.assertRaises(self.failureException, self.assertCountEqual,
00734                           [1, "2", "a", "a"], ["a", "2", True, 1])
00735         self.assertRaises(self.failureException, self.assertCountEqual,
00736                           [10], [10, 11])
00737         self.assertRaises(self.failureException, self.assertCountEqual,
00738                           [10, 11], [10])
00739         self.assertRaises(self.failureException, self.assertCountEqual,
00740                           [10, 11, 10], [10, 11])
00741 
00742         # Test that sequences of unhashable objects can be tested for sameness:
00743         self.assertCountEqual([[1, 2], [3, 4], 0], [False, [3, 4], [1, 2]])
00744         # Test that iterator of unhashable objects can be tested for sameness:
00745         self.assertCountEqual(iter([1, 2, [], 3, 4]),
00746                               iter([1, 2, [], 3, 4]))
00747 
00748         # hashable types, but not orderable
00749         self.assertRaises(self.failureException, self.assertCountEqual,
00750                           [], [divmod, 'x', 1, 5j, 2j, frozenset()])
00751         # comparing dicts
00752         self.assertCountEqual([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}])
00753         # comparing heterogenous non-hashable sequences
00754         self.assertCountEqual([1, 'x', divmod, []], [divmod, [], 'x', 1])
00755         self.assertRaises(self.failureException, self.assertCountEqual,
00756                           [], [divmod, [], 'x', 1, 5j, 2j, set()])
00757         self.assertRaises(self.failureException, self.assertCountEqual,
00758                           [[1]], [[2]])
00759 
00760         # Same elements, but not same sequence length
00761         self.assertRaises(self.failureException, self.assertCountEqual,
00762                           [1, 1, 2], [2, 1])
00763         self.assertRaises(self.failureException, self.assertCountEqual,
00764                           [1, 1, "2", "a", "a"], ["2", "2", True, "a"])
00765         self.assertRaises(self.failureException, self.assertCountEqual,
00766                           [1, {'b': 2}, None, True], [{'b': 2}, True, None])
00767 
00768         # Same elements which don't reliably compare, in
00769         # different order, see issue 10242
00770         a = [{2,4}, {1,2}]
00771         b = a[::-1]
00772         self.assertCountEqual(a, b)
00773 
00774         # test utility functions supporting assertCountEqual()
00775 
00776         diffs = set(unittest.util._count_diff_all_purpose('aaabccd', 'abbbcce'))
00777         expected = {(3,1,'a'), (1,3,'b'), (1,0,'d'), (0,1,'e')}
00778         self.assertEqual(diffs, expected)
00779 
00780         diffs = unittest.util._count_diff_all_purpose([[]], [])
00781         self.assertEqual(diffs, [(1, 0, [])])
00782 
00783         diffs = set(unittest.util._count_diff_hashable('aaabccd', 'abbbcce'))
00784         expected = {(3,1,'a'), (1,3,'b'), (1,0,'d'), (0,1,'e')}
00785         self.assertEqual(diffs, expected)

Here is the call graph for this function:

Definition at line 491 of file test_case.py.

00491 
00492     def testAssertDictContainsSubset(self):
00493         with warnings.catch_warnings():
00494             warnings.simplefilter("ignore", DeprecationWarning)
00495 
00496             self.assertDictContainsSubset({}, {})
00497             self.assertDictContainsSubset({}, {'a': 1})
00498             self.assertDictContainsSubset({'a': 1}, {'a': 1})
00499             self.assertDictContainsSubset({'a': 1}, {'a': 1, 'b': 2})
00500             self.assertDictContainsSubset({'a': 1, 'b': 2}, {'a': 1, 'b': 2})
00501 
00502             with self.assertRaises(self.failureException):
00503                 self.assertDictContainsSubset({1: "one"}, {})
00504 
00505             with self.assertRaises(self.failureException):
00506                 self.assertDictContainsSubset({'a': 2}, {'a': 1})
00507 
00508             with self.assertRaises(self.failureException):
00509                 self.assertDictContainsSubset({'c': 1}, {'a': 1})
00510 
00511             with self.assertRaises(self.failureException):
00512                 self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})
00513 
00514             with self.assertRaises(self.failureException):
00515                 self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1})
00516 
00517             one = ''.join(chr(i) for i in range(255))
00518             # this used to cause a UnicodeDecodeError constructing the failure msg
00519             with self.assertRaises(self.failureException):
00520                 self.assertDictContainsSubset({'foo': one}, {'foo': '\uFFFD'})

Here is the call graph for this function:

Definition at line 664 of file test_case.py.

00664 
00665     def testAssertDictEqualTruncates(self):
00666         test = unittest.TestCase('assertEqual')
00667         def truncate(msg, diff):
00668             return 'foo'
00669         test._truncateMessage = truncate
00670         try:
00671             test.assertDictEqual({}, {1: 0})
00672         except self.failureException as e:
00673             self.assertEqual(str(e), 'foo')
00674         else:
00675             self.fail('assertDictEqual did not fail')

Here is the call graph for this function:

Definition at line 521 of file test_case.py.

00521 
00522     def testAssertEqual(self):
00523         equal_pairs = [
00524                 ((), ()),
00525                 ({}, {}),
00526                 ([], []),
00527                 (set(), set()),
00528                 (frozenset(), frozenset())]
00529         for a, b in equal_pairs:
00530             # This mess of try excepts is to test the assertEqual behavior
00531             # itself.
00532             try:
00533                 self.assertEqual(a, b)
00534             except self.failureException:
00535                 self.fail('assertEqual(%r, %r) failed' % (a, b))
00536             try:
00537                 self.assertEqual(a, b, msg='foo')
00538             except self.failureException:
00539                 self.fail('assertEqual(%r, %r) with msg= failed' % (a, b))
00540             try:
00541                 self.assertEqual(a, b, 'foo')
00542             except self.failureException:
00543                 self.fail('assertEqual(%r, %r) with third parameter failed' %
00544                           (a, b))
00545 
00546         unequal_pairs = [
00547                ((), []),
00548                ({}, set()),
00549                (set([4,1]), frozenset([4,2])),
00550                (frozenset([4,5]), set([2,3])),
00551                (set([3,4]), set([5,4]))]
00552         for a, b in unequal_pairs:
00553             self.assertRaises(self.failureException, self.assertEqual, a, b)
00554             self.assertRaises(self.failureException, self.assertEqual, a, b,
00555                               'foo')
00556             self.assertRaises(self.failureException, self.assertEqual, a, b,
00557                               msg='foo')

Here is the call graph for this function:

Definition at line 688 of file test_case.py.

00688 
00689     def testAssertEqual_diffThreshold(self):
00690         # check threshold value
00691         self.assertEqual(self._diffThreshold, 2**16)
00692         # disable madDiff to get diff markers
00693         self.maxDiff = None
00694 
00695         # set a lower threshold value and add a cleanup to restore it
00696         old_threshold = self._diffThreshold
00697         self._diffThreshold = 2**8
00698         self.addCleanup(lambda: setattr(self, '_diffThreshold', old_threshold))
00699 
00700         # under the threshold: diff marker (^) in error message
00701         s = 'x' * (2**7)
00702         with self.assertRaises(self.failureException) as cm:
00703             self.assertEqual(s + 'a', s + 'b')
00704         self.assertIn('^', str(cm.exception))
00705         self.assertEqual(s + 'a', s + 'a')
00706 
00707         # over the threshold: diff not used and marker (^) not in error message
00708         s = 'x' * (2**9)
00709         # if the path that uses difflib is taken, _truncateMessage will be
00710         # called -- replace it with explodingTruncation to verify that this
00711         # doesn't happen
00712         def explodingTruncation(message, diff):
00713             raise SystemError('this should not be raised')
00714         old_truncate = self._truncateMessage
00715         self._truncateMessage = explodingTruncation
00716         self.addCleanup(lambda: setattr(self, '_truncateMessage', old_truncate))
00717 
00718         s1, s2 = s + 'a', s + 'b'
00719         with self.assertRaises(self.failureException) as cm:
00720             self.assertEqual(s1, s2)
00721         self.assertNotIn('^', str(cm.exception))
00722         self.assertEqual(str(cm.exception), '%r != %r' % (s1, s2))
00723         self.assertEqual(s + 'a', s + 'a')

Here is the call graph for this function:

Definition at line 470 of file test_case.py.

00470 
00471     def testAssertIn(self):
00472         animals = {'monkey': 'banana', 'cow': 'grass', 'seal': 'fish'}
00473 
00474         self.assertIn('a', 'abc')
00475         self.assertIn(2, [1, 2, 3])
00476         self.assertIn('monkey', animals)
00477 
00478         self.assertNotIn('d', 'abc')
00479         self.assertNotIn(0, [1, 2, 3])
00480         self.assertNotIn('otter', animals)
00481 
00482         self.assertRaises(self.failureException, self.assertIn, 'x', 'abc')
00483         self.assertRaises(self.failureException, self.assertIn, 4, [1, 2, 3])
00484         self.assertRaises(self.failureException, self.assertIn, 'elephant',
00485                           animals)
00486 
00487         self.assertRaises(self.failureException, self.assertNotIn, 'c', 'abc')
00488         self.assertRaises(self.failureException, self.assertNotIn, 1, [1, 2, 3])
00489         self.assertRaises(self.failureException, self.assertNotIn, 'cow',
00490                           animals)

Here is the call graph for this function:

Definition at line 448 of file test_case.py.

00448 
00449     def testAssertIs(self):
00450         thing = object()
00451         self.assertIs(thing, thing)
00452         self.assertRaises(self.failureException, self.assertIs, thing, object())

Here is the call graph for this function:

Definition at line 458 of file test_case.py.

00458 
00459     def testAssertIsInstance(self):
00460         thing = []
00461         self.assertIsInstance(thing, list)
00462         self.assertRaises(self.failureException, self.assertIsInstance,
00463                           thing, dict)

Here is the call graph for this function:

Definition at line 933 of file test_case.py.

00933 
00934     def testAssertIsNone(self):
00935         self.assertIsNone(None)
00936         self.assertRaises(self.failureException, self.assertIsNone, False)
00937         self.assertIsNotNone('DjZoPloGears on Rails')
00938         self.assertRaises(self.failureException, self.assertIsNotNone, None)

Here is the call graph for this function:

Definition at line 453 of file test_case.py.

00453 
00454     def testAssertIsNot(self):
00455         thing = object()
00456         self.assertIsNot(thing, object())
00457         self.assertRaises(self.failureException, self.assertIsNot, thing, thing)

Here is the call graph for this function:

Definition at line 884 of file test_case.py.

00884 
00885     def testAssertMultiLineEqual(self):
00886         sample_text = """\
00887 http://www.python.org/doc/2.3/lib/module-unittest.html
00888 test case
00889     A test case is the smallest unit of testing. [...]
00890 """
00891         revised_sample_text = """\
00892 http://www.python.org/doc/2.4.1/lib/module-unittest.html
00893 test case
00894     A test case is the smallest unit of testing. [...] You may provide your
00895     own implementation that does not subclass from TestCase, of course.
00896 """
00897         sample_text_error = """\
00898 - http://www.python.org/doc/2.3/lib/module-unittest.html
00899 ?                             ^
00900 + http://www.python.org/doc/2.4.1/lib/module-unittest.html
00901 ?                             ^^^
00902   test case
00903 -     A test case is the smallest unit of testing. [...]
00904 +     A test case is the smallest unit of testing. [...] You may provide your
00905 ?                                                       +++++++++++++++++++++
00906 +     own implementation that does not subclass from TestCase, of course.
00907 """
00908         self.maxDiff = None
00909         try:
00910             self.assertMultiLineEqual(sample_text, revised_sample_text)
00911         except self.failureException as e:
00912             # need to remove the first line of the error message
00913             error = str(e).split('\n', 1)[1]
00914 
00915             # no fair testing ourself with ourself, and assertEqual is used for strings
00916             # so can't use assertEqual either. Just use assertTrue.
00917             self.assertTrue(sample_text_error == error)

Here is the call graph for this function:

Definition at line 676 of file test_case.py.

00676 
00677     def testAssertMultiLineEqualTruncates(self):
00678         test = unittest.TestCase('assertEqual')
00679         def truncate(msg, diff):
00680             return 'foo'
00681         test._truncateMessage = truncate
00682         try:
00683             test.assertMultiLineEqual('foo', 'bar')
00684         except self.failureException as e:
00685             self.assertEqual(str(e), 'foo')
00686         else:
00687             self.fail('assertMultiLineEqual did not fail')

Here is the call graph for this function:

Definition at line 464 of file test_case.py.

00464 
00465     def testAssertNotIsInstance(self):
00466         thing = []
00467         self.assertNotIsInstance(thing, dict)
00468         self.assertRaises(self.failureException, self.assertNotIsInstance,
00469                           thing, list)

Here is the call graph for this function:

Definition at line 954 of file test_case.py.

00954 
00955     def testAssertNotRaisesRegex(self):
00956         self.assertRaisesRegex(
00957                 self.failureException, '^Exception not raised by <lambda>$',
00958                 self.assertRaisesRegex, Exception, re.compile('x'),
00959                 lambda: None)
00960         self.assertRaisesRegex(
00961                 self.failureException, '^Exception not raised by <lambda>$',
00962                 self.assertRaisesRegex, Exception, 'x',
00963                 lambda: None)

Here is the call graph for this function:

Definition at line 979 of file test_case.py.

00979 
00980     def testAssertRaisesExcValue(self):
00981         class ExceptionMock(Exception):
00982             pass
00983 
00984         def Stub(foo):
00985             raise ExceptionMock(foo)
00986         v = "particular value"
00987 
00988         ctx = self.assertRaises(ExceptionMock)
00989         with ctx:
00990             Stub(v)
00991         e = ctx.exception
00992         self.assertIsInstance(e, ExceptionMock)
00993         self.assertEqual(e.args[0], v)

Definition at line 944 of file test_case.py.

00944 
00945     def testAssertRaisesRegex(self):
00946         class ExceptionMock(Exception):
00947             pass
00948 
00949         def Stub():
00950             raise ExceptionMock('We expect')
00951 
00952         self.assertRaisesRegex(ExceptionMock, re.compile('expect$'), Stub)
00953         self.assertRaisesRegex(ExceptionMock, 'expect$', Stub)

Definition at line 964 of file test_case.py.

00964 
00965     def testAssertRaisesRegexMismatch(self):
00966         def Stub():
00967             raise Exception('Unexpected')
00968 
00969         self.assertRaisesRegex(
00970                 self.failureException,
00971                 r'"\^Expected\$" does not match "Unexpected"',
00972                 self.assertRaisesRegex, Exception, '^Expected$',
00973                 Stub)
00974         self.assertRaisesRegex(
00975                 self.failureException,
00976                 r'"\^Expected\$" does not match "Unexpected"',
00977                 self.assertRaisesRegex, Exception,
00978                 re.compile('^Expected$'), Stub)

Here is the call graph for this function:

Definition at line 939 of file test_case.py.

00939 
00940     def testAssertRegex(self):
00941         self.assertRegex('asdfabasdf', r'ab+')
00942         self.assertRaises(self.failureException, self.assertRegex,
00943                           'saaas', r'aaaa')

Here is the call graph for this function:

Definition at line 610 of file test_case.py.

00610 
00611     def testAssertSequenceEqualMaxDiff(self):
00612         self.assertEqual(self.maxDiff, 80*8)
00613         seq1 = 'a' + 'x' * 80**2
00614         seq2 = 'b' + 'x' * 80**2
00615         diff = '\n'.join(difflib.ndiff(pprint.pformat(seq1).splitlines(),
00616                                        pprint.pformat(seq2).splitlines()))
00617         # the +1 is the leading \n added by assertSequenceEqual
00618         omitted = unittest.case.DIFF_OMITTED % (len(diff) + 1,)
00619 
00620         self.maxDiff = len(diff)//2
00621         try:
00622 
00623             self.assertSequenceEqual(seq1, seq2)
00624         except self.failureException as e:
00625             msg = e.args[0]
00626         else:
00627             self.fail('assertSequenceEqual did not fail.')
00628         self.assertTrue(len(msg) < len(diff))
00629         self.assertIn(omitted, msg)
00630 
00631         self.maxDiff = len(diff) * 2
00632         try:
00633             self.assertSequenceEqual(seq1, seq2)
00634         except self.failureException as e:
00635             msg = e.args[0]
00636         else:
00637             self.fail('assertSequenceEqual did not fail.')
00638         self.assertTrue(len(msg) > len(diff))
00639         self.assertNotIn(omitted, msg)
00640 
00641         self.maxDiff = None
00642         try:
00643             self.assertSequenceEqual(seq1, seq2)
00644         except self.failureException as e:
00645             msg = e.args[0]
00646         else:
00647             self.fail('assertSequenceEqual did not fail.')
00648         self.assertTrue(len(msg) > len(diff))
00649         self.assertNotIn(omitted, msg)

Here is the call graph for this function:

Definition at line 786 of file test_case.py.

00786 
00787     def testAssertSetEqual(self):
00788         set1 = set()
00789         set2 = set()
00790         self.assertSetEqual(set1, set2)
00791 
00792         self.assertRaises(self.failureException, self.assertSetEqual, None, set2)
00793         self.assertRaises(self.failureException, self.assertSetEqual, [], set2)
00794         self.assertRaises(self.failureException, self.assertSetEqual, set1, None)
00795         self.assertRaises(self.failureException, self.assertSetEqual, set1, [])
00796 
00797         set1 = set(['a'])
00798         set2 = set()
00799         self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
00800 
00801         set1 = set(['a'])
00802         set2 = set(['a'])
00803         self.assertSetEqual(set1, set2)
00804 
00805         set1 = set(['a'])
00806         set2 = set(['a', 'b'])
00807         self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
00808 
00809         set1 = set(['a'])
00810         set2 = frozenset(['a', 'b'])
00811         self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
00812 
00813         set1 = set(['a', 'b'])
00814         set2 = frozenset(['a', 'b'])
00815         self.assertSetEqual(set1, set2)
00816 
00817         set1 = set()
00818         set2 = "foo"
00819         self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)
00820         self.assertRaises(self.failureException, self.assertSetEqual, set2, set1)
00821 
00822         # make sure any string formatting is tuple-safe
00823         set1 = set([(0, 1), (2, 3)])
00824         set2 = set([(4, 5)])
00825         self.assertRaises(self.failureException, self.assertSetEqual, set1, set2)

Here is the call graph for this function:

Definition at line 994 of file test_case.py.

00994 
00995     def testAssertWarnsCallable(self):
00996         def _runtime_warn():
00997             warnings.warn("foo", RuntimeWarning)
00998         # Success when the right warning is triggered, even several times
00999         self.assertWarns(RuntimeWarning, _runtime_warn)
01000         self.assertWarns(RuntimeWarning, _runtime_warn)
01001         # A tuple of warning classes is accepted
01002         self.assertWarns((DeprecationWarning, RuntimeWarning), _runtime_warn)
01003         # *args and **kwargs also work
01004         self.assertWarns(RuntimeWarning,
01005                          warnings.warn, "foo", category=RuntimeWarning)
01006         # Failure when no warning is triggered
01007         with self.assertRaises(self.failureException):
01008             self.assertWarns(RuntimeWarning, lambda: 0)
01009         # Failure when another warning is triggered
01010         with warnings.catch_warnings():
01011             # Force default filter (in case tests are run with -We)
01012             warnings.simplefilter("default", RuntimeWarning)
01013             with self.assertRaises(self.failureException):
01014                 self.assertWarns(DeprecationWarning, _runtime_warn)
01015         # Filters for other warnings are not modified
01016         with warnings.catch_warnings():
01017             warnings.simplefilter("error", RuntimeWarning)
01018             with self.assertRaises(RuntimeWarning):
01019                 self.assertWarns(DeprecationWarning, _runtime_warn)

Here is the call graph for this function:

Definition at line 1020 of file test_case.py.

01020 
01021     def testAssertWarnsContext(self):
01022         # Believe it or not, it is preferrable to duplicate all tests above,
01023         # to make sure the __warningregistry__ $@ is circumvented correctly.
01024         def _runtime_warn():
01025             warnings.warn("foo", RuntimeWarning)
01026         _runtime_warn_lineno = inspect.getsourcelines(_runtime_warn)[1]
01027         with self.assertWarns(RuntimeWarning) as cm:
01028             _runtime_warn()
01029         # A tuple of warning classes is accepted
01030         with self.assertWarns((DeprecationWarning, RuntimeWarning)) as cm:
01031             _runtime_warn()
01032         # The context manager exposes various useful attributes
01033         self.assertIsInstance(cm.warning, RuntimeWarning)
01034         self.assertEqual(cm.warning.args[0], "foo")
01035         self.assertIn("test_case.py", cm.filename)
01036         self.assertEqual(cm.lineno, _runtime_warn_lineno + 1)
01037         # Same with several warnings
01038         with self.assertWarns(RuntimeWarning):
01039             _runtime_warn()
01040             _runtime_warn()
01041         with self.assertWarns(RuntimeWarning):
01042             warnings.warn("foo", category=RuntimeWarning)
01043         # Failure when no warning is triggered
01044         with self.assertRaises(self.failureException):
01045             with self.assertWarns(RuntimeWarning):
01046                 pass
01047         # Failure when another warning is triggered
01048         with warnings.catch_warnings():
01049             # Force default filter (in case tests are run with -We)
01050             warnings.simplefilter("default", RuntimeWarning)
01051             with self.assertRaises(self.failureException):
01052                 with self.assertWarns(DeprecationWarning):
01053                     _runtime_warn()
01054         # Filters for other warnings are not modified
01055         with warnings.catch_warnings():
01056             warnings.simplefilter("error", RuntimeWarning)
01057             with self.assertRaises(RuntimeWarning):
01058                 with self.assertWarns(DeprecationWarning):
01059                     _runtime_warn()

Here is the call graph for this function:

Definition at line 1060 of file test_case.py.

01060 
01061     def testAssertWarnsRegexCallable(self):
01062         def _runtime_warn(msg):
01063             warnings.warn(msg, RuntimeWarning)
01064         self.assertWarnsRegex(RuntimeWarning, "o+",
01065                               _runtime_warn, "foox")
01066         # Failure when no warning is triggered
01067         with self.assertRaises(self.failureException):
01068             self.assertWarnsRegex(RuntimeWarning, "o+",
01069                                   lambda: 0)
01070         # Failure when another warning is triggered
01071         with warnings.catch_warnings():
01072             # Force default filter (in case tests are run with -We)
01073             warnings.simplefilter("default", RuntimeWarning)
01074             with self.assertRaises(self.failureException):
01075                 self.assertWarnsRegex(DeprecationWarning, "o+",
01076                                       _runtime_warn, "foox")
01077         # Failure when message doesn't match
01078         with self.assertRaises(self.failureException):
01079             self.assertWarnsRegex(RuntimeWarning, "o+",
01080                                   _runtime_warn, "barz")
01081         # A little trickier: we ask RuntimeWarnings to be raised, and then
01082         # check for some of them.  It is implementation-defined whether
01083         # non-matching RuntimeWarnings are simply re-raised, or produce a
01084         # failureException.
01085         with warnings.catch_warnings():
01086             warnings.simplefilter("error", RuntimeWarning)
01087             with self.assertRaises((RuntimeWarning, self.failureException)):
01088                 self.assertWarnsRegex(RuntimeWarning, "o+",
01089                                       _runtime_warn, "barz")

Here is the call graph for this function:

Definition at line 1090 of file test_case.py.

01090 
01091     def testAssertWarnsRegexContext(self):
01092         # Same as above, but with assertWarnsRegex as a context manager
01093         def _runtime_warn(msg):
01094             warnings.warn(msg, RuntimeWarning)
01095         _runtime_warn_lineno = inspect.getsourcelines(_runtime_warn)[1]
01096         with self.assertWarnsRegex(RuntimeWarning, "o+") as cm:
01097             _runtime_warn("foox")
01098         self.assertIsInstance(cm.warning, RuntimeWarning)
01099         self.assertEqual(cm.warning.args[0], "foox")
01100         self.assertIn("test_case.py", cm.filename)
01101         self.assertEqual(cm.lineno, _runtime_warn_lineno + 1)
01102         # Failure when no warning is triggered
01103         with self.assertRaises(self.failureException):
01104             with self.assertWarnsRegex(RuntimeWarning, "o+"):
01105                 pass
01106         # Failure when another warning is triggered
01107         with warnings.catch_warnings():
01108             # Force default filter (in case tests are run with -We)
01109             warnings.simplefilter("default", RuntimeWarning)
01110             with self.assertRaises(self.failureException):
01111                 with self.assertWarnsRegex(DeprecationWarning, "o+"):
01112                     _runtime_warn("foox")
01113         # Failure when message doesn't match
01114         with self.assertRaises(self.failureException):
01115             with self.assertWarnsRegex(RuntimeWarning, "o+"):
01116                 _runtime_warn("barz")
01117         # A little trickier: we ask RuntimeWarnings to be raised, and then
01118         # check for some of them.  It is implementation-defined whether
01119         # non-matching RuntimeWarnings are simply re-raised, or produce a
01120         # failureException.
01121         with warnings.catch_warnings():
01122             warnings.simplefilter("error", RuntimeWarning)
01123             with self.assertRaises((RuntimeWarning, self.failureException)):
01124                 with self.assertWarnsRegex(RuntimeWarning, "o+"):
01125                     _runtime_warn("barz")

Here is the call graph for this function:

Definition at line 1165 of file test_case.py.

01165 
01166     def testDeepcopy(self):
01167         # Issue: 5660
01168         class TestableTest(unittest.TestCase):
01169             def testNothing(self):
01170                 pass
01171 
01172         test = TestableTest('testNothing')
01173 
01174         # This shouldn't blow up
01175         deepcopy(test)

Test that the deprecated fail* methods get removed in 3.3

Definition at line 1152 of file test_case.py.

01152 
01153     def testDeprecatedFailMethods(self):
01154         """Test that the deprecated fail* methods get removed in 3.3"""
01155         if sys.version_info[:2] < (3, 3):
01156             return
01157         deprecated_names = [
01158             'failIfEqual', 'failUnlessEqual', 'failUnlessAlmostEqual',
01159             'failIfAlmostEqual', 'failUnless', 'failUnlessRaises', 'failIf',
01160             'assertSameElements', 'assertDictContainsSubset',
01161         ]
01162         for deprecated_name in deprecated_names:
01163             with self.assertRaises(AttributeError):
01164                 getattr(self, deprecated_name)  # remove these in 3.3

Here is the call graph for this function:

Test that the deprecated methods raise a DeprecationWarning. See #9424.

Definition at line 1126 of file test_case.py.

01126 
01127     def testDeprecatedMethodNames(self):
01128         """
01129         Test that the deprecated methods raise a DeprecationWarning. See #9424.
01130         """
01131         old = (
01132             (self.failIfEqual, (3, 5)),
01133             (self.assertNotEquals, (3, 5)),
01134             (self.failUnlessEqual, (3, 3)),
01135             (self.assertEquals, (3, 3)),
01136             (self.failUnlessAlmostEqual, (2.0, 2.0)),
01137             (self.assertAlmostEquals, (2.0, 2.0)),
01138             (self.failIfAlmostEqual, (3.0, 5.0)),
01139             (self.assertNotAlmostEquals, (3.0, 5.0)),
01140             (self.failUnless, (True,)),
01141             (self.assert_, (True,)),
01142             (self.failUnlessRaises, (TypeError, lambda _: 3.14 + 'spam')),
01143             (self.failIf, (False,)),
01144             (self.assertSameElements, ([1, 1, 2, 3], [1, 2, 3])),
01145             (self.assertDictContainsSubset, (dict(a=1, b=2), dict(a=1, b=2, c=3))),
01146             (self.assertRaisesRegexp, (KeyError, 'foo', lambda: {}['foo'])),
01147             (self.assertRegexpMatches, ('bar', 'bar')),
01148         )
01149         for meth, args in old:
01150             with self.assertWarns(DeprecationWarning):
01151                 meth(*args)

Here is the call graph for this function:

Definition at line 558 of file test_case.py.

00558 
00559     def testEquality(self):
00560         self.assertListEqual([], [])
00561         self.assertTupleEqual((), ())
00562         self.assertSequenceEqual([], ())
00563 
00564         a = [0, 'a', []]
00565         b = []
00566         self.assertRaises(unittest.TestCase.failureException,
00567                           self.assertListEqual, a, b)
00568         self.assertRaises(unittest.TestCase.failureException,
00569                           self.assertListEqual, tuple(a), tuple(b))
00570         self.assertRaises(unittest.TestCase.failureException,
00571                           self.assertSequenceEqual, a, tuple(b))
00572 
00573         b.extend(a)
00574         self.assertListEqual(a, b)
00575         self.assertTupleEqual(tuple(a), tuple(b))
00576         self.assertSequenceEqual(a, tuple(b))
00577         self.assertSequenceEqual(tuple(a), b)
00578 
00579         self.assertRaises(self.failureException, self.assertListEqual,
00580                           a, tuple(b))
00581         self.assertRaises(self.failureException, self.assertTupleEqual,
00582                           tuple(a), b)
00583         self.assertRaises(self.failureException, self.assertListEqual, None, b)
00584         self.assertRaises(self.failureException, self.assertTupleEqual, None,
00585                           tuple(b))
00586         self.assertRaises(self.failureException, self.assertSequenceEqual,
00587                           None, tuple(b))
00588         self.assertRaises(self.failureException, self.assertListEqual, 1, 1)
00589         self.assertRaises(self.failureException, self.assertTupleEqual, 1, 1)
00590         self.assertRaises(self.failureException, self.assertSequenceEqual,
00591                           1, 1)
00592 
00593         self.assertDictEqual({}, {})
00594 
00595         c = { 'x': 1 }
00596         d = {}
00597         self.assertRaises(unittest.TestCase.failureException,
00598                           self.assertDictEqual, c, d)
00599 
00600         d.update(c)
00601         self.assertDictEqual(c, d)
00602 
00603         d['x'] = 0
00604         self.assertRaises(unittest.TestCase.failureException,
00605                           self.assertDictEqual, c, d, 'These are unequal')
00606 
00607         self.assertRaises(self.failureException, self.assertDictEqual, None, d)
00608         self.assertRaises(self.failureException, self.assertDictEqual, [], d)
00609         self.assertRaises(self.failureException, self.assertDictEqual, 1, 1)

Here is the call graph for this function:

Definition at line 826 of file test_case.py.

00826 
00827     def testInequality(self):
00828         # Try ints
00829         self.assertGreater(2, 1)
00830         self.assertGreaterEqual(2, 1)
00831         self.assertGreaterEqual(1, 1)
00832         self.assertLess(1, 2)
00833         self.assertLessEqual(1, 2)
00834         self.assertLessEqual(1, 1)
00835         self.assertRaises(self.failureException, self.assertGreater, 1, 2)
00836         self.assertRaises(self.failureException, self.assertGreater, 1, 1)
00837         self.assertRaises(self.failureException, self.assertGreaterEqual, 1, 2)
00838         self.assertRaises(self.failureException, self.assertLess, 2, 1)
00839         self.assertRaises(self.failureException, self.assertLess, 1, 1)
00840         self.assertRaises(self.failureException, self.assertLessEqual, 2, 1)
00841 
00842         # Try Floats
00843         self.assertGreater(1.1, 1.0)
00844         self.assertGreaterEqual(1.1, 1.0)
00845         self.assertGreaterEqual(1.0, 1.0)
00846         self.assertLess(1.0, 1.1)
00847         self.assertLessEqual(1.0, 1.1)
00848         self.assertLessEqual(1.0, 1.0)
00849         self.assertRaises(self.failureException, self.assertGreater, 1.0, 1.1)
00850         self.assertRaises(self.failureException, self.assertGreater, 1.0, 1.0)
00851         self.assertRaises(self.failureException, self.assertGreaterEqual, 1.0, 1.1)
00852         self.assertRaises(self.failureException, self.assertLess, 1.1, 1.0)
00853         self.assertRaises(self.failureException, self.assertLess, 1.0, 1.0)
00854         self.assertRaises(self.failureException, self.assertLessEqual, 1.1, 1.0)
00855 
00856         # Try Strings
00857         self.assertGreater('bug', 'ant')
00858         self.assertGreaterEqual('bug', 'ant')
00859         self.assertGreaterEqual('ant', 'ant')
00860         self.assertLess('ant', 'bug')
00861         self.assertLessEqual('ant', 'bug')
00862         self.assertLessEqual('ant', 'ant')
00863         self.assertRaises(self.failureException, self.assertGreater, 'ant', 'bug')
00864         self.assertRaises(self.failureException, self.assertGreater, 'ant', 'ant')
00865         self.assertRaises(self.failureException, self.assertGreaterEqual, 'ant', 'bug')
00866         self.assertRaises(self.failureException, self.assertLess, 'bug', 'ant')
00867         self.assertRaises(self.failureException, self.assertLess, 'ant', 'ant')
00868         self.assertRaises(self.failureException, self.assertLessEqual, 'bug', 'ant')
00869 
00870         # Try bytes
00871         self.assertGreater(b'bug', b'ant')
00872         self.assertGreaterEqual(b'bug', b'ant')
00873         self.assertGreaterEqual(b'ant', b'ant')
00874         self.assertLess(b'ant', b'bug')
00875         self.assertLessEqual(b'ant', b'bug')
00876         self.assertLessEqual(b'ant', b'ant')
00877         self.assertRaises(self.failureException, self.assertGreater, b'ant', b'bug')
00878         self.assertRaises(self.failureException, self.assertGreater, b'ant', b'ant')
00879         self.assertRaises(self.failureException, self.assertGreaterEqual, b'ant',
00880                           b'bug')
00881         self.assertRaises(self.failureException, self.assertLess, b'bug', b'ant')
00882         self.assertRaises(self.failureException, self.assertLess, b'ant', b'ant')
00883         self.assertRaises(self.failureException, self.assertLessEqual, b'bug', b'ant')

Here is the call graph for this function:

Definition at line 1193 of file test_case.py.

01193 
01194     def testKeyboardInterrupt(self):
01195         def _raise(self=None):
01196             raise KeyboardInterrupt
01197         def nothing(self):
01198             pass
01199 
01200         class Test1(unittest.TestCase):
01201             test_something = _raise
01202 
01203         class Test2(unittest.TestCase):
01204             setUp = _raise
01205             test_something = nothing
01206 
01207         class Test3(unittest.TestCase):
01208             test_something = nothing
01209             tearDown = _raise
01210 
01211         class Test4(unittest.TestCase):
01212             def test_something(self):
01213                 self.addCleanup(_raise)
01214 
01215         for klass in (Test1, Test2, Test3, Test4):
01216             with self.assertRaises(KeyboardInterrupt):
01217                 klass('test_something').run()

Definition at line 1176 of file test_case.py.

01176 
01177     def testPickle(self):
01178         # Issue 10326
01179 
01180         # Can't use TestCase classes defined in Test class as
01181         # pickle does not work with inner classes
01182         test = unittest.TestCase('run')
01183         for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
01184 
01185             # blew up prior to fix
01186             pickled_test = pickle.dumps(test, protocol=protocol)
01187             unpickled_test = pickle.loads(pickled_test)
01188             self.assertEqual(test, unpickled_test)
01189 
01190             # exercise the TestCase instance in a way that will invoke
01191             # the type equality lookup mechanism
01192             unpickled_test.assertEqual(set(), set())

Here is the call graph for this function:

Tests shortDescription() for a method with a longer docstring.

This method ensures that only the first line of a docstring is
returned used in the short description, no matter how long the
whole thing is.

Definition at line 423 of file test_case.py.

00423 
00424     def testShortDescriptionWithMultiLineDocstring(self):
00425         """Tests shortDescription() for a method with a longer docstring.
00426 
00427         This method ensures that only the first line of a docstring is
00428         returned used in the short description, no matter how long the
00429         whole thing is.
00430         """
00431         self.assertEqual(
00432                 self.shortDescription(),
00433                  'Tests shortDescription() for a method with a longer '
00434                  'docstring.')

Here is the call graph for this function:

Tests shortDescription() for a method with a docstring.

Definition at line 415 of file test_case.py.

00415 
00416     def testShortDescriptionWithOneLineDocstring(self):
00417         """Tests shortDescription() for a method with a docstring."""
00418         self.assertEqual(
00419                 self.shortDescription(),
00420                 'Tests shortDescription() for a method with a docstring.')

Here is the call graph for this function:

Definition at line 410 of file test_case.py.

00410 
00411     def testShortDescriptionWithoutDocstring(self):
00412         self.assertIsNone(self.shortDescription())

Here is the call graph for this function:

Definition at line 1218 of file test_case.py.

01218 
01219     def testSkippingEverywhere(self):
01220         def _skip(self=None):
01221             raise unittest.SkipTest('some reason')
01222         def nothing(self):
01223             pass
01224 
01225         class Test1(unittest.TestCase):
01226             test_something = _skip
01227 
01228         class Test2(unittest.TestCase):
01229             setUp = _skip
01230             test_something = nothing
01231 
01232         class Test3(unittest.TestCase):
01233             test_something = nothing
01234             tearDown = _skip
01235 
01236         class Test4(unittest.TestCase):
01237             def test_something(self):
01238                 self.addCleanup(_skip)
01239 
01240         for klass in (Test1, Test2, Test3, Test4):
01241             result = unittest.TestResult()
01242             klass('test_something').run(result)
01243             self.assertEqual(len(result.skipped), 1)
01244             self.assertEqual(result.testsRun, 1)

Definition at line 1245 of file test_case.py.

01245 
01246     def testSystemExit(self):
01247         def _raise(self=None):
01248             raise SystemExit
01249         def nothing(self):
01250             pass
01251 
01252         class Test1(unittest.TestCase):
01253             test_something = _raise
01254 
01255         class Test2(unittest.TestCase):
01256             setUp = _raise
01257             test_something = nothing
01258 
01259         class Test3(unittest.TestCase):
01260             test_something = nothing
01261             tearDown = _raise
01262 
01263         class Test4(unittest.TestCase):
01264             def test_something(self):
01265                 self.addCleanup(_raise)
01266 
01267         for klass in (Test1, Test2, Test3, Test4):
01268             result = unittest.TestResult()
01269             klass('test_something').run(result)
01270             self.assertEqual(len(result.errors), 1)
01271             self.assertEqual(result.testsRun, 1)

Definition at line 650 of file test_case.py.

00650 
00651     def testTruncateMessage(self):
00652         self.maxDiff = 1
00653         message = self._truncateMessage('foo', 'bar')
00654         omitted = unittest.case.DIFF_OMITTED % len('bar')
00655         self.assertEqual(message, 'foo' + omitted)
00656 
00657         self.maxDiff = None
00658         message = self._truncateMessage('foo', 'bar')
00659         self.assertEqual(message, 'foobar')
00660 
00661         self.maxDiff = 4
00662         message = self._truncateMessage('foo', 'bar')
00663         self.assertEqual(message, 'foobar')

Here is the call graph for this function:


Member Data Documentation

Definition at line 696 of file test_case.py.

Definition at line 714 of file test_case.py.

list unittest.test.test_case.Test_TestCase.eq_pairs = [(Test.Foo('test1'), Test.Foo('test1'))] [static]

Set up attributes used by inherited tests.

Definition at line 53 of file test_case.py.

Definition at line 619 of file test_case.py.

Initial value:
[(Test.Foo('test1'), Test.Foo('runTest')),
                (Test.Foo('test1'), Test.Bar('test1')),
                (Test.Foo('test1'), Test.Bar('test2'))]

Definition at line 56 of file test_case.py.


The documentation for this class was generated from the following file: