Back to index

python3.2  3.2.2
Public Member Functions | Private Attributes | Static Private Attributes
doctest.DocTestCase Class Reference
Inheritance diagram for doctest.DocTestCase:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def setUp
def tearDown
def runTest
def format_failure
def debug
def id
def __repr__
def shortDescription

Private Attributes

 _dt_optionflags
 _dt_checker
 _dt_test
 _dt_setUp
 _dt_tearDown

Static Private Attributes

 __str__ = __repr__

Detailed Description

Definition at line 2070 of file doctest.py.


Constructor & Destructor Documentation

def doctest.DocTestCase.__init__ (   self,
  test,
  optionflags = 0,
  setUp = None,
  tearDown = None,
  checker = None 
)

Definition at line 2073 of file doctest.py.

02073 
02074                  checker=None):
02075 
02076         unittest.TestCase.__init__(self)
02077         self._dt_optionflags = optionflags
02078         self._dt_checker = checker
02079         self._dt_test = test
02080         self._dt_setUp = setUp
02081         self._dt_tearDown = tearDown

Here is the caller graph for this function:


Member Function Documentation

Reimplemented in doctest.DocFileCase.

Definition at line 2207 of file doctest.py.

02207 
02208     def __repr__(self):
02209         name = self._dt_test.name.split('.')
02210         return "%s (%s)" % (name[-1], '.'.join(name[:-1]))

def doctest.DocTestCase.debug (   self)

Definition at line 2132 of file doctest.py.

02132 
02133     def debug(self):
02134         r"""Run the test case without results and without catching exceptions
02135 
02136            The unit test framework includes a debug method on test cases
02137            and test suites to support post-mortem debugging.  The test code
02138            is run in such a way that errors are not caught.  This way a
02139            caller can catch the errors and initiate post-mortem debugging.
02140 
02141            The DocTestCase provides a debug method that raises
02142            UnexpectedException errors if there is an unexpected
02143            exception:
02144 
02145              >>> test = DocTestParser().get_doctest('>>> raise KeyError\n42',
02146              ...                {}, 'foo', 'foo.py', 0)
02147              >>> case = DocTestCase(test)
02148              >>> try:
02149              ...     case.debug()
02150              ... except UnexpectedException as f:
02151              ...     failure = f
02152 
02153            The UnexpectedException contains the test, the example, and
02154            the original exception:
02155 
02156              >>> failure.test is test
02157              True
02158 
02159              >>> failure.example.want
02160              '42\n'
02161 
02162              >>> exc_info = failure.exc_info
02163              >>> raise exc_info[1] # Already has the traceback
02164              Traceback (most recent call last):
02165              ...
02166              KeyError
02167 
02168            If the output doesn't match, then a DocTestFailure is raised:
02169 
02170              >>> test = DocTestParser().get_doctest('''
02171              ...      >>> x = 1
02172              ...      >>> x
02173              ...      2
02174              ...      ''', {}, 'foo', 'foo.py', 0)
02175              >>> case = DocTestCase(test)
02176 
02177              >>> try:
02178              ...    case.debug()
02179              ... except DocTestFailure as f:
02180              ...    failure = f
02181 
02182            DocTestFailure objects provide access to the test:
02183 
02184              >>> failure.test is test
02185              True
02186 
02187            As well as to the example:
02188 
02189              >>> failure.example.want
02190              '2\n'
02191 
02192            and the actual output:
02193 
02194              >>> failure.got
02195              '1\n'
02196 
02197            """
02198 
02199         self.setUp()
02200         runner = DebugRunner(optionflags=self._dt_optionflags,
02201                              checker=self._dt_checker, verbose=False)
02202         runner.run(self._dt_test, clear_globs=False)
02203         self.tearDown()

Here is the caller graph for this function:

def doctest.DocTestCase.format_failure (   self,
  err 
)

Reimplemented in doctest.DocFileCase.

Definition at line 2120 of file doctest.py.

02120 
02121     def format_failure(self, err):
02122         test = self._dt_test
02123         if test.lineno is None:
02124             lineno = 'unknown line number'
02125         else:
02126             lineno = '%s' % test.lineno
02127         lname = '.'.join(test.name.split('.')[-1:])
02128         return ('Failed doctest test for %s\n'
02129                 '  File "%s", line %s, in %s\n\n%s'
02130                 % (test.name, test.filename, lineno, lname, err)
02131                 )

Here is the caller graph for this function:

def doctest.DocTestCase.id (   self)

Reimplemented in doctest.DocFileCase.

Definition at line 2204 of file doctest.py.

02204 
02205     def id(self):
02206         return self._dt_test.name

Here is the caller graph for this function:

Definition at line 2096 of file doctest.py.

02096 
02097     def runTest(self):
02098         test = self._dt_test
02099         old = sys.stdout
02100         new = StringIO()
02101         optionflags = self._dt_optionflags
02102 
02103         if not (optionflags & REPORTING_FLAGS):
02104             # The option flags don't include any reporting flags,
02105             # so add the default reporting flags
02106             optionflags |= _unittest_reportflags
02107 
02108         runner = DocTestRunner(optionflags=optionflags,
02109                                checker=self._dt_checker, verbose=False)
02110 
02111         try:
02112             runner.DIVIDER = "-"*70
02113             failures, tries = runner.run(
02114                 test, out=new.write, clear_globs=False)
02115         finally:
02116             sys.stdout = old
02117 
02118         if failures:
02119             raise self.failureException(self.format_failure(new.getvalue()))

Here is the call graph for this function:

def doctest.DocTestCase.setUp (   self)

Reimplemented in doctest.SkipDocTestCase.

Definition at line 2082 of file doctest.py.

02082 
02083     def setUp(self):
02084         test = self._dt_test
02085 
02086         if self._dt_setUp is not None:
02087             self._dt_setUp(test)

Here is the caller graph for this function:

Reimplemented in doctest.SkipDocTestCase.

Definition at line 2213 of file doctest.py.

02213 
02214     def shortDescription(self):
02215         return "Doctest: " + self._dt_test.name

Here is the caller graph for this function:

Definition at line 2088 of file doctest.py.

02088 
02089     def tearDown(self):
02090         test = self._dt_test
02091 
02092         if self._dt_tearDown is not None:
02093             self._dt_tearDown(test)
02094 
02095         test.globs.clear()

Here is the caller graph for this function:


Member Data Documentation

Reimplemented in doctest.DocFileCase.

Definition at line 2211 of file doctest.py.

Definition at line 2077 of file doctest.py.

Definition at line 2076 of file doctest.py.

Definition at line 2079 of file doctest.py.

Definition at line 2080 of file doctest.py.

Definition at line 2078 of file doctest.py.


The documentation for this class was generated from the following file: