~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/trial/test/test_doctest.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2001-2008 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 makeDocSuite(self, module):
 
31
        """
 
32
        Return a L{runner.DocTestSuite} for the doctests in C{module}.
 
33
        """
 
34
        return self.assertWarns(
 
35
            DeprecationWarning, "DocTestSuite is deprecated in Twisted 8.0.",
 
36
            __file__, lambda: runner.DocTestSuite(mockdoctest))
 
37
 
 
38
 
 
39
    def test_correctCount(self):
 
40
        """
 
41
        L{countTestCases} returns the number of doctests in the module.
 
42
        """
 
43
        suite = self.makeDocSuite(mockdoctest)
 
44
        self.assertEqual(7, suite.countTestCases())
 
45
 
 
46
 
 
47
    def test_basicTrialIntegration(self):
 
48
        """
 
49
        L{loadDoctests} loads all of the doctests in the given module.
 
50
        """
 
51
        loader = runner.TestLoader()
 
52
        suite = loader.loadDoctests(mockdoctest)
 
53
        self.assertEqual(7, suite.countTestCases())
 
54
 
 
55
 
 
56
    def _testRun(self, suite):
 
57
        """
 
58
        Run C{suite} and check the result.
 
59
        """
 
60
        result = reporter.TestResult()
 
61
        suite.run(result)
 
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))
 
65
 
 
66
 
 
67
    def test_expectedResults(self, count=1):
 
68
        """
 
69
        Trial can correctly run doctests with its xUnit test APIs.
 
70
        """
 
71
        suite = runner.TestLoader().loadDoctests(mockdoctest)
 
72
        self._testRun(suite)
 
73
 
 
74
 
 
75
    def test_repeatable(self):
 
76
        """
 
77
        Doctests should be runnable repeatably.
 
78
        """
 
79
        suite = runner.TestLoader().loadDoctests(mockdoctest)
 
80
        self._testRun(suite)
 
81
        self._testRun(suite)