~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-08-27 13:20:24 UTC
  • mfrom: (4650.1.9 test-speed)
  • Revision ID: pqm@pqm.ubuntu.com-20090827132024-h13eo7blndo2dfpl
(robertc) Detangle core logic inselftest to make it more
        understandable and compatible with current python. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
820
820
    def test_known_failure(self):
821
821
        """A KnownFailure being raised should trigger several result actions."""
822
822
        class InstrumentedTestResult(tests.ExtendedTestResult):
823
 
            def done(self): pass
 
823
            def stopTestRun(self): pass
824
824
            def startTests(self): pass
825
825
            def report_test_start(self, test): pass
826
826
            def report_known_failure(self, test, err):
874
874
    def test_add_not_supported(self):
875
875
        """Test the behaviour of invoking addNotSupported."""
876
876
        class InstrumentedTestResult(tests.ExtendedTestResult):
877
 
            def done(self): pass
 
877
            def stopTestRun(self): pass
878
878
            def startTests(self): pass
879
879
            def report_test_start(self, test): pass
880
880
            def report_unsupported(self, test, feature):
918
918
    def test_unavailable_exception(self):
919
919
        """An UnavailableFeature being raised should invoke addNotSupported."""
920
920
        class InstrumentedTestResult(tests.ExtendedTestResult):
921
 
            def done(self): pass
 
921
            def stopTestRun(self): pass
922
922
            def startTests(self): pass
923
923
            def report_test_start(self, test): pass
924
924
            def addNotSupported(self, test, feature):
1001
1001
        because of our use of global state.
1002
1002
        """
1003
1003
        old_root = tests.TestCaseInTempDir.TEST_ROOT
 
1004
        old_leak = tests.TestCase._first_thread_leaker_id
1004
1005
        try:
1005
1006
            tests.TestCaseInTempDir.TEST_ROOT = None
 
1007
            tests.TestCase._first_thread_leaker_id = None
1006
1008
            return testrunner.run(test)
1007
1009
        finally:
1008
1010
            tests.TestCaseInTempDir.TEST_ROOT = old_root
 
1011
            tests.TestCase._first_thread_leaker_id = old_leak
1009
1012
 
1010
1013
    def test_known_failure_failed_run(self):
1011
1014
        # run a test that generates a known failure which should be printed in
1291
1294
        self.assertContainsRe(log, 'this will be kept')
1292
1295
        self.assertEqual(log, test._log_contents)
1293
1296
 
 
1297
    def test_startTestRun(self):
 
1298
        """run should call result.startTestRun()"""
 
1299
        calls = []
 
1300
        class LoggingDecorator(tests.ForwardingResult):
 
1301
            def startTestRun(self):
 
1302
                tests.ForwardingResult.startTestRun(self)
 
1303
                calls.append('startTestRun')
 
1304
        test = unittest.FunctionTestCase(lambda:None)
 
1305
        stream = StringIO()
 
1306
        runner = tests.TextTestRunner(stream=stream,
 
1307
            result_decorators=[LoggingDecorator])
 
1308
        result = self.run_test_runner(runner, test)
 
1309
        self.assertLength(1, calls)
 
1310
 
 
1311
    def test_stopTestRun(self):
 
1312
        """run should call result.stopTestRun()"""
 
1313
        calls = []
 
1314
        class LoggingDecorator(tests.ForwardingResult):
 
1315
            def stopTestRun(self):
 
1316
                tests.ForwardingResult.stopTestRun(self)
 
1317
                calls.append('stopTestRun')
 
1318
        test = unittest.FunctionTestCase(lambda:None)
 
1319
        stream = StringIO()
 
1320
        runner = tests.TextTestRunner(stream=stream,
 
1321
            result_decorators=[LoggingDecorator])
 
1322
        result = self.run_test_runner(runner, test)
 
1323
        self.assertLength(1, calls)
 
1324
 
1294
1325
 
1295
1326
class SampleTestCase(tests.TestCase):
1296
1327
 
2934
2965
                                                self.verbosity)
2935
2966
        tests.run_suite(suite, runner_class=MyRunner, stream=StringIO())
2936
2967
        self.assertLength(1, calls)
2937
 
 
2938
 
    def test_done(self):
2939
 
        """run_suite should call result.done()"""
2940
 
        self.calls = 0
2941
 
        def one_more_call(): self.calls += 1
2942
 
        def test_function():
2943
 
            pass
2944
 
        test = unittest.FunctionTestCase(test_function)
2945
 
        class InstrumentedTestResult(tests.ExtendedTestResult):
2946
 
            def done(self): one_more_call()
2947
 
        class MyRunner(tests.TextTestRunner):
2948
 
            def run(self, test):
2949
 
                return InstrumentedTestResult(self.stream, self.descriptions,
2950
 
                                              self.verbosity)
2951
 
        tests.run_suite(test, runner_class=MyRunner, stream=StringIO())
2952
 
        self.assertEquals(1, self.calls)