93
94
DocTestMatches(u"...a test message\n", doctest.ELLIPSIS))
96
class TestUnicodeFilename(tests.TestCase):
98
def test_probe_passes(self):
99
"""UnicodeFilename._probe passes."""
100
# We can't test much more than that because the behaviour depends
102
tests.UnicodeFilename._probe()
105
97
class TestTreeShape(tests.TestCaseInTempDir):
107
99
def test_unicode_paths(self):
108
self.requireFeature(tests.UnicodeFilename)
100
self.requireFeature(features.UnicodeFilenameFeature)
110
102
filename = u'hell\u00d8'
111
103
self.build_tree_contents([(filename, 'contents of hello')])
867
test = self.get_passing_test()
868
result.startTest(test)
869
prefix = len(result_stream.getvalue())
870
# the err parameter has the shape:
871
# (class, exception object, traceback)
872
# KnownFailures dont get their tracebacks shown though, so we
874
err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
875
result.report_known_failure(test, err)
876
output = result_stream.getvalue()[prefix:]
877
lines = output.splitlines()
878
self.assertContainsRe(lines[0], r'XFAIL *\d+ms$')
879
if sys.version_info > (2, 7):
880
self.expectFailure("_ExpectedFailure on 2.7 loses the message",
881
self.assertNotEqual, lines[1], ' ')
882
self.assertEqual(lines[1], ' foo')
883
self.assertEqual(2, len(lines))
859
_get_test("test_xfail").run(result)
860
self.assertContainsRe(result_stream.getvalue(),
861
"\n\\S+\\.test_xfail\\s+XFAIL\\s+\\d+ms\n"
862
"\\s*(?:Text attachment: )?reason"
885
867
def get_passing_test(self):
886
868
"""Return a test object that can't be run usefully."""
897
879
self._call = test, feature
898
880
result = InstrumentedTestResult(None, None, None, None)
899
881
test = SampleTestCase('_test_pass')
900
feature = tests.Feature()
882
feature = features.Feature()
901
883
result.startTest(test)
902
884
result.addNotSupported(test, feature)
903
885
# it should invoke 'report_unsupported'.
941
923
def addNotSupported(self, test, feature):
942
924
self._call = test, feature
943
925
result = InstrumentedTestResult(None, None, None, None)
944
feature = tests.Feature()
926
feature = features.Feature()
945
927
class Test(tests.TestCase):
946
928
def test_function(self):
947
929
raise tests.UnavailableFeature(feature)
966
948
def test_strict_with_known_failure(self):
967
949
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
969
test = self.get_passing_test()
970
err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
971
result.addExpectedFailure(test, err)
951
test = _get_test("test_xfail")
972
953
self.assertFalse(result.wasStrictlySuccessful())
973
954
self.assertEqual(None, result._extractBenchmarkTime(test))
1090
1062
self.expectFailure("No absolute truth", self.assertTrue, True)
1091
1063
runner = tests.TextTestRunner(stream=StringIO())
1092
1064
result = self.run_test_runner(runner, Test("test_truth"))
1093
self.assertContainsRe(runner.stream.getvalue(),
1095
"FAIL: \\S+\.test_truth\n"
1098
"No absolute truth\n"
1101
"Ran 1 test in .*\n"
1103
"FAILED \\(failures=1\\)\n\\Z")
1065
if testtools_version <= (0, 9, 11):
1066
self.assertContainsRe(runner.stream.getvalue(),
1068
"FAIL: \\S+\.test_truth\n"
1071
"No absolute truth\n"
1074
"Ran 1 test in .*\n"
1076
"FAILED \\(failures=1\\)\n\\Z")
1078
self.assertContainsRe(runner.stream.getvalue(),
1080
"FAIL: \\S+\.test_truth\n"
1082
"Empty attachments:\n"
1085
"reason: {{{No absolute truth}}}\n"
1087
"Ran 1 test in .*\n"
1089
"FAILED \\(failures=1\\)\n\\Z")
1105
1091
def test_result_decorator(self):
1106
1092
# decorate results
1192
1178
def test_unsupported_features_listed(self):
1193
1179
"""When unsupported features are encountered they are detailed."""
1194
class Feature1(tests.Feature):
1180
class Feature1(features.Feature):
1195
1181
def _probe(self): return False
1196
class Feature2(tests.Feature):
1182
class Feature2(features.Feature):
1197
1183
def _probe(self): return False
1198
1184
# create sample tests
1199
1185
test1 = SampleTestCase('_test_pass')
1265
1251
lambda trace=False: "ascii")
1266
1252
result = self.run_test_runner(tests.TextTestRunner(stream=out),
1267
1253
FailureWithUnicode("test_log_unicode"))
1268
self.assertContainsRe(out.getvalue(),
1269
"Text attachment: log\n"
1271
"\d+\.\d+ \\\\u2606\n"
1254
if testtools_version > (0, 9, 11):
1255
self.assertContainsRe(out.getvalue(), "log: {{{\d+\.\d+ \\\\u2606}}}")
1257
self.assertContainsRe(out.getvalue(),
1258
"Text attachment: log\n"
1260
"\d+\.\d+ \\\\u2606\n"
1275
1264
class SampleTestCase(tests.TestCase):
1513
1502
def test_requireFeature_available(self):
1514
1503
"""self.requireFeature(available) is a no-op."""
1515
class Available(tests.Feature):
1504
class Available(features.Feature):
1516
1505
def _probe(self):return True
1517
1506
feature = Available()
1518
1507
self.requireFeature(feature)
1520
1509
def test_requireFeature_unavailable(self):
1521
1510
"""self.requireFeature(unavailable) raises UnavailableFeature."""
1522
class Unavailable(tests.Feature):
1511
class Unavailable(features.Feature):
1523
1512
def _probe(self):return False
1524
1513
feature = Unavailable()
1525
1514
self.assertRaises(tests.UnavailableFeature,
1754
1743
result = self._run_test('test_fail')
1755
1744
self.assertEqual(1, len(result.failures))
1756
1745
result_content = result.failures[0][1]
1757
self.assertContainsRe(result_content, 'Text attachment: log')
1746
if testtools_version < (0, 9, 12):
1747
self.assertContainsRe(result_content, 'Text attachment: log')
1758
1748
self.assertContainsRe(result_content, 'this was a failing test')
1760
1750
def test_error_has_log(self):
1761
1751
result = self._run_test('test_error')
1762
1752
self.assertEqual(1, len(result.errors))
1763
1753
result_content = result.errors[0][1]
1764
self.assertContainsRe(result_content, 'Text attachment: log')
1754
if testtools_version < (0, 9, 12):
1755
self.assertContainsRe(result_content, 'Text attachment: log')
1765
1756
self.assertContainsRe(result_content, 'this test errored')
1767
1758
def test_skip_has_no_log(self):
2619
2610
self.assertEqual('bzr: interrupted\n', result[1])
2622
class TestFeature(tests.TestCase):
2624
def test_caching(self):
2625
"""Feature._probe is called by the feature at most once."""
2626
class InstrumentedFeature(tests.Feature):
2628
super(InstrumentedFeature, self).__init__()
2631
self.calls.append('_probe')
2633
feature = InstrumentedFeature()
2635
self.assertEqual(['_probe'], feature.calls)
2637
self.assertEqual(['_probe'], feature.calls)
2639
def test_named_str(self):
2640
"""Feature.__str__ should thunk to feature_name()."""
2641
class NamedFeature(tests.Feature):
2642
def feature_name(self):
2644
feature = NamedFeature()
2645
self.assertEqual('symlinks', str(feature))
2647
def test_default_str(self):
2648
"""Feature.__str__ should default to __class__.__name__."""
2649
class NamedFeature(tests.Feature):
2651
feature = NamedFeature()
2652
self.assertEqual('NamedFeature', str(feature))
2655
class TestUnavailableFeature(tests.TestCase):
2657
def test_access_feature(self):
2658
feature = tests.Feature()
2659
exception = tests.UnavailableFeature(feature)
2660
self.assertIs(feature, exception.args[0])
2663
simple_thunk_feature = tests._CompatabilityThunkFeature(
2664
deprecated_in((2, 1, 0)),
2665
'bzrlib.tests.test_selftest',
2666
'simple_thunk_feature','UnicodeFilename',
2667
replacement_module='bzrlib.tests'
2670
class Test_CompatibilityFeature(tests.TestCase):
2672
def test_does_thunk(self):
2673
res = self.callDeprecated(
2674
['bzrlib.tests.test_selftest.simple_thunk_feature was deprecated'
2675
' in version 2.1.0. Use bzrlib.tests.UnicodeFilename instead.'],
2676
simple_thunk_feature.available)
2677
self.assertEqual(tests.UnicodeFilename.available(), res)
2680
class TestModuleAvailableFeature(tests.TestCase):
2682
def test_available_module(self):
2683
feature = tests.ModuleAvailableFeature('bzrlib.tests')
2684
self.assertEqual('bzrlib.tests', feature.module_name)
2685
self.assertEqual('bzrlib.tests', str(feature))
2686
self.assertTrue(feature.available())
2687
self.assertIs(tests, feature.module)
2689
def test_unavailable_module(self):
2690
feature = tests.ModuleAvailableFeature('bzrlib.no_such_module_exists')
2691
self.assertEqual('bzrlib.no_such_module_exists', str(feature))
2692
self.assertFalse(feature.available())
2693
self.assertIs(None, feature.module)
2696
2613
class TestSelftestFiltering(tests.TestCase):
2698
2615
def setUp(self):