~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: 2009-11-02 11:05:12 UTC
  • mfrom: (4780.1.5 subunit)
  • Revision ID: pqm@pqm.ubuntu.com-20091102110512-yw3aimu88nbmvoo9
(robertc) Overhaul TestResult handling of test outcomes to degrade
        more gracefully and be more compatible with Python2.7 (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
827
827
            def report_known_failure(self, test, err):
828
828
                self._call = test, err
829
829
        result = InstrumentedTestResult(None, None, None, None)
830
 
        def test_function():
831
 
            raise tests.KnownFailure('failed!')
832
 
        test = unittest.FunctionTestCase(test_function)
 
830
        class Test(tests.TestCase):
 
831
            def test_function(self):
 
832
                raise tests.KnownFailure('failed!')
 
833
        test = Test("test_function")
833
834
        test.run(result)
834
835
        # it should invoke 'report_known_failure'.
835
836
        self.assertEqual(2, len(result._call))
926
927
                self._call = test, feature
927
928
        result = InstrumentedTestResult(None, None, None, None)
928
929
        feature = tests.Feature()
929
 
        def test_function():
930
 
            raise tests.UnavailableFeature(feature)
931
 
        test = unittest.FunctionTestCase(test_function)
 
930
        class Test(tests.TestCase):
 
931
            def test_function(self):
 
932
                raise tests.UnavailableFeature(feature)
 
933
        test = Test("test_function")
932
934
        test.run(result)
933
935
        # it should invoke 'addNotSupported'.
934
936
        self.assertEqual(2, len(result._call))
951
953
                                             verbosity=1)
952
954
        test = self.get_passing_test()
953
955
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
954
 
        result._addKnownFailure(test, err)
 
956
        result.addExpectedFailure(test, err)
955
957
        self.assertFalse(result.wasStrictlySuccessful())
956
958
        self.assertEqual(None, result._extractBenchmarkTime(test))
957
959
 
1014
1016
    def test_known_failure_failed_run(self):
1015
1017
        # run a test that generates a known failure which should be printed in
1016
1018
        # the final output when real failures occur.
1017
 
        def known_failure_test():
1018
 
            raise tests.KnownFailure('failed')
 
1019
        class Test(tests.TestCase):
 
1020
            def known_failure_test(self):
 
1021
                raise tests.KnownFailure('failed')
1019
1022
        test = unittest.TestSuite()
1020
 
        test.addTest(unittest.FunctionTestCase(known_failure_test))
 
1023
        test.addTest(Test("known_failure_test"))
1021
1024
        def failing_test():
1022
1025
            raise AssertionError('foo')
1023
1026
        test.addTest(unittest.FunctionTestCase(failing_test))
1041
1044
            )
1042
1045
 
1043
1046
    def test_known_failure_ok_run(self):
1044
 
        # run a test that generates a known failure which should be printed in the final output.
1045
 
        def known_failure_test():
1046
 
            raise tests.KnownFailure('failed')
1047
 
        test = unittest.FunctionTestCase(known_failure_test)
 
1047
        # run a test that generates a known failure which should be printed in
 
1048
        # the final output.
 
1049
        class Test(tests.TestCase):
 
1050
            def known_failure_test(self):
 
1051
                raise tests.KnownFailure('failed')
 
1052
        test = Test("known_failure_test")
1048
1053
        stream = StringIO()
1049
1054
        runner = tests.TextTestRunner(stream=stream)
1050
1055
        result = self.run_test_runner(runner, test)
1127
1132
 
1128
1133
    def test_not_applicable(self):
1129
1134
        # run a test that is skipped because it's not applicable
1130
 
        def not_applicable_test():
1131
 
            raise tests.TestNotApplicable('this test never runs')
 
1135
        class Test(tests.TestCase):
 
1136
            def not_applicable_test(self):
 
1137
                raise tests.TestNotApplicable('this test never runs')
1132
1138
        out = StringIO()
1133
1139
        runner = tests.TextTestRunner(stream=out, verbosity=2)
1134
 
        test = unittest.FunctionTestCase(not_applicable_test)
 
1140
        test = Test("not_applicable_test")
1135
1141
        result = self.run_test_runner(runner, test)
1136
1142
        self._log_file.write(out.getvalue())
1137
1143
        self.assertTrue(result.wasSuccessful())