~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-26 08:05:45 UTC
  • mfrom: (5916 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5917.
  • Revision ID: john@arbash-meinel.com-20110526080545-5tprxfczyj4bfk0o
Merge bzr.dev 5916 and make sure the right patch is applied.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    DocTestMatches,
37
37
    Equals,
38
38
    )
39
 
import testtools.tests.helpers
 
39
import testtools.testresult.doubles
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.tests.helpers.ExtendedTestResult()
 
724
        terminal = testtools.testresult.doubles.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.tests.helpers.ExtendedTestResult()
 
747
        capture = testtools.testresult.doubles.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
 
            self.fail('foo')
 
1048
            raise AssertionError('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
 
            '    self.fail\\(\'foo\'\\)\n'
 
1062
            '    raise AssertionError\\(\'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.expectFailure('failed', self.assertTrue, False)
 
1074
                self.knownFailure("Never works...")
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
 
        calls = []
 
2040
        results = []
2041
2041
        class Test(object):
2042
2042
            def __call__(test, result):
2043
2043
                test.run(result)
2044
2044
            def run(test, result):
2045
 
                self.assertIsInstance(result, ExtendedToOriginalDecorator)
2046
 
                calls.append("called")
 
2045
                results.append(result)
2047
2046
            def countTestCases(self):
2048
2047
                return 1
2049
2048
        self.run_selftest(test_suite_factory=Test, lsprof_tests=True)
2050
 
        self.assertLength(1, calls)
 
2049
        self.assertLength(1, results)
 
2050
        self.assertIsInstance(results.pop(), ExtendedToOriginalDecorator)
2051
2051
 
2052
2052
    def test_random(self):
2053
2053
        # test randomising by listing a number of tests.
2195
2195
        content, result = self.run_subunit_stream('test_unexpected_success')
2196
2196
        self.assertContainsRe(content, '(?m)^log$')
2197
2197
        self.assertContainsRe(content, 'test with unexpected success')
2198
 
        self.expectFailure('subunit treats "unexpectedSuccess"'
2199
 
                           ' as a plain success',
2200
 
            self.assertEqual, 1, len(result.unexpectedSuccesses))
 
2198
        # GZ 2011-05-18: Old versions of subunit treat unexpected success as a
 
2199
        #                success, if a min version check is added remove this
 
2200
        from subunit import TestProtocolClient as _Client
 
2201
        if _Client.addUnexpectedSuccess.im_func is _Client.addSuccess.im_func:
 
2202
            self.expectFailure('subunit treats "unexpectedSuccess"'
 
2203
                               ' as a plain success',
 
2204
                self.assertEqual, 1, len(result.unexpectedSuccesses))
2201
2205
        self.assertEqual(1, len(result.unexpectedSuccesses))
2202
2206
        test = result.unexpectedSuccesses[0]
2203
2207
        # RemotedTestCase doesn't preserve the "details"