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:
562
533
def report_test_start(self, test):
564
535
name = self._shortened_test_description(test)
565
# width needs space for 6 char status, plus 1 for slash, plus an
566
# 11-char time string, plus a trailing blank
567
# when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on space
568
self.stream.write(self._ellipsize_to_right(name,
569
osutils.terminal_width()-18))
536
width = osutils.terminal_width()
537
if width is not None:
538
# width needs space for 6 char status, plus 1 for slash, plus an
539
# 11-char time string, plus a trailing blank
540
# when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on
542
self.stream.write(self._ellipsize_to_right(name, width-18))
544
self.stream.write(name)
570
545
self.stream.flush()
572
547
def _error_summary(self, err):
1143
1119
:raises AssertionError: If the expected and actual stat values differ
1144
1120
other than by atime.
1146
self.assertEqual(expected.st_size, actual.st_size)
1147
self.assertEqual(expected.st_mtime, actual.st_mtime)
1148
self.assertEqual(expected.st_ctime, actual.st_ctime)
1149
self.assertEqual(expected.st_dev, actual.st_dev)
1150
self.assertEqual(expected.st_ino, actual.st_ino)
1151
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')
1153
1140
def assertLength(self, length, obj_with_len):
1154
1141
"""Assert that obj_with_len is of length length."""
1594
1583
def _do_skip(self, result, reason):
1595
1584
addSkip = getattr(result, 'addSkip', None)
1596
1585
if not callable(addSkip):
1597
result.addError(self, sys.exc_info())
1586
result.addSuccess(result)
1599
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)
1601
1616
def run(self, result=None):
1602
1617
if result is None: result = self.defaultTestResult()
1618
result.startTest(self)
1623
result.stopTest(self)
1625
def _run(self, result):
1603
1626
for feature in getattr(self, '_test_needs_features', []):
1604
1627
if not feature.available():
1605
result.startTest(self)
1606
if getattr(result, 'addNotSupported', None):
1607
result.addNotSupported(self, feature)
1609
result.addSuccess(self)
1610
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)
1614
result.startTest(self)
1615
absent_attr = object()
1617
method_name = getattr(self, '_testMethodName', absent_attr)
1618
if method_name is absent_attr:
1620
method_name = getattr(self, '_TestCase__testMethodName')
1621
testMethod = getattr(self, method_name)
1625
if not self._bzr_test_setUp_run:
1627
"test setUp did not invoke "
1628
"bzrlib.tests.TestCase's setUp")
1629
except KeyboardInterrupt:
1632
except TestSkipped, e:
1633
self._do_skip(result, e.args[0])
1637
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())
1645
except self.failureException:
1646
result.addFailure(self, sys.exc_info())
1647
except TestSkipped, e:
1649
reason = "No reason given."
1652
self._do_skip(result, reason)
1653
except KeyboardInterrupt:
1657
result.addError(self, sys.exc_info())
1661
if not self._bzr_test_tearDown_run:
1663
"test tearDown did not invoke "
1664
"bzrlib.tests.TestCase's tearDown")
1665
except KeyboardInterrupt:
1669
result.addError(self, sys.exc_info())
1672
if ok: result.addSuccess(self)
1674
result.stopTest(self)
1705
if ok: result.addSuccess(self)
1676
except TestNotApplicable:
1677
# Not moved from the result [yet].
1680
1707
except KeyboardInterrupt:
1681
1708
self._runCleanups()
4182
4247
UnicodeFilenameFeature = _UnicodeFilenameFeature()
4250
class ModuleAvailableFeature(Feature):
4251
"""This is a feature than describes a module we want to be available.
4253
Declare the name of the module in __init__(), and then after probing, the
4254
module will be available as 'self.module'.
4256
:ivar module: The module if it is available, else None.
4259
def __init__(self, module_name):
4260
super(ModuleAvailableFeature, self).__init__()
4261
self.module_name = module_name
4265
self._module = __import__(self.module_name, {}, {}, [''])
4272
if self.available(): # Make sure the probe has been done
4276
def feature_name(self):
4277
return self.module_name
4185
4281
def probe_unicode_in_user_encoding():
4186
4282
"""Try to encode several unicode strings to use in unicode-aware tests.
4187
4283
Return first successfull match.