class DocTestCase(TestCase):
methods:
def __init__(self, test, optionflags=0, setUp=None, tearDown=None, checker=None):
*no docstring available*
arguments:
- self: <UNKNOWN>
- test: <UNKNOWN>
- optionflags: <UNKNOWN>
- setUp: <UNKNOWN>
- tearDown: <UNKNOWN>
- checker: <UNKNOWN>
return value:
<UNKNOWN>
source: compat/doctest.py
2112 |
2113 |
2114 |
2115 |
2116 |
2117 |
2118 |
2119 |
2120 | |
def __init__(self, test, optionflags=0, setUp=None, tearDown=None, |
checker=None): |
|
unittest.TestCase.__init__(self) |
self._dt_optionflags = optionflags |
self._dt_checker = checker |
self._dt_test = test |
self._dt_setUp = setUp |
self._dt_tearDown = tearDown | |
def failUnlessAlmostEqual(self, first, second, places=7, msg=None):
Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- places: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnlessAlmostEqual(self, first, second, places=7, msg=None):
Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- places: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnlessEqual(self, first, second, msg=None):
Fail if the two objects are unequal as determined by the '=='
operator.
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnlessEqual(self, first, second, msg=None):
Fail if the two objects are unequal as determined by the '=='
operator.
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failIf(self, expr, msg=None):
Fail the test if the expression is true.
arguments:
- self: <UNKNOWN>
- expr: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failIfAlmostEqual(self, first, second, places=7, msg=None):
Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- places: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failIfAlmostEqual(self, first, second, places=7, msg=None):
Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- places: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failIfEqual(self, first, second, msg=None):
Fail if the two objects are equal as determined by the '=='
operator.
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failIfEqual(self, first, second, msg=None):
Fail if the two objects are equal as determined by the '=='
operator.
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnlessRaises(self, excClass, callableObj, *args, **kwargs):
Fail unless an exception of class excClass is thrown
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
thrown, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
arguments:
- self: <UNKNOWN>
- excClass: <UNKNOWN>
- callableObj: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnless(self, expr, msg=None):
Fail the test unless the expression is true.
arguments:
- self: <UNKNOWN>
- expr: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnless(self, expr, msg=None):
Fail the test unless the expression is true.
arguments:
- self: <UNKNOWN>
- expr: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def countTestCases(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
could not get to source file
def debug(self):
Run the test case without results and without catching exceptions
The unit test framework includes a debug method on test cases
and test suites to support post-mortem debugging. The test code
is run in such a way that errors are not caught. This way a
caller can catch the errors and initiate post-mortem debugging.
The DocTestCase provides a debug method that raises
UnexpectedException errors if there is an unexepcted
exception:
>>> test = DocTestParser().get_doctest('>>> raise KeyError\n42',
... {}, 'foo', 'foo.py', 0)
>>> case = DocTestCase(test)
>>> try:
... case.debug()
... except UnexpectedException, failure:
... pass
The UnexpectedException contains the test, the example, and
the original exception:
>>> failure.test is test
True
>>> failure.example.want
'42\n'
>>> exc_info = failure.exc_info
>>> raise exc_info[0], exc_info[1], exc_info[2]
Traceback (most recent call last):
...
KeyError
If the output doesn't match, then a DocTestFailure is raised:
>>> test = DocTestParser().get_doctest('''
... >>> x = 1
... >>> x
... 2
... ''', {}, 'foo', 'foo.py', 0)
>>> case = DocTestCase(test)
>>> try:
... case.debug()
... except DocTestFailure, failure:
... pass
DocTestFailure objects provide access to the test:
>>> failure.test is test
True
As well as to the example:
>>> failure.example.want
'2\n'
and the actual output:
>>> failure.got
'1\n'
arguments:
return value:
<UNKNOWN>
source: compat/doctest.py
2172 |
2173 |
2174 |
2175 |
2176 |
2177 |
2178 |
2179 |
2180 |
2181 |
2182 |
2183 |
2184 |
2185 |
2186 |
2187 |
2188 |
2189 |
2190 |
2191 |
2192 |
2193 |
2194 |
2195 |
2196 |
2197 |
2198 |
2199 |
2200 |
2201 |
2202 |
2203 |
2204 |
2205 |
2206 |
2207 |
2208 |
2209 |
2210 |
2211 |
2212 |
2213 |
2214 |
2215 |
2216 |
2217 |
2218 |
2219 |
2220 |
2221 |
2222 |
2223 |
2224 |
2225 |
2226 |
2227 |
2228 |
2229 |
2230 |
2231 |
2232 |
2233 |
2234 |
2235 |
2236 |
2237 |
2238 |
2239 |
2240 |
2241 |
2242 | |
def debug(self): |
r"""Run the test case without results and without catching exceptions |
|
The unit test framework includes a debug method on test cases |
and test suites to support post-mortem debugging. The test code |
is run in such a way that errors are not caught. This way a |
caller can catch the errors and initiate post-mortem debugging. |
|
The DocTestCase provides a debug method that raises |
UnexpectedException errors if there is an unexepcted |
exception: |
|
>>> test = DocTestParser().get_doctest('>>> raise KeyError\n42', |
... {}, 'foo', 'foo.py', 0) |
>>> case = DocTestCase(test) |
>>> try: |
... case.debug() |
... except UnexpectedException, failure: |
... pass |
|
The UnexpectedException contains the test, the example, and |
the original exception: |
|
>>> failure.test is test |
True |
|
>>> failure.example.want |
'42\n' |
|
>>> exc_info = failure.exc_info |
>>> raise exc_info[0], exc_info[1], exc_info[2] |
Traceback (most recent call last): |
... |
KeyError |
|
If the output doesn't match, then a DocTestFailure is raised: |
|
>>> test = DocTestParser().get_doctest(''' |
... >>> x = 1 |
... >>> x |
... 2 |
... ''', {}, 'foo', 'foo.py', 0) |
>>> case = DocTestCase(test) |
|
>>> try: |
... case.debug() |
... except DocTestFailure, failure: |
... pass |
|
DocTestFailure objects provide access to the test: |
|
>>> failure.test is test |
True |
|
As well as to the example: |
|
>>> failure.example.want |
'2\n' |
|
and the actual output: |
|
>>> failure.got |
'1\n' |
|
""" |
|
self.setUp() |
runner = DebugRunner(optionflags=self._dt_optionflags, |
checker=self._dt_checker, verbose=False) |
runner.run(self._dt_test) |
self.tearDown() | |
def defaultTestResult(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
could not get to source file
def fail(self, msg=None):
Fail immediately, with the given message.
arguments:
- self: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failIf(self, expr, msg=None):
Fail the test if the expression is true.
arguments:
- self: <UNKNOWN>
- expr: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failIfAlmostEqual(self, first, second, places=7, msg=None):
Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- places: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failIfEqual(self, first, second, msg=None):
Fail if the two objects are equal as determined by the '=='
operator.
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnless(self, expr, msg=None):
Fail the test unless the expression is true.
arguments:
- self: <UNKNOWN>
- expr: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnlessAlmostEqual(self, first, second, places=7, msg=None):
Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- places: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnlessEqual(self, first, second, msg=None):
Fail if the two objects are unequal as determined by the '=='
operator.
arguments:
- self: <UNKNOWN>
- first: <UNKNOWN>
- second: <UNKNOWN>
- msg: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def failUnlessRaises(self, excClass, callableObj, *args, **kwargs):
Fail unless an exception of class excClass is thrown
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
thrown, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
arguments:
- self: <UNKNOWN>
- excClass: <UNKNOWN>
- callableObj: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def format_failure(self, err):
def id(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
def run(self, result=None):
*no docstring available*
arguments:
- self: <UNKNOWN>
- result: <UNKNOWN>
return value:
<UNKNOWN>
could not get to source file
def runTest(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
source: compat/doctest.py
2136 |
2137 |
2138 |
2139 |
2140 |
2141 |
2142 |
2143 |
2144 |
2145 |
2146 |
2147 |
2148 |
2149 |
2150 |
2151 |
2152 |
2153 |
2154 |
2155 |
2156 |
2157 |
2158 | |
def runTest(self): |
test = self._dt_test |
old = sys.stdout |
new = StringIO() |
optionflags = self._dt_optionflags |
|
if not (optionflags & REPORTING_FLAGS): |
|
|
optionflags |= _unittest_reportflags |
|
runner = DocTestRunner(optionflags=optionflags, |
checker=self._dt_checker, verbose=False) |
|
try: |
runner.DIVIDER = "-"*70 |
failures, tries = runner.run( |
test, out=new.write, clear_globs=False) |
finally: |
sys.stdout = old |
|
if failures: |
raise self.failureException(self.format_failure(new.getvalue())) | |
def setUp(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
def shortDescription(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
def tearDown(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
source: compat/doctest.py
2128 |
2129 |
2130 |
2131 |
2132 |
2133 |
2134 | |
def tearDown(self): |
test = self._dt_test |
|
if self._dt_tearDown is not None: |
self._dt_tearDown(test) |
|
test.globs.clear() | |
def __call__(self, *args, **kwds):
*no docstring available*
arguments:
return value:
<UNKNOWN>
could not get to source file
def __repr__(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
source: compat/doctest.py
|
def __repr__(self): |
name = self._dt_test.name.split('.') |
return "%s (%s)" % (name[-1], '.'.join(name[:-1])) | |
def __repr__(self):
*no docstring available*
arguments:
return value:
<UNKNOWN>
source: compat/doctest.py
|
def __repr__(self): |
name = self._dt_test.name.split('.') |
return "%s (%s)" % (name[-1], '.'.join(name[:-1])) | |