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):
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')
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'
1064
1064
'^----------------------------------------------------------------------\n'
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)
2038
2038
def test_lsprof_tests(self):
2039
2039
self.requireFeature(test_lsprof.LSProfFeature)
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):
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)
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)
3527
class TestSelftestExcludePatterns(tests.TestCase):
3530
super(TestSelftestExcludePatterns, self).setUp()
3531
self.overrideAttr(tests, 'test_suite', self.suite_factory)
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):
3537
# We don't need the full class path
3538
return self._testMethodName
3545
return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")])
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)
3554
def test_full_list(self):
3555
self.assertTestList(['a', 'b', 'c'])
3557
def test_single_exclude(self):
3558
self.assertTestList(['b', 'c'], '-x', 'a')
3560
def test_mutiple_excludes(self):
3561
self.assertTestList(['c'], '-x', 'a', '-x', 'b')