681
681
self.assertEqual(url, t.clone('..').base)
684
class MockProgress(progress._BaseProgressBar):
685
"""Progress-bar standin that records calls.
687
Useful for testing pb using code.
691
progress._BaseProgressBar.__init__(self)
695
self.calls.append(('tick',))
697
def update(self, msg=None, current=None, total=None):
698
self.calls.append(('update', msg, current, total))
701
self.calls.append(('clear',))
703
def note(self, msg, *args):
704
self.calls.append(('note', msg, args))
707
684
class TestTestResult(tests.TestCase):
709
686
def check_timing(self, test_case, expected_re):
723
700
self.time(time.sleep, 0.003)
724
701
self.check_timing(ShortDelayTestCase('test_short_delay'),
726
# if a benchmark time is given, we want a x of y style result.
703
# if a benchmark time is given, we now show just that time followed by
727
705
self.check_timing(ShortDelayTestCase('test_short_benchmark'),
728
r"^ +[0-9]+ms/ +[0-9]+ms$")
730
708
def test_unittest_reporting_unittest_class(self):
731
709
# getting the time from a non-bzrlib test works ok
861
839
self.assertEqual(lines[1], ' foo')
862
840
self.assertEqual(2, len(lines))
864
def test_text_report_known_failure(self):
865
# text test output formatting
867
result = bzrlib.tests.TextTestResult(
873
test = self.get_passing_test()
874
# this seeds the state to handle reporting the test.
875
result.startTest(test)
876
# the err parameter has the shape:
877
# (class, exception object, traceback)
878
# KnownFailures dont get their tracebacks shown though, so we
880
err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
881
result.report_known_failure(test, err)
884
('update', '[1 in 0s] passing_test', None, None),
885
('note', 'XFAIL: %s\n%s\n', ('passing_test', err[1]))
888
# known_failures should be printed in the summary, so if we run a test
889
# after there are some known failures, the update prefix should match
891
result.known_failure_count = 3
895
('update', '[2 in 0s] passing_test', None, None),
899
842
def get_passing_test(self):
900
843
"""Return a test object that can't be run usefully."""
901
844
def passing_test():
943
886
result.report_unsupported(test, feature)
944
887
output = result_stream.getvalue()[prefix:]
945
888
lines = output.splitlines()
946
self.assertEqual(lines, ['NODEP 0ms',
889
self.assertEqual(lines, ['NODEP 0ms',
947
890
" The feature 'Feature' is not available."])
949
def test_text_report_unsupported(self):
950
# text test output formatting
952
result = bzrlib.tests.TextTestResult(
958
test = self.get_passing_test()
959
feature = tests.Feature()
960
# this seeds the state to handle reporting the test.
961
result.startTest(test)
962
result.report_unsupported(test, feature)
963
# no output on unsupported features
965
[('update', '[1 in 0s] passing_test', None, None)
968
# the number of missing features should be printed in the progress
969
# summary, so check for that.
970
result.unsupported = {'foo':0, 'bar':0}
974
('update', '[2 in 0s, 2 missing] passing_test', None, None),
978
892
def test_unavailable_exception(self):
979
893
"""An UnavailableFeature being raised should invoke addNotSupported."""
980
894
class InstrumentedTestResult(tests.ExtendedTestResult):
1485
1399
result = bzrlib.tests.VerboseTestResult(
1486
1400
unittest._WritelnDecorator(output_stream),
1487
1401
descriptions=0,
1489
num_tests=sample_test.countTestCases())
1490
1403
sample_test.run(result)
1491
1404
self.assertContainsRe(
1492
1405
output_stream.getvalue(),
1493
r"\d+ms/ +\d+ms\n$")
1495
1408
def test_hooks_sanitised(self):
1496
1409
"""The bzrlib hooks should be sanitised by setUp."""
1686
1599
def test_assert_isinstance(self):
1687
1600
self.assertIsInstance(2, int)
1688
1601
self.assertIsInstance(u'', basestring)
1689
self.assertRaises(AssertionError, self.assertIsInstance, None, int)
1602
e = self.assertRaises(AssertionError, self.assertIsInstance, None, int)
1603
self.assertEquals(str(e),
1604
"None is an instance of <type 'NoneType'> rather than <type 'int'>")
1690
1605
self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int)
1606
e = self.assertRaises(AssertionError,
1607
self.assertIsInstance, None, int, "it's just not")
1608
self.assertEquals(str(e),
1609
"None is an instance of <type 'NoneType'> rather than <type 'int'>"
1692
1612
def test_assertEndsWith(self):
1693
1613
self.assertEndsWith('foo', 'oo')
2360
2280
return tests.ExtendedTestResult(self.stream, self.descriptions,
2361
2281
self.verbosity)
2362
2282
tests.run_suite(suite, runner_class=MyRunner, stream=StringIO())
2363
self.assertEqual(calls, [suite])
2283
self.assertLength(1, calls)
2365
2285
def test_done(self):
2366
2286
"""run_suite should call result.done()"""