~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-30 22:40:42 UTC
  • mfrom: (4323 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4324.
  • Revision ID: tanner@real-time.com-20090430224042-53v45axtue5bw45l
Merge 1.14.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib import (
29
29
    branchbuilder,
30
30
    bzrdir,
 
31
    debug,
31
32
    errors,
 
33
    lockdir,
32
34
    memorytree,
33
35
    osutils,
34
36
    remote,
619
621
        # But we have a safety net in place.
620
622
        self.assertRaises(AssertionError, self._check_safety_net)
621
623
 
 
624
    def test_dangling_locks_cause_failures(self):
 
625
        # This is currently only enabled during debug runs, so turn debugging
 
626
        # on.
 
627
        debug.debug_flags.add('lock')
 
628
        class TestDanglingLock(TestCaseWithMemoryTransport):
 
629
            def test_function(self):
 
630
                t = self.get_transport('.')
 
631
                l = lockdir.LockDir(t, 'lock')
 
632
                l.create()
 
633
                l.attempt_lock()
 
634
        test = TestDanglingLock('test_function')
 
635
        result = test.run()
 
636
        self.assertEqual(1, len(result.errors))
 
637
 
622
638
 
623
639
class TestTestCaseWithTransport(TestCaseWithTransport):
624
640
    """Tests for the convenience functions TestCaseWithTransport introduces."""
836
852
    def test_known_failure(self):
837
853
        """A KnownFailure being raised should trigger several result actions."""
838
854
        class InstrumentedTestResult(ExtendedTestResult):
839
 
 
 
855
            def done(self): pass
 
856
            def startTests(self): pass
840
857
            def report_test_start(self, test): pass
841
858
            def report_known_failure(self, test, err):
842
859
                self._call = test, err
884
901
        # text test output formatting
885
902
        pb = MockProgress()
886
903
        result = bzrlib.tests.TextTestResult(
887
 
            None,
 
904
            StringIO(),
888
905
            descriptions=0,
889
906
            verbosity=1,
890
907
            pb=pb,
924
941
    def test_add_not_supported(self):
925
942
        """Test the behaviour of invoking addNotSupported."""
926
943
        class InstrumentedTestResult(ExtendedTestResult):
 
944
            def done(self): pass
 
945
            def startTests(self): pass
927
946
            def report_test_start(self, test): pass
928
947
            def report_unsupported(self, test, feature):
929
948
                self._call = test, feature
966
985
        # text test output formatting
967
986
        pb = MockProgress()
968
987
        result = bzrlib.tests.TextTestResult(
969
 
            None,
 
988
            StringIO(),
970
989
            descriptions=0,
971
990
            verbosity=1,
972
991
            pb=pb,
994
1013
    def test_unavailable_exception(self):
995
1014
        """An UnavailableFeature being raised should invoke addNotSupported."""
996
1015
        class InstrumentedTestResult(ExtendedTestResult):
997
 
 
 
1016
            def done(self): pass
 
1017
            def startTests(self): pass
998
1018
            def report_test_start(self, test): pass
999
1019
            def addNotSupported(self, test, feature):
1000
1020
                self._call = test, feature
1037
1057
        self.assertTrue(result.wasStrictlySuccessful())
1038
1058
        self.assertEqual(None, result._extractBenchmarkTime(test))
1039
1059
 
 
1060
    def test_startTests(self):
 
1061
        """Starting the first test should trigger startTests."""
 
1062
        class InstrumentedTestResult(ExtendedTestResult):
 
1063
            calls = 0
 
1064
            def startTests(self): self.calls += 1
 
1065
            def report_test_start(self, test): pass
 
1066
        result = InstrumentedTestResult(None, None, None, None)
 
1067
        def test_function():
 
1068
            pass
 
1069
        test = unittest.FunctionTestCase(test_function)
 
1070
        test.run(result)
 
1071
        self.assertEquals(1, result.calls)
 
1072
 
1040
1073
 
1041
1074
class TestUnicodeFilenameFeature(TestCase):
1042
1075
 
1094
1127
            '----------------------------------------------------------------------',
1095
1128
            '',
1096
1129
            'FAILED (failures=1, known_failure_count=1)'],
1097
 
            lines[0:5] + lines[6:10] + lines[11:])
 
1130
            lines[3:8] + lines[9:13] + lines[14:])
1098
1131
 
1099
1132
    def test_known_failure_ok_run(self):
1100
1133
        # run a test that generates a known failure which should be printed in the final output.
2348
2381
                calls.append(test)
2349
2382
                return ExtendedTestResult(self.stream, self.descriptions,
2350
2383
                    self.verbosity)
2351
 
        run_suite(suite, runner_class=MyRunner)
 
2384
        run_suite(suite, runner_class=MyRunner, stream=StringIO())
2352
2385
        self.assertEqual(calls, [suite])
 
2386
 
 
2387
    def test_done(self):
 
2388
        """run_suite should call result.done()"""
 
2389
        self.calls = 0
 
2390
        def one_more_call(): self.calls += 1
 
2391
        def test_function():
 
2392
            pass
 
2393
        test = unittest.FunctionTestCase(test_function)
 
2394
        class InstrumentedTestResult(ExtendedTestResult):
 
2395
            def done(self): one_more_call()
 
2396
        class MyRunner(TextTestRunner):
 
2397
            def run(self, test):
 
2398
                return InstrumentedTestResult(self.stream, self.descriptions,
 
2399
                                              self.verbosity)
 
2400
        run_suite(test, runner_class=MyRunner, stream=StringIO())
 
2401
        self.assertEquals(1, self.calls)