Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / trial / test / test_doctest.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Test Twisted's doctest support.
6 """
7
8 from twisted.trial import itrial, runner, unittest, reporter
9 from twisted.trial.test import mockdoctest
10
11
12 class TestRunners(unittest.TestCase):
13     """
14     Tests for Twisted's doctest support.
15     """
16
17     def test_id(self):
18         """
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.
22         """
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())
28
29
30     def test_basicTrialIntegration(self):
31         """
32         L{loadDoctests} loads all of the doctests in the given module.
33         """
34         loader = runner.TestLoader()
35         suite = loader.loadDoctests(mockdoctest)
36         self.assertEqual(7, suite.countTestCases())
37
38
39     def _testRun(self, suite):
40         """
41         Run C{suite} and check the result.
42         """
43         result = reporter.TestResult()
44         suite.run(result)
45         self.assertEqual(5, result.successes)
46         # doctest reports failures as errors in 2.3
47         self.assertEqual(2, len(result.errors) + len(result.failures))
48
49
50     def test_expectedResults(self, count=1):
51         """
52         Trial can correctly run doctests with its xUnit test APIs.
53         """
54         suite = runner.TestLoader().loadDoctests(mockdoctest)
55         self._testRun(suite)
56
57
58     def test_repeatable(self):
59         """
60         Doctests should be runnable repeatably.
61         """
62         suite = runner.TestLoader().loadDoctests(mockdoctest)
63         self._testRun(suite)
64         self._testRun(suite)