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