~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Robert Collins
  • Date: 2009-12-16 22:29:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4920.
  • Revision ID: robertc@robertcollins.net-20091216222931-wbbn5ey4mwmpatwd
Review feedback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
        log = details['log']
98
98
        self.assertThat(log.content_type, Equals(ContentType(
99
99
            "text", "plain", {"charset": "utf8"})))
100
 
        self.assertThat(u"".join(log.iter_text()),
 
100
        self.assertThat(u"".join(log.iter_text()), Equals(self.get_log()))
 
101
        self.assertThat(self.get_log(),
101
102
            DocTestMatches(u"...a test message\n", ELLIPSIS))
102
103
 
103
104
 
847
848
            def stopTestRun(self): pass
848
849
            def startTests(self): pass
849
850
            def report_test_start(self, test): pass
850
 
            def report_known_failure(self, test, err):
851
 
                self._call = test, err
 
851
            def report_known_failure(self, test, err=None, details=None):
 
852
                self._call = test, 'known failure'
852
853
        result = InstrumentedTestResult(None, None, None, None)
853
854
        class Test(tests.TestCase):
854
855
            def test_function(self):
858
859
        # it should invoke 'report_known_failure'.
859
860
        self.assertEqual(2, len(result._call))
860
861
        self.assertEqual(test.id(), result._call[0].id())
861
 
        self.assertEqual(tests.KnownFailure, result._call[1][0])
862
 
        self.assertIsInstance(result._call[1][1], tests.KnownFailure)
 
862
        self.assertEqual('known failure', result._call[1])
863
863
        # we dont introspec the traceback, if the rest is ok, it would be
864
864
        # exceptional for it not to be.
865
865
        # it should update the known_failure_count on the object.
1043
1043
        # the final output when real failures occur.
1044
1044
        class Test(tests.TestCase):
1045
1045
            def known_failure_test(self):
1046
 
                raise tests.KnownFailure('failed')
 
1046
                self.expectFailure('failed', self.assertTrue, False)
1047
1047
        test = unittest.TestSuite()
1048
1048
        test.addTest(Test("known_failure_test"))
1049
1049
        def failing_test():
1050
 
            raise AssertionError('foo')
 
1050
            self.fail('foo')
1051
1051
        test.addTest(unittest.FunctionTestCase(failing_test))
1052
1052
        stream = StringIO()
1053
1053
        runner = tests.TextTestRunner(stream=stream)
1061
1061
            '^----------------------------------------------------------------------\n'
1062
1062
            'Traceback \\(most recent call last\\):\n'
1063
1063
            '  .*' # File .*, line .*, in failing_test' - but maybe not from .pyc
1064
 
            '    raise AssertionError\\(\'foo\'\\)\n'
 
1064
            '    self.fail\\(\'foo\'\\)\n'
1065
1065
            '.*'
1066
1066
            '^----------------------------------------------------------------------\n'
1067
1067
            '.*'
1073
1073
        # the final output.
1074
1074
        class Test(tests.TestCase):
1075
1075
            def known_failure_test(self):
1076
 
                raise tests.KnownFailure('failed')
 
1076
                self.expectFailure('failed', self.assertTrue, False)
1077
1077
        test = Test("known_failure_test")
1078
1078
        stream = StringIO()
1079
1079
        runner = tests.TextTestRunner(stream=stream)
2340
2340
        self.assertEqual('bzr: interrupted\n', result[1])
2341
2341
 
2342
2342
 
2343
 
class TestKnownFailure(tests.TestCase):
2344
 
 
2345
 
    def test_known_failure(self):
2346
 
        """Check that KnownFailure is defined appropriately."""
2347
 
        # a KnownFailure is an assertion error for compatability with unaware
2348
 
        # runners.
2349
 
        self.assertIsInstance(tests.KnownFailure(""), AssertionError)
2350
 
 
2351
 
    def test_expect_failure(self):
2352
 
        try:
2353
 
            self.expectFailure("Doomed to failure", self.assertTrue, False)
2354
 
        except tests.KnownFailure, e:
2355
 
            self.assertEqual('Doomed to failure', e.args[0])
2356
 
        try:
2357
 
            self.expectFailure("Doomed to failure", self.assertTrue, True)
2358
 
        except AssertionError, e:
2359
 
            self.assertEqual('Unexpected success.  Should have failed:'
2360
 
                             ' Doomed to failure', e.args[0])
2361
 
        else:
2362
 
            self.fail('Assertion not raised')
2363
 
 
2364
 
 
2365
2343
class TestFeature(tests.TestCase):
2366
2344
 
2367
2345
    def test_caching(self):
2603
2581
        # the test framework
2604
2582
        self.assertEquals('always fails', str(e))
2605
2583
        # check that there's no traceback in the test log
2606
 
        log = u"".join(self.getDetails()['log'].iter_text())
2607
 
        self.assertNotContainsRe(log, r'Traceback')
 
2584
        self.assertNotContainsRe(self.get_log(), r'Traceback')
2608
2585
 
2609
2586
    def test_run_bzr_user_error_caught(self):
2610
2587
        # Running bzr in blackbox mode, normal/expected/user errors should be
2919
2896
        tpr.register('bar', 'bbb.aaa.rrr')
2920
2897
        tpr.register('bar', 'bBB.aAA.rRR')
2921
2898
        self.assertEquals('bbb.aaa.rrr', tpr.get('bar'))
2922
 
        self.assertThat(u"".join(self.getDetails()['log'].iter_text()),
 
2899
        self.assertThat(self.get_log(),
2923
2900
            DocTestMatches("...bar...bbb.aaa.rrr...BB.aAA.rRR", ELLIPSIS))
2924
2901
 
2925
2902
    def test_get_unknown_prefix(self):