~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

(jameinel) (bug #780544) when updating the WT,
 allow it to be done with a fast delta,
 rather than setting the state from scratch. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    DocTestMatches,
37
37
    Equals,
38
38
    )
39
 
import testtools.testresult.doubles
 
39
import testtools.tests.helpers
40
40
 
41
41
import bzrlib
42
42
from bzrlib import (
721
721
 
722
722
    def test_profiles_tests(self):
723
723
        self.requireFeature(test_lsprof.LSProfFeature)
724
 
        terminal = testtools.testresult.doubles.ExtendedTestResult()
 
724
        terminal = testtools.tests.helpers.ExtendedTestResult()
725
725
        result = tests.ProfileResult(terminal)
726
726
        class Sample(tests.TestCase):
727
727
            def a(self):
744
744
                descriptions=0,
745
745
                verbosity=1,
746
746
                )
747
 
        capture = testtools.testresult.doubles.ExtendedTestResult()
 
747
        capture = testtools.tests.helpers.ExtendedTestResult()
748
748
        test_case.run(MultiTestResult(result, capture))
749
749
        run_case = capture._events[0][1]
750
750
        timed_string = result._testTimeString(run_case)
1045
1045
        test = unittest.TestSuite()
1046
1046
        test.addTest(Test("known_failure_test"))
1047
1047
        def failing_test():
1048
 
            raise AssertionError('foo')
 
1048
            self.fail('foo')
1049
1049
        test.addTest(unittest.FunctionTestCase(failing_test))
1050
1050
        stream = StringIO()
1051
1051
        runner = tests.TextTestRunner(stream=stream)
1059
1059
            '^----------------------------------------------------------------------\n'
1060
1060
            'Traceback \\(most recent call last\\):\n'
1061
1061
            '  .*' # File .*, line .*, in failing_test' - but maybe not from .pyc
1062
 
            '    raise AssertionError\\(\'foo\'\\)\n'
 
1062
            '    self.fail\\(\'foo\'\\)\n'
1063
1063
            '.*'
1064
1064
            '^----------------------------------------------------------------------\n'
1065
1065
            '.*'
1071
1071
        # the final output.
1072
1072
        class Test(tests.TestCase):
1073
1073
            def known_failure_test(self):
1074
 
                self.knownFailure("Never works...")
 
1074
                self.expectFailure('failed', self.assertTrue, False)
1075
1075
        test = Test("known_failure_test")
1076
1076
        stream = StringIO()
1077
1077
        runner = tests.TextTestRunner(stream=stream)
2037
2037
 
2038
2038
    def test_lsprof_tests(self):
2039
2039
        self.requireFeature(test_lsprof.LSProfFeature)
2040
 
        results = []
 
2040
        calls = []
2041
2041
        class Test(object):
2042
2042
            def __call__(test, result):
2043
2043
                test.run(result)
2044
2044
            def run(test, result):
2045
 
                results.append(result)
 
2045
                self.assertIsInstance(result, ExtendedToOriginalDecorator)
 
2046
                calls.append("called")
2046
2047
            def countTestCases(self):
2047
2048
                return 1
2048
2049
        self.run_selftest(test_suite_factory=Test, lsprof_tests=True)
2049
 
        self.assertLength(1, results)
2050
 
        self.assertIsInstance(results.pop(), ExtendedToOriginalDecorator)
 
2050
        self.assertLength(1, calls)
2051
2051
 
2052
2052
    def test_random(self):
2053
2053
        # test randomising by listing a number of tests.
3522
3522
        self.assertDocTestStringFails(doctest.DocTestSuite, test)
3523
3523
        # tests.DocTestSuite sees None
3524
3524
        self.assertDocTestStringSucceds(tests.IsolatedDocTestSuite, test)
3525
 
 
3526
 
 
3527
 
class TestSelftestExcludePatterns(tests.TestCase):
3528
 
 
3529
 
    def setUp(self):
3530
 
        super(TestSelftestExcludePatterns, self).setUp()
3531
 
        self.overrideAttr(tests, 'test_suite', self.suite_factory)
3532
 
 
3533
 
    def suite_factory(self, keep_only=None, starting_with=None):
3534
 
        """A test suite factory with only a few tests."""
3535
 
        class Test(tests.TestCase):
3536
 
            def id(self):
3537
 
                # We don't need the full class path
3538
 
                return self._testMethodName
3539
 
            def a(self):
3540
 
                pass
3541
 
            def b(self):
3542
 
                pass
3543
 
            def c(self):
3544
 
                pass
3545
 
        return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")])
3546
 
 
3547
 
    def assertTestList(self, expected, *selftest_args):
3548
 
        # We rely on setUp installing the right test suite factory so we can
3549
 
        # test at the command level without loading the whole test suite
3550
 
        out, err = self.run_bzr(('selftest', '--list') + selftest_args)
3551
 
        actual = out.splitlines()
3552
 
        self.assertEquals(expected, actual)
3553
 
 
3554
 
    def test_full_list(self):
3555
 
        self.assertTestList(['a', 'b', 'c'])
3556
 
 
3557
 
    def test_single_exclude(self):
3558
 
        self.assertTestList(['b', 'c'], '-x', 'a')
3559
 
 
3560
 
    def test_mutiple_excludes(self):
3561
 
        self.assertTestList(['c'], '-x', 'a', '-x', 'b')