~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-08-21 04:47:13 UTC
  • mfrom: (2695.1.5 test-cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20070821044713-ttnupbvhlsbwh1he
(mbp) fix problem with extractBenchmarkTime; better assertSubset

Show diffs side-by-side

added added

removed removed

Lines of Context:
706
706
 
707
707
class TestTestResult(TestCase):
708
708
 
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,
711
 
                                        descriptions=0,
712
 
                                        verbosity=1,
713
 
                                        )
714
 
        result._recordTestStartTime()
715
 
        time.sleep(0.003)
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$")
 
711
                descriptions=0,
 
712
                verbosity=1,
 
713
                )
 
714
        test_case.run(result)
 
715
        timed_string = result._testTimeString(test_case)
 
716
        self.assertContainsRe(timed_string, expected_re)
 
717
 
 
718
    def test_test_reporting(self):
 
719
        class ShortDelayTestCase(TestCase):
 
720
            def test_short_delay(self):
 
721
                time.sleep(0.003)
 
722
            def test_short_benchmark(self):
 
723
                self.time(time.sleep, 0.003)
 
724
        self.check_timing(ShortDelayTestCase('test_short_delay'),
 
725
                          r"^ +[0-9]+ms$")
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$")
734
729
 
 
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):
 
734
                time.sleep(0.003)
 
735
        self.check_timing(ShortDelayTestCase('test_short_delay'),
 
736
                          r"^ +[0-9]+ms$")
 
737
        
735
738
    def test_assigned_benchmark_file_stores_date(self):
736
739
        output = StringIO()
737
740
        result = bzrlib.tests.TextTestResult(self._log_file,
740
743
                                        bench_history=output
741
744
                                        )
742
745
        output_string = output.getvalue()
743
 
        
744
746
        # if you are wondering about the regexp please read the comment in
745
747
        # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
746
748
        # XXX: what comment?  -- Andrew Bennetts
845
847
            )
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
936
936
        test = self.get_passing_test()
937
937
        feature = Feature()
938
938
        result.startTest(test)
939
 
        result.extractBenchmarkTime(test)
940
939
        prefix = len(result_stream.getvalue())
941
940
        result.report_unsupported(test, feature)
942
941
        output = result_stream.getvalue()[prefix:]
956
955
        feature = Feature()
957
956
        # this seeds the state to handle reporting the test.
958
957
        result.startTest(test)
959
 
        result.extractBenchmarkTime(test)
960
958
        result.report_unsupported(test, feature)
961
959
        # no output on unsupported features
962
960
        self.assertEqual(
995
993
 
996
994
    def test_strict_with_unsupported_feature(self):
997
995
        result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
998
 
                                                verbosity=1)
 
996
                                             verbosity=1)
999
997
        test = self.get_passing_test()
1000
998
        feature = "Unsupported Feature"
1001
999
        result.addNotSupported(test, feature)
1002
1000
        self.assertFalse(result.wasStrictlySuccessful())
1003
 
 
 
1001
        self.assertEqual(None, result._extractBenchmarkTime(test))
 
1002
 
1004
1003
    def test_strict_with_known_failure(self):
1005
1004
        result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1006
 
                                                verbosity=1)
 
1005
                                             verbosity=1)
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))
1011
1011
 
1012
1012
    def test_strict_with_success(self):
1013
1013
        result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1014
 
                                                verbosity=1)
 
1014
                                             verbosity=1)
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))
1018
1019
 
1019
1020
 
1020
1021
class TestRunner(TestCase):