707
707
class TestTestResult(TestCase):
709
def test_elapsed_time_with_benchmarking(self):
709
def check_timing(self, test_case, expected_re):
710
710
result = bzrlib.tests.TextTestResult(self._log_file,
714
result._recordTestStartTime()
716
result.extractBenchmarkTime(self)
717
timed_string = result._testTimeString()
718
# without explicit benchmarking, we should get a simple time.
719
self.assertContainsRe(timed_string, "^ +[0-9]+ms$")
714
test_case.run(result)
715
timed_string = result._testTimeString(test_case)
716
self.assertContainsRe(timed_string, expected_re)
718
def test_test_reporting(self):
719
class ShortDelayTestCase(TestCase):
720
def test_short_delay(self):
722
def test_short_benchmark(self):
723
self.time(time.sleep, 0.003)
724
self.check_timing(ShortDelayTestCase('test_short_delay'),
720
726
# if a benchmark time is given, we want a x of y style result.
721
self.time(time.sleep, 0.001)
722
result.extractBenchmarkTime(self)
723
timed_string = result._testTimeString()
724
self.assertContainsRe(
725
timed_string, "^ +[0-9]+ms/ +[0-9]+ms$")
726
# extracting the time from a non-bzrlib testcase sets to None
727
result._recordTestStartTime()
728
result.extractBenchmarkTime(
729
unittest.FunctionTestCase(self.test_elapsed_time_with_benchmarking))
730
timed_string = result._testTimeString()
731
self.assertContainsRe(timed_string, "^ +[0-9]+ms$")
732
# cheat. Yes, wash thy mouth out with soap.
733
self._benchtime = None
727
self.check_timing(ShortDelayTestCase('test_short_benchmark'),
728
r"^ +[0-9]+ms/ +[0-9]+ms$")
730
def test_unittest_reporting_unittest_class(self):
731
# getting the time from a non-bzrlib test works ok
732
class ShortDelayTestCase(unittest.TestCase):
733
def test_short_delay(self):
735
self.check_timing(ShortDelayTestCase('test_short_delay'),
735
738
def test_assigned_benchmark_file_stores_date(self):
736
739
output = StringIO()
737
740
result = bzrlib.tests.TextTestResult(self._log_file,
846
848
test = self.get_passing_test()
847
849
result.startTest(test)
848
result.extractBenchmarkTime(test)
849
850
prefix = len(result_stream.getvalue())
850
851
# the err parameter has the shape:
851
852
# (class, exception object, traceback)
871
872
test = self.get_passing_test()
872
873
# this seeds the state to handle reporting the test.
873
874
result.startTest(test)
874
result.extractBenchmarkTime(test)
875
875
# the err parameter has the shape:
876
876
# (class, exception object, traceback)
877
877
# KnownFailures dont get their tracebacks shown though, so we
996
994
def test_strict_with_unsupported_feature(self):
997
995
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
999
997
test = self.get_passing_test()
1000
998
feature = "Unsupported Feature"
1001
999
result.addNotSupported(test, feature)
1002
1000
self.assertFalse(result.wasStrictlySuccessful())
1001
self.assertEqual(None, result._extractBenchmarkTime(test))
1004
1003
def test_strict_with_known_failure(self):
1005
1004
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1007
1006
test = self.get_passing_test()
1008
1007
err = (KnownFailure, KnownFailure('foo'), None)
1009
result.addKnownFailure(test, err)
1008
result._addKnownFailure(test, err)
1010
1009
self.assertFalse(result.wasStrictlySuccessful())
1010
self.assertEqual(None, result._extractBenchmarkTime(test))
1012
1012
def test_strict_with_success(self):
1013
1013
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1015
1015
test = self.get_passing_test()
1016
1016
result.addSuccess(test)
1017
1017
self.assertTrue(result.wasStrictlySuccessful())
1018
self.assertEqual(None, result._extractBenchmarkTime(test))
1020
1021
class TestRunner(TestCase):