486
486
def report_known_failure(self, test, err):
487
ui.ui_factory.note('XFAIL: %s\n%s\n' % (
488
self._test_description(test), err[1]))
490
489
def report_skip(self, test, reason):
595
594
# to encode using ascii.
596
595
new_encoding = osutils.get_terminal_encoding()
597
596
codec = codecs.lookup(new_encoding)
598
stream = osutils.StreamWriter(codec, stream)
597
stream = osutils.UnicodeOrBytesToBytesWriter(codec, stream)
599
598
stream.encoding = new_encoding
600
599
self.stream = unittest._WritelnDecorator(stream)
601
600
self.descriptions = descriptions
672
671
traceback._some_str = _clever_some_str
676
class KnownFailure(AssertionError):
677
"""Indicates that a test failed in a precisely expected manner.
679
Such failures dont block the whole test suite from passing because they are
680
indicators of partially completed code or of future work. We have an
681
explicit error for them so that we can ensure that they are always visible:
682
KnownFailures are always shown in the output of bzr selftest.
675
KnownFailure = testtools.testcase._ExpectedFailure
686
678
class UnavailableFeature(Exception):
798
790
(UnavailableFeature, self._do_unsupported_or_skip))
799
791
self.exception_handlers.insert(0,
800
792
(TestNotApplicable, self._do_not_applicable))
801
self.exception_handlers.insert(0,
802
(KnownFailure, self._do_known_failure))
805
795
super(TestCase, self).setUp()
1293
1283
m += ": " + msg
1296
def expectFailure(self, reason, assertion, *args, **kwargs):
1297
"""Invoke a test, expecting it to fail for the given reason.
1299
This is for assertions that ought to succeed, but currently fail.
1300
(The failure is *expected* but not *wanted*.) Please be very precise
1301
about the failure you're expecting. If a new bug is introduced,
1302
AssertionError should be raised, not KnownFailure.
1304
Frequently, expectFailure should be followed by an opposite assertion.
1307
Intended to be used with a callable that raises AssertionError as the
1308
'assertion' parameter. args and kwargs are passed to the 'assertion'.
1310
Raises KnownFailure if the test fails. Raises AssertionError if the
1315
self.expectFailure('Math is broken', self.assertNotEqual, 54,
1317
self.assertEqual(42, dynamic_val)
1319
This means that a dynamic_val of 54 will cause the test to raise
1320
a KnownFailure. Once math is fixed and the expectFailure is removed,
1321
only a dynamic_val of 42 will allow the test to pass. Anything other
1322
than 54 or 42 will cause an AssertionError.
1325
assertion(*args, **kwargs)
1326
except AssertionError:
1327
raise KnownFailure(reason)
1329
self.fail('Unexpected success. Should have failed: %s' % reason)
1331
1286
def assertFileEqual(self, content, path):
1332
1287
"""Fail if path does not contain 'content'."""
1333
1288
self.failUnlessExists(path)
1645
1600
def _get_log(self, keep_log_file=False):
1646
"""Get the log from bzrlib.trace calls from this test.
1601
"""Internal helper to get the log from bzrlib.trace for this test.
1603
Please use self.getDetails, or self.get_log to access this in test case
1648
1606
:param keep_log_file: When True, if the log is still a file on disk
1649
1607
leave it as a file on disk. When False, if the log is still a file
1693
1651
return "No log file content and no log file name."
1654
"""Get a unicode string containing the log from bzrlib.trace.
1656
Undecodable characters are replaced.
1658
return u"".join(self.getDetails()['log'].iter_text())
1695
1660
def requireFeature(self, feature):
1696
1661
"""This test requires a specific feature is available.