/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Vincent Ladeuil
  • Date: 2010-10-13 07:55:13 UTC
  • mfrom: (5492 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5501.
  • Revision ID: v.ladeuil+lp@free.fr-20101013075513-hil6q8xi7i9e3ozq
Merge bzr.dev fixing NEWS entry

Show diffs side-by-side

added added

removed removed

Lines of Context:
849
849
        self.assertContainsRe(output,
850
850
            r"LSProf output for <type 'unicode'>\(\('world',\), {'errors': 'replace'}\)\n")
851
851
 
 
852
    def test_uses_time_from_testtools(self):
 
853
        """Test case timings in verbose results should use testtools times"""
 
854
        import datetime
 
855
        class TimeAddedVerboseTestResult(tests.VerboseTestResult):
 
856
            def startTest(self, test):
 
857
                self.time(datetime.datetime.utcfromtimestamp(1.145))
 
858
                super(TimeAddedVerboseTestResult, self).startTest(test)
 
859
            def addSuccess(self, test):
 
860
                self.time(datetime.datetime.utcfromtimestamp(51.147))
 
861
                super(TimeAddedVerboseTestResult, self).addSuccess(test)
 
862
            def report_tests_starting(self): pass
 
863
        sio = StringIO()
 
864
        self.get_passing_test().run(TimeAddedVerboseTestResult(sio, 0, 2))
 
865
        self.assertEndsWith(sio.getvalue(), "OK    50002ms\n")
 
866
 
852
867
    def test_known_failure(self):
853
868
        """A KnownFailure being raised should trigger several result actions."""
854
869
        class InstrumentedTestResult(tests.ExtendedTestResult):
3301
3316
        self.assertContainsString(result.stream.getvalue(), "leaking threads")
3302
3317
 
3303
3318
 
 
3319
class TestPostMortemDebugging(tests.TestCase):
 
3320
    """Check post mortem debugging works when tests fail or error"""
 
3321
 
 
3322
    class TracebackRecordingResult(tests.ExtendedTestResult):
 
3323
        def __init__(self):
 
3324
            tests.ExtendedTestResult.__init__(self, StringIO(), 0, 1)
 
3325
            self.postcode = None
 
3326
        def _post_mortem(self, tb=None):
 
3327
            """Record the code object at the end of the current traceback"""
 
3328
            tb = tb or sys.exc_info()[2]
 
3329
            if tb is not None:
 
3330
                next = tb.tb_next
 
3331
                while next is not None:
 
3332
                    tb = next
 
3333
                    next = next.tb_next
 
3334
                self.postcode = tb.tb_frame.f_code
 
3335
        def report_error(self, test, err):
 
3336
            pass
 
3337
        def report_failure(self, test, err):
 
3338
            pass
 
3339
 
 
3340
    def test_location_unittest_error(self):
 
3341
        """Needs right post mortem traceback with erroring unittest case"""
 
3342
        class Test(unittest.TestCase):
 
3343
            def runTest(self):
 
3344
                raise RuntimeError
 
3345
        result = self.TracebackRecordingResult()
 
3346
        Test().run(result)
 
3347
        self.assertEqual(result.postcode, Test.runTest.func_code)
 
3348
 
 
3349
    def test_location_unittest_failure(self):
 
3350
        """Needs right post mortem traceback with failing unittest case"""
 
3351
        class Test(unittest.TestCase):
 
3352
            def runTest(self):
 
3353
                raise self.failureException
 
3354
        result = self.TracebackRecordingResult()
 
3355
        Test().run(result)
 
3356
        self.assertEqual(result.postcode, Test.runTest.func_code)
 
3357
 
 
3358
    def test_location_bt_error(self):
 
3359
        """Needs right post mortem traceback with erroring bzrlib.tests case"""
 
3360
        class Test(tests.TestCase):
 
3361
            def test_error(self):
 
3362
                raise RuntimeError
 
3363
        result = self.TracebackRecordingResult()
 
3364
        Test("test_error").run(result)
 
3365
        self.assertEqual(result.postcode, Test.test_error.func_code)
 
3366
 
 
3367
    def test_location_bt_failure(self):
 
3368
        """Needs right post mortem traceback with failing bzrlib.tests case"""
 
3369
        class Test(tests.TestCase):
 
3370
            def test_failure(self):
 
3371
                raise self.failureException
 
3372
        result = self.TracebackRecordingResult()
 
3373
        Test("test_failure").run(result)
 
3374
        self.assertEqual(result.postcode, Test.test_failure.func_code)
 
3375
 
 
3376
    def test_env_var_triggers_post_mortem(self):
 
3377
        """Check pdb.post_mortem is called iff BZR_TEST_PDB is set"""
 
3378
        import pdb
 
3379
        result = tests.ExtendedTestResult(StringIO(), 0, 1)
 
3380
        post_mortem_calls = []
 
3381
        self.overrideAttr(pdb, "post_mortem", post_mortem_calls.append)
 
3382
        self.addCleanup(osutils.set_or_unset_env, "BZR_TEST_PDB",
 
3383
            osutils.set_or_unset_env("BZR_TEST_PDB", None))
 
3384
        result._post_mortem(1)
 
3385
        os.environ["BZR_TEST_PDB"] = "on"
 
3386
        result._post_mortem(2)
 
3387
        self.assertEqual([2], post_mortem_calls)
 
3388
 
 
3389
 
3304
3390
class TestRunSuite(tests.TestCase):
3305
3391
 
3306
3392
    def test_runner_class(self):