704
708
class TestTestResult(TestCase):
706
def test_elapsed_time_with_benchmarking(self):
710
def check_timing(self, test_case, expected_re):
707
711
result = bzrlib.tests.TextTestResult(self._log_file,
711
result._recordTestStartTime()
713
result.extractBenchmarkTime(self)
714
timed_string = result._testTimeString()
715
# without explicit benchmarking, we should get a simple time.
716
self.assertContainsRe(timed_string, "^ +[0-9]+ms$")
715
test_case.run(result)
716
timed_string = result._testTimeString(test_case)
717
self.assertContainsRe(timed_string, expected_re)
719
def test_test_reporting(self):
720
class ShortDelayTestCase(TestCase):
721
def test_short_delay(self):
723
def test_short_benchmark(self):
724
self.time(time.sleep, 0.003)
725
self.check_timing(ShortDelayTestCase('test_short_delay'),
717
727
# if a benchmark time is given, we want a x of y style result.
718
self.time(time.sleep, 0.001)
719
result.extractBenchmarkTime(self)
720
timed_string = result._testTimeString()
721
self.assertContainsRe(
722
timed_string, "^ +[0-9]+ms/ +[0-9]+ms$")
723
# extracting the time from a non-bzrlib testcase sets to None
724
result._recordTestStartTime()
725
result.extractBenchmarkTime(
726
unittest.FunctionTestCase(self.test_elapsed_time_with_benchmarking))
727
timed_string = result._testTimeString()
728
self.assertContainsRe(timed_string, "^ +[0-9]+ms$")
729
# cheat. Yes, wash thy mouth out with soap.
730
self._benchtime = None
728
self.check_timing(ShortDelayTestCase('test_short_benchmark'),
729
r"^ +[0-9]+ms/ +[0-9]+ms$")
731
def test_unittest_reporting_unittest_class(self):
732
# getting the time from a non-bzrlib test works ok
733
class ShortDelayTestCase(unittest.TestCase):
734
def test_short_delay(self):
736
self.check_timing(ShortDelayTestCase('test_short_delay'),
732
739
def test_assigned_benchmark_file_stores_date(self):
733
740
output = StringIO()
734
741
result = bzrlib.tests.TextTestResult(self._log_file,
843
849
test = self.get_passing_test()
844
850
result.startTest(test)
845
result.extractBenchmarkTime(test)
846
851
prefix = len(result_stream.getvalue())
847
852
# the err parameter has the shape:
848
853
# (class, exception object, traceback)
868
873
test = self.get_passing_test()
869
874
# this seeds the state to handle reporting the test.
870
875
result.startTest(test)
871
result.extractBenchmarkTime(test)
872
876
# the err parameter has the shape:
873
877
# (class, exception object, traceback)
874
878
# KnownFailures dont get their tracebacks shown though, so we
990
992
# and not count as an error
991
993
self.assertEqual(0, result.error_count)
995
def test_strict_with_unsupported_feature(self):
996
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
998
test = self.get_passing_test()
999
feature = "Unsupported Feature"
1000
result.addNotSupported(test, feature)
1001
self.assertFalse(result.wasStrictlySuccessful())
1002
self.assertEqual(None, result._extractBenchmarkTime(test))
1004
def test_strict_with_known_failure(self):
1005
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1007
test = self.get_passing_test()
1008
err = (KnownFailure, KnownFailure('foo'), None)
1009
result._addKnownFailure(test, err)
1010
self.assertFalse(result.wasStrictlySuccessful())
1011
self.assertEqual(None, result._extractBenchmarkTime(test))
1013
def test_strict_with_success(self):
1014
result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1016
test = self.get_passing_test()
1017
result.addSuccess(test)
1018
self.assertTrue(result.wasStrictlySuccessful())
1019
self.assertEqual(None, result._extractBenchmarkTime(test))
994
1022
class TestRunner(TestCase):
1108
1136
# Check if cleanup was called the right number of times.
1109
1137
self.assertEqual(0, test.counter)
1139
def test_not_applicable(self):
1140
# run a test that is skipped because it's not applicable
1141
def not_applicable_test():
1142
from bzrlib.tests import TestNotApplicable
1143
raise TestNotApplicable('this test never runs')
1145
runner = TextTestRunner(stream=out, verbosity=2)
1146
test = unittest.FunctionTestCase(not_applicable_test)
1147
result = self.run_test_runner(runner, test)
1148
self._log_file.write(out.getvalue())
1149
self.assertTrue(result.wasSuccessful())
1150
self.assertTrue(result.wasStrictlySuccessful())
1151
self.assertContainsRe(out.getvalue(),
1152
r'(?m)not_applicable_test * N/A')
1153
self.assertContainsRe(out.getvalue(),
1154
r'(?m)^ this test never runs')
1156
def test_not_applicable_demo(self):
1157
# just so you can see it in the test output
1158
raise TestNotApplicable('this test is just a demonstation')
1111
1160
def test_unsupported_features_listed(self):
1112
1161
"""When unsupported features are encountered they are detailed."""
1113
1162
class Feature1(Feature):