~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

Pull out the test-case changes that I understand.

Stuff like avoiding closures over self by using a local variable,
and then assigning that local variable to an attribute of self.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for the test framework."""
18
18
 
19
19
from cStringIO import StringIO
20
 
import gc
21
20
import doctest
22
21
import os
23
22
import signal
3380
3379
        self.assertLength(1, calls)
3381
3380
 
3382
3381
 
3383
 
class TestUncollectedWarnings(tests.TestCase):
3384
 
    """Check a test case still alive after being run emits a warning"""
3385
 
 
3386
 
    class Test(tests.TestCase):
3387
 
        def test_pass(self):
3388
 
            pass
3389
 
        def test_self_ref(self):
3390
 
            self.also_self = self.test_self_ref
3391
 
        def test_skip(self):
3392
 
            self.skip("Don't need")
3393
 
 
3394
 
    def _get_suite(self):
3395
 
        return TestUtil.TestSuite([
3396
 
            self.Test("test_pass"),
3397
 
            self.Test("test_self_ref"),
3398
 
            self.Test("test_skip"),
3399
 
            ])
3400
 
 
3401
 
    def _run_selftest_with_suite(self, **kwargs):
3402
 
        sio = StringIO()
3403
 
        gc_on = gc.isenabled()
3404
 
        if gc_on:
3405
 
            gc.disable()
3406
 
        try:
3407
 
            tests.selftest(test_suite_factory=self._get_suite, stream=sio,
3408
 
                **kwargs)
3409
 
        finally:
3410
 
            if gc_on:
3411
 
                gc.enable()
3412
 
        output = sio.getvalue()
3413
 
        self.assertNotContainsRe(output, "Uncollected test case.*test_pass")
3414
 
        self.assertContainsRe(output, "Uncollected test case.*test_self_ref")
3415
 
        return output
3416
 
 
3417
 
    def test_testsuite(self):
3418
 
        self._run_selftest_with_suite()
3419
 
 
3420
 
    def test_pattern(self):
3421
 
        out = self._run_selftest_with_suite(pattern="test_(?:pass|self_ref)$")
3422
 
        self.assertNotContainsRe(out, "test_skip")
3423
 
 
3424
 
    def test_exclude_pattern(self):
3425
 
        out = self._run_selftest_with_suite(exclude_pattern="test_skip$")
3426
 
        self.assertNotContainsRe(out, "test_skip")
3427
 
 
3428
 
    def test_random_seed(self):
3429
 
        self._run_selftest_with_suite(random_seed="now")
3430
 
 
3431
 
    def test_matching_tests_first(self):
3432
 
        self._run_selftest_with_suite(matching_tests_first=True,
3433
 
            pattern="test_self_ref$")
3434
 
 
3435
 
    def test_starting_with_and_exclude(self):
3436
 
        out = self._run_selftest_with_suite(starting_with=["bt."],
3437
 
            exclude_pattern="test_skip$")
3438
 
        self.assertNotContainsRe(out, "test_skip")
3439
 
 
3440
 
    def test_additonal_decorator(self):
3441
 
        out = self._run_selftest_with_suite(
3442
 
            suite_decorators=[tests.TestDecorator])
3443
 
 
3444
 
 
3445
 
class TestUncollectedWarningsSubunit(TestUncollectedWarnings):
3446
 
    """Check warnings from tests staying alive are emitted with subunit"""
3447
 
 
3448
 
    _test_needs_features = [features.subunit]
3449
 
 
3450
 
    def _run_selftest_with_suite(self, **kwargs):
3451
 
        return TestUncollectedWarnings._run_selftest_with_suite(self,
3452
 
            runner_class=tests.SubUnitBzrRunner, **kwargs)
3453
 
 
3454
 
 
3455
3382
class TestEnvironHandling(tests.TestCase):
3456
3383
 
3457
3384
    def test_overrideEnv_None_called_twice_doesnt_leak(self):