[Python-checkins] python/dist/src/Lib doctest.py, 1.36.2.22,
1.36.2.23
dcjim at users.sourceforge.net
dcjim at users.sourceforge.net
Fri Aug 6 16:32:53 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6902
Modified Files:
Tag: tim-doctest-branch
doctest.py
Log Message:
Shortened some class names.
Added a test for the DocTestCase debug method, and debugged the
resulting failure. :)
Also changed the signature to DocTestCase.__init__ so it accepts
optionflags rather than a runner.
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.36.2.22
retrieving revision 1.36.2.23
diff -C2 -d -r1.36.2.22 -r1.36.2.23
*** doctest.py 6 Aug 2004 06:30:21 -0000 1.36.2.22
--- doctest.py 6 Aug 2004 14:32:50 -0000 1.36.2.23
***************
*** 297,301 ****
'run_docstring_examples',
'Tester',
! 'DocTestTestCase',
'DocTestSuite',
'testsource',
--- 297,301 ----
'run_docstring_examples',
'Tester',
! 'DocTestCase',
'DocTestSuite',
'testsource',
***************
*** 1601,1610 ****
If the output doesn't match, then a DocTestFailure is raised:
! >>> try:
! ... test = DocTest('''
... >>> x = 1
... >>> x
... 2
... ''', {}, 'foo', 'foo.py', 0)
... runner.run(test)
... except DocTestFailure, failure:
--- 1601,1611 ----
If the output doesn't match, then a DocTestFailure is raised:
! >>> test = DocTest('''
... >>> x = 1
... >>> x
... 2
... ''', {}, 'foo', 'foo.py', 0)
+
+ >>> try:
... runner.run(test)
... except DocTestFailure, failure:
***************
*** 1865,1892 ****
######################################################################
! class DocTestTestCase(unittest.TestCase):
! """A test case that wraps a test function.
!
! This is useful for slipping pre-existing test functions into the
! PyUnit framework. Optionally, set-up and tidy-up functions can be
! supplied. As with TestCase, the tidy-up ('tearDown') function will
! always be called if the set-up ('setUp') function ran successfully.
! """
! def __init__(self, test_runner, test,
! setUp=None, tearDown=None):
unittest.TestCase.__init__(self)
! self.__test_runner = test_runner
self._dt_test = test
! self.__setUp = setUp
! self.__tearDown = tearDown
def setUp(self):
! if self.__setUp is not None:
! self.__setUp()
def tearDown(self):
! if self.__tearDown is not None:
! self.__tearDown()
def runTest(self):
--- 1866,1885 ----
######################################################################
! class DocTestCase(unittest.TestCase):
! def __init__(self, test, optionflags=0, setUp=None, tearDown=None):
unittest.TestCase.__init__(self)
! self._dt_optionflags = optionflags
self._dt_test = test
! self._dt_setUp = setUp
! self._dt_tearDown = tearDown
def setUp(self):
! if self._dt_setUp is not None:
! self._dt_setUp()
def tearDown(self):
! if self._dt_tearDown is not None:
! self._dt_tearDown()
def runTest(self):
***************
*** 1894,1900 ****
old = sys.stdout
new = StringIO()
try:
! self.__test_runner.DIVIDER = "-"*70
! failures, tries = self.__test_runner.run(test, out=new.write)
finally:
sys.stdout = old
--- 1887,1895 ----
old = sys.stdout
new = StringIO()
+ runner = DocTestRunner(optionflags=self._dt_optionflags, verbose=False)
+
try:
! runner.DIVIDER = "-"*70
! failures, tries = runner.run(test, out=new.write)
finally:
sys.stdout = old
***************
*** 1916,1922 ****
def debug(self):
! runner = DebugRunner(verbose=False,
! optionflags=self.__test_runner.optionflags)
! runner.run(self._dt_test, nooutput)
def id(self):
--- 1911,1961 ----
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:
!
! >>> test = DocTest('>>> raise KeyError', {}, 'foo', 'foo.py', 0)
! >>> case = DocTestCase(test)
! >>> case.debug()
! Traceback (most recent call last):
! ...
! KeyError
!
! If the output doesn't match, then a DocTestFailure is raised:
!
! >>> test = 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'
!
! """
!
! runner = DebugRunner(verbose = False, optionflags=self._dt_optionflags)
! runner.run(self._dt_test, out=nooutput)
def id(self):
***************
*** 1955,1959 ****
if test_finder is None:
test_finder = DocTestFinder()
- test_runner = DocTestRunner(optionflags=optionflags, verbose=False)
module = _normalize_module(module)
--- 1994,1997 ----
***************
*** 1976,1985 ****
filename = filename[:-1]
test.filename = filename
! suite.addTest(DocTestTestCase(test_runner, test,
! setUp, tearDown))
return suite
! class DocTestFileTestCase(DocTestTestCase):
def id(self):
--- 2014,2022 ----
filename = filename[:-1]
test.filename = filename
! suite.addTest(DocTestCase(test, optionflags, setUp, tearDown))
return suite
! class DocFileCase(DocTestCase):
def id(self):
***************
*** 2007,2014 ****
globs = {}
- test_runner = DocTestRunner(optionflags=optionflags, verbose=False)
test = DocTest(doc, globs, name, path, 0)
!
! return DocTestFileTestCase(test_runner, test, setUp, tearDown)
def DocFileSuite(*paths, **kw):
--- 2044,2050 ----
globs = {}
test = DocTest(doc, globs, name, path, 0)
!
! return DocFileCase(test, optionflags, setUp, tearDown)
def DocFileSuite(*paths, **kw):
More information about the Python-checkins
mailing list