297
298
Called from the TestCase run() method when the test
298
299
fails with an unexpected error.
300
self._testConcluded(test)
301
if isinstance(err[1], TestNotApplicable):
302
return self._addNotApplicable(test, err)
303
elif isinstance(err[1], UnavailableFeature):
304
return self.addNotSupported(test, err[1].args[0])
307
unittest.TestResult.addError(self, test, err)
308
self.error_count += 1
309
self.report_error(test, err)
312
self._cleanupLogFile(test)
302
unittest.TestResult.addError(self, test, err)
303
self.error_count += 1
304
self.report_error(test, err)
307
self._cleanupLogFile(test)
314
309
def addFailure(self, test, err):
315
310
"""Tell result that test failed.
317
312
Called from the TestCase run() method when the test
318
313
fails because e.g. an assert() method failed.
320
self._testConcluded(test)
321
if isinstance(err[1], KnownFailure):
322
return self._addKnownFailure(test, err)
325
unittest.TestResult.addFailure(self, test, err)
326
self.failure_count += 1
327
self.report_failure(test, err)
330
self._cleanupLogFile(test)
316
unittest.TestResult.addFailure(self, test, err)
317
self.failure_count += 1
318
self.report_failure(test, err)
321
self._cleanupLogFile(test)
332
323
def addSuccess(self, test):
333
324
"""Tell result that test completed successfully.
335
326
Called from the TestCase run()
337
self._testConcluded(test)
338
328
if self._bench_history is not None:
339
329
benchmark_time = self._extractBenchmarkTime(test)
340
330
if benchmark_time is not None:
375
358
self.skip_count += 1
376
359
self.report_skip(test, reason)
378
def _addNotApplicable(self, test, skip_excinfo):
379
if isinstance(skip_excinfo[1], TestNotApplicable):
380
self.not_applicable_count += 1
381
self.report_not_applicable(test, skip_excinfo)
384
except KeyboardInterrupt:
387
self.addError(test, test.exc_info())
389
# seems best to treat this as success from point-of-view of unittest
390
# -- it actually does nothing so it barely matters :)
391
unittest.TestResult.addSuccess(self, test)
392
test._log_contents = ''
361
def addNotApplicable(self, test, reason):
362
self.not_applicable_count += 1
363
self.report_not_applicable(test, reason)
394
365
def printErrorList(self, flavour, errors):
395
366
for test, err in errors:
1147
1119
:raises AssertionError: If the expected and actual stat values differ
1148
1120
other than by atime.
1150
self.assertEqual(expected.st_size, actual.st_size)
1151
self.assertEqual(expected.st_mtime, actual.st_mtime)
1152
self.assertEqual(expected.st_ctime, actual.st_ctime)
1153
self.assertEqual(expected.st_dev, actual.st_dev)
1154
self.assertEqual(expected.st_ino, actual.st_ino)
1155
self.assertEqual(expected.st_mode, actual.st_mode)
1122
self.assertEqual(expected.st_size, actual.st_size,
1123
'st_size did not match')
1124
self.assertEqual(expected.st_mtime, actual.st_mtime,
1125
'st_mtime did not match')
1126
self.assertEqual(expected.st_ctime, actual.st_ctime,
1127
'st_ctime did not match')
1128
if sys.platform != 'win32':
1129
# On Win32 both 'dev' and 'ino' cannot be trusted. In python2.4 it
1130
# is 'dev' that varies, in python 2.5 (6?) it is st_ino that is
1131
# odd. Regardless we shouldn't actually try to assert anything
1132
# about their values
1133
self.assertEqual(expected.st_dev, actual.st_dev,
1134
'st_dev did not match')
1135
self.assertEqual(expected.st_ino, actual.st_ino,
1136
'st_ino did not match')
1137
self.assertEqual(expected.st_mode, actual.st_mode,
1138
'st_mode did not match')
1157
1140
def assertLength(self, length, obj_with_len):
1158
1141
"""Assert that obj_with_len is of length length."""
1599
1583
def _do_skip(self, result, reason):
1600
1584
addSkip = getattr(result, 'addSkip', None)
1601
1585
if not callable(addSkip):
1602
result.addError(self, sys.exc_info())
1586
result.addSuccess(result)
1604
1588
addSkip(self, reason)
1590
def _do_known_failure(self, result):
1591
err = sys.exc_info()
1592
addExpectedFailure = getattr(result, 'addExpectedFailure', None)
1593
if addExpectedFailure is not None:
1594
addExpectedFailure(self, err)
1596
result.addSuccess(self)
1598
def _do_not_applicable(self, result, e):
1600
reason = 'No reason given'
1603
addNotApplicable = getattr(result, 'addNotApplicable', None)
1604
if addNotApplicable is not None:
1605
result.addNotApplicable(self, reason)
1607
self._do_skip(result, reason)
1609
def _do_unsupported_or_skip(self, result, reason):
1610
addNotSupported = getattr(result, 'addNotSupported', None)
1611
if addNotSupported is not None:
1612
result.addNotSupported(self, reason)
1614
self._do_skip(result, reason)
1606
1616
def run(self, result=None):
1607
1617
if result is None: result = self.defaultTestResult()
1618
result.startTest(self)
1623
result.stopTest(self)
1625
def _run(self, result):
1608
1626
for feature in getattr(self, '_test_needs_features', []):
1609
1627
if not feature.available():
1610
result.startTest(self)
1611
if getattr(result, 'addNotSupported', None):
1612
result.addNotSupported(self, feature)
1614
result.addSuccess(self)
1615
result.stopTest(self)
1628
return self._do_unsupported_or_skip(result, feature)
1630
absent_attr = object()
1632
method_name = getattr(self, '_testMethodName', absent_attr)
1633
if method_name is absent_attr:
1635
method_name = getattr(self, '_TestCase__testMethodName')
1636
testMethod = getattr(self, method_name)
1619
result.startTest(self)
1620
absent_attr = object()
1622
method_name = getattr(self, '_testMethodName', absent_attr)
1623
if method_name is absent_attr:
1625
method_name = getattr(self, '_TestCase__testMethodName')
1626
testMethod = getattr(self, method_name)
1630
if not self._bzr_test_setUp_run:
1632
"test setUp did not invoke "
1633
"bzrlib.tests.TestCase's setUp")
1634
except KeyboardInterrupt:
1637
except TestSkipped, e:
1638
self._do_skip(result, e.args[0])
1642
result.addError(self, sys.exc_info())
1640
if not self._bzr_test_setUp_run:
1642
"test setUp did not invoke "
1643
"bzrlib.tests.TestCase's setUp")
1644
except KeyboardInterrupt:
1647
except KnownFailure:
1648
self._do_known_failure(result)
1651
except TestNotApplicable, e:
1652
self._do_not_applicable(result, e)
1655
except TestSkipped, e:
1656
self._do_skip(result, e.args[0])
1659
except UnavailableFeature, e:
1660
self._do_unsupported_or_skip(result, e.args[0])
1664
result.addError(self, sys.exc_info())
1672
except KnownFailure:
1673
self._do_known_failure(result)
1674
except self.failureException:
1675
result.addFailure(self, sys.exc_info())
1676
except TestNotApplicable, e:
1677
self._do_not_applicable(result, e)
1678
except TestSkipped, e:
1680
reason = "No reason given."
1683
self._do_skip(result, reason)
1684
except UnavailableFeature, e:
1685
self._do_unsupported_or_skip(result, e.args[0])
1686
except KeyboardInterrupt:
1690
result.addError(self, sys.exc_info())
1694
if not self._bzr_test_tearDown_run:
1696
"test tearDown did not invoke "
1697
"bzrlib.tests.TestCase's tearDown")
1698
except KeyboardInterrupt:
1702
result.addError(self, sys.exc_info())
1650
except self.failureException:
1651
result.addFailure(self, sys.exc_info())
1652
except TestSkipped, e:
1654
reason = "No reason given."
1657
self._do_skip(result, reason)
1658
except KeyboardInterrupt:
1662
result.addError(self, sys.exc_info())
1666
if not self._bzr_test_tearDown_run:
1668
"test tearDown did not invoke "
1669
"bzrlib.tests.TestCase's tearDown")
1670
except KeyboardInterrupt:
1674
result.addError(self, sys.exc_info())
1677
if ok: result.addSuccess(self)
1679
result.stopTest(self)
1705
if ok: result.addSuccess(self)
1681
except TestNotApplicable:
1682
# Not moved from the result [yet].
1685
1707
except KeyboardInterrupt:
1686
1708
self._runCleanups()