1
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Test twisted's doctest support.
8
from twisted.trial import itrial, runner, unittest, reporter
9
from twisted.trial.test import mockdoctest
12
class TestRunners(unittest.TestCase):
14
Tests for Twisted's doctest support.
19
Check that the id() of the doctests' case object contains the FQPN of
20
the actual tests. We need this because id() has weird behaviour w/
21
doctest in Python 2.3.
23
loader = runner.TestLoader()
24
suite = loader.loadDoctests(mockdoctest)
25
idPrefix = 'twisted.trial.test.mockdoctest.Counter'
26
for test in suite._tests:
27
self.assertIn(idPrefix, itrial.ITestCase(test).id())
30
def makeDocSuite(self, module):
32
Return a L{runner.DocTestSuite} for the doctests in C{module}.
34
return self.assertWarns(
35
DeprecationWarning, "DocTestSuite is deprecated in Twisted 8.0.",
36
__file__, lambda: runner.DocTestSuite(mockdoctest))
39
def test_correctCount(self):
41
L{countTestCases} returns the number of doctests in the module.
43
suite = self.makeDocSuite(mockdoctest)
44
self.assertEqual(7, suite.countTestCases())
47
def test_basicTrialIntegration(self):
49
L{loadDoctests} loads all of the doctests in the given module.
51
loader = runner.TestLoader()
52
suite = loader.loadDoctests(mockdoctest)
53
self.assertEqual(7, suite.countTestCases())
56
def _testRun(self, suite):
58
Run C{suite} and check the result.
60
result = reporter.TestResult()
62
self.assertEqual(5, result.successes)
63
# doctest reports failures as errors in 2.3
64
self.assertEqual(2, len(result.errors) + len(result.failures))
67
def test_expectedResults(self, count=1):
69
Trial can correctly run doctests with its xUnit test APIs.
71
suite = runner.TestLoader().loadDoctests(mockdoctest)
75
def test_repeatable(self):
77
Doctests should be runnable repeatably.
79
suite = runner.TestLoader().loadDoctests(mockdoctest)