577
576
class TestTestResult(TestCase):
579
def test_progress_bar_style_quiet(self):
580
# test using a progress bar.
581
dummy_test = TestTestResult('test_progress_bar_style_quiet')
582
dummy_error = (Exception, None, [])
583
mypb = MockProgress()
584
mypb.update('Running tests', 0, 4)
585
last_calls = mypb.calls[:]
587
result = bzrlib.tests._MyResult(self._log_file,
591
self.assertEqual(last_calls, mypb.calls)
594
"""Shorten a string based on the terminal width"""
595
return result._ellipsise_unimportant_words(s,
596
osutils.terminal_width())
599
result.startTest(dummy_test)
600
# starting a test prints the test name
601
last_calls += [('update', '...tyle_quiet', 0, None)]
602
self.assertEqual(last_calls, mypb.calls)
603
result.addError(dummy_test, dummy_error)
604
last_calls += [('update', 'ERROR ', 1, None),
605
('note', shorten(dummy_test.id() + ': ERROR'), ())
607
self.assertEqual(last_calls, mypb.calls)
610
result.startTest(dummy_test)
611
last_calls += [('update', '...tyle_quiet', 1, None)]
612
self.assertEqual(last_calls, mypb.calls)
613
last_calls += [('update', 'FAIL ', 2, None),
614
('note', shorten(dummy_test.id() + ': FAIL'), ())
616
result.addFailure(dummy_test, dummy_error)
617
self.assertEqual(last_calls, mypb.calls)
620
result.startTest(dummy_test)
621
last_calls += [('update', '...tyle_quiet', 2, None)]
622
self.assertEqual(last_calls, mypb.calls)
623
result.addSuccess(dummy_test)
624
last_calls += [('update', 'OK ', 3, None)]
625
self.assertEqual(last_calls, mypb.calls)
628
result.startTest(dummy_test)
629
last_calls += [('update', '...tyle_quiet', 3, None)]
630
self.assertEqual(last_calls, mypb.calls)
631
result.addSkipped(dummy_test, dummy_error)
632
last_calls += [('update', 'SKIP ', 4, None)]
633
self.assertEqual(last_calls, mypb.calls)
635
578
def test_elapsed_time_with_benchmarking(self):
636
result = bzrlib.tests._MyResult(self._log_file,
579
result = bzrlib.tests.TextTestResult(self._log_file,
761
705
TestCaseInTempDir.TEST_ROOT = old_root
763
def test_accepts_and_uses_pb_parameter(self):
764
test = TestRunner('dummy_test')
765
mypb = MockProgress()
766
self.assertEqual([], mypb.calls)
767
runner = TextTestRunner(stream=self._log_file, pb=mypb)
768
result = self.run_test_runner(runner, test)
769
self.assertEqual(1, result.testsRun)
770
self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
771
self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
772
self.assertEqual(('update', 'OK ', 1, None), mypb.calls[2])
773
self.assertEqual(('update', 'Cleaning up', 0, 1), mypb.calls[3])
774
self.assertEqual(('clear',), mypb.calls[4])
775
self.assertEqual(5, len(mypb.calls))
777
707
def test_skipped_test(self):
778
708
# run a test that is skipped, and check the suite as a whole still
909
839
"""Test that the TestCase.time() method accumulates a benchmark time."""
910
840
sample_test = TestTestCase("method_that_times_a_bit_twice")
911
841
output_stream = StringIO()
912
result = bzrlib.tests._MyResult(
842
result = bzrlib.tests.VerboseTestResult(
913
843
unittest._WritelnDecorator(output_stream),
846
num_tests=sample_test.countTestCases())
916
847
sample_test.run(result)
917
848
self.assertContainsRe(
918
849
output_stream.getvalue(),
919
"[1-9][0-9]ms/ [1-9][0-9]ms\n$")
921
852
def test__gather_lsprof_in_benchmarks(self):
922
853
"""When _gather_lsprof_in_benchmarks is on, accumulate profile data.