[Python-checkins]
python/dist/src/Lib/test test_doctest.py, 1.5.18.6, 1.5.18.7
edloper at users.sourceforge.net
edloper at users.sourceforge.net
Tue Aug 3 22:13:15 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2128/test
Modified Files:
Tag: tim-doctest-branch
test_doctest.py
Log Message:
- Added sample objects, defined in the module, that can be used by
test cases.
- Removed line numbers from test cases (they change too easily)
- Explicitly set verbose=False when running test cases for DocTestRunner
(so that it doesn't pick up the verbosity from sys.argv)
- Added a couple tests for the debugger
- Added support for computing coverage
Index: test_doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_doctest.py,v
retrieving revision 1.5.18.6
retrieving revision 1.5.18.7
diff -C2 -d -r1.5.18.6 -r1.5.18.7
*** test_doctest.py 3 Aug 2004 19:52:49 -0000 1.5.18.6
--- test_doctest.py 3 Aug 2004 20:13:12 -0000 1.5.18.7
***************
*** 6,9 ****
--- 6,119 ----
import doctest
+ ######################################################################
+ ## Sample Objects (used by test cases)
+ ######################################################################
+
+ def sample_func(v):
+ """
+ >>> print sample_func(22)
+ 44
+ """
+ return v+v
+
+ class SampleClass:
+ """
+ >>> print 1
+ 1
+ """
+ def __init__(self, val):
+ """
+ >>> print SampleClass(12).get()
+ 12
+ """
+ self.val = val
+
+ def double(self):
+ """
+ >>> print SampleClass(12).double().get()
+ 24
+ """
+ return SampleClass(self.val + self.val)
+
+ def get(self):
+ """
+ >>> print SampleClass(-5).get()
+ -5
+ """
+ return self.val
+
+ def a_staticmethod(v):
+ """
+ >>> print SampleClass.a_staticmethod(10)
+ 11
+ """
+ return v+1
+ a_staticmethod = staticmethod(a_staticmethod)
+
+ def a_classmethod(cls, v):
+ """
+ >>> print SampleClass.a_classmethod(10)
+ 12
+ >>> print SampleClass(0).a_classmethod(10)
+ 12
+ """
+ return v+2
+ a_classmethod = classmethod(a_classmethod)
+
+ a_property = property(get, doc="""
+ >>> print SampleClass(22).a_property
+ 22
+ """)
+
+ class NestedClass:
+ """
+ >>> x = SampleClass.NestedClass(5)
+ >>> y = x.square()
+ >>> print y.get()
+ 25
+ """
+ def __init__(self, val=0):
+ """
+ >>> print SampleClass.NestedClass().get()
+ 0
+ """
+ self.val = val
+ def square(self):
+ return SampleClass.NestedClass(self.val*self.val)
+ def get(self):
+ return self.val
+
+ class SampleNewStyleClass(object):
+ r"""
+ >>> print '1\n2\n3'
+ 1
+ 2
+ 3
+ """
+ def __init__(self, val):
+ """
+ >>> print SampleNewStyleClass(12).get()
+ 12
+ """
+ self.val = val
+
+ def double(self):
+ """
+ >>> print SampleNewStyleClass(12).double().get()
+ 24
+ """
+ return SampleNewStyleClass(self.val + self.val)
+
+ def get(self):
+ """
+ >>> print SampleNewStyleClass(-5).get()
+ -5
+ """
+ return self.val
+
+ ######################################################################
+ ## Test Cases
+ ######################################################################
+
def test_Example(): r"""
Unit tests for the `Example` class.
***************
*** 118,121 ****
--- 228,232 ----
"""
+ # [XX] test that it's getting line numbers right.
def test_DocTestFinder(): r"""
Unit tests for the `DocTestFinder` class.
***************
*** 131,149 ****
will return a single test (for that function's docstring):
! >>> # Functions:
! >>> def double(v):
! ... '''
! ... >>> print double(22)
! ... 44
! ... '''
! ... return v+v
>>> finder = doctest.DocTestFinder()
! >>> tests = finder.find(double)
>>> print tests
! [<DocTest double from None:1 (1 example)>]
>>> e = tests[0].examples[0]
>>> print (e.source, e.want, e.lineno)
! ('print double(22)', '44\n', 1)
If an object has no docstring, then a test is not created for it:
--- 242,258 ----
will return a single test (for that function's docstring):
! >>> # Allow ellipsis in the following examples (since the filename
! >>> # and line number in the traceback can vary):
! >>> doctest: +ELLIPSIS
>>> finder = doctest.DocTestFinder()
! >>> tests = finder.find(sample_func)
>>> print tests
! [<DocTest sample_func from ...:12 (1 example)>]
>>> e = tests[0].examples[0]
>>> print (e.source, e.want, e.lineno)
! ('print sample_func(22)', '44\n', 1)
!
! >>> doctest: -ELLIPSIS # Turn ellipsis back off
If an object has no docstring, then a test is not created for it:
***************
*** 170,292 ****
methods, classmethods, staticmethods, properties, and nested classes.
- >>> # A class:
- >>> class A:
- ... '''
- ... >>> print 1
- ... 1
- ... '''
- ... def __init__(self, val):
- ... '''
- ... >>> print A(12).get()
- ... 12
- ... '''
- ... self.val = val
- ...
- ... def double(self):
- ... '''
- ... >>> print A(12).double().get()
- ... 24
- ... '''
- ... return A(self.val + self.val)
- ...
- ... def get(self):
- ... '''
- ... >>> print A(-5).get()
- ... -5
- ... '''
- ... return self.val
- ...
- ... def a_staticmethod(v):
- ... '''
- ... >>> print A.a_staticmethod(10)
- ... 11
- ... '''
- ... return v+1
- ... a_staticmethod = staticmethod(a_staticmethod)
- ...
- ... def a_classmethod(cls, v):
- ... '''
- ... >>> print A.a_classmethod(10)
- ... 12
- ... >>> print A(0).a_classmethod(10)
- ... 12
- ... '''
- ... return v+2
- ... a_classmethod = classmethod(a_classmethod)
- ...
- ... a_property = property(get, doc='''
- ... >>> print x(22).a_property
- ... 22
- ... ''')
- ...
- ... class NestedClass:
- ... '''
- ... >>> x = A.NestedClass(5)
- ... >>> y = x.square()
- ... >>> print y.get()
- ... 25
- ... '''
- ... def __init__(self, val=0):
- ... '''
- ... >>> print A.NestedClass().get()
- ... 0
- ... '''
- ... self.val = val
- ... def square(self):
- ... A.NestedClass(self.val*self.val)
- ... def get(self):
- ... return self.val
-
>>> finder = doctest.DocTestFinder()
! >>> tests = finder.find(A)
>>> tests.sort()
>>> for t in tests:
! ... print '%4s %2s %s' % (t.lineno, len(t.examples), t.name)
! None 1 A
! None 3 A.NestedClass
! 96 1 A.NestedClass.__init__
! 7 1 A.__init__
! 40 2 A.a_classmethod
! None 1 A.a_property
! 40 1 A.a_staticmethod
! 40 1 A.double
! 40 1 A.get
New-style classes are also supported:
! >>> class B(object):
! ... '''
! ... >>> print 1
! ... 1
! ... '''
! ... def __init__(self, val):
! ... '''
! ... >>> print B(12).get()
! ... 12
! ... '''
! ... self.val = val
! ...
! ... def double(self):
! ... '''
! ... >>> print B(12).double().get()
! ... 24
! ... '''
! ... return B(self.val + self.val)
! ...
! ... def get(self):
! ... '''
! ... >>> print B(-5).get()
! ... -5
! ... '''
! ... return self.val
!
! >>> tests = finder.find(B)
>>> tests.sort()
>>> for t in tests:
! ... print '%4s %2s %s' % (t.lineno, len(t.examples), t.name)
! None 1 B
! 7 1 B.__init__
! 40 1 B.double
! 40 1 B.get
Finding Tests in Modules
--- 279,307 ----
methods, classmethods, staticmethods, properties, and nested classes.
>>> finder = doctest.DocTestFinder()
! >>> tests = finder.find(SampleClass)
>>> tests.sort()
>>> for t in tests:
! ... print '%2s %s' % (len(t.examples), t.name)
! 1 SampleClass
! 3 SampleClass.NestedClass
! 1 SampleClass.NestedClass.__init__
! 1 SampleClass.__init__
! 2 SampleClass.a_classmethod
! 1 SampleClass.a_property
! 1 SampleClass.a_staticmethod
! 1 SampleClass.double
! 1 SampleClass.get
New-style classes are also supported:
! >>> tests = finder.find(SampleNewStyleClass)
>>> tests.sort()
>>> for t in tests:
! ... print '%2s %s' % (len(t.examples), t.name)
! 1 SampleNewStyleClass
! 1 SampleNewStyleClass.__init__
! 1 SampleNewStyleClass.double
! 1 SampleNewStyleClass.get
Finding Tests in Modules
***************
*** 306,311 ****
... return val*3
>>> m.__dict__.update({
! ... 'double': double,
! ... 'A': A,
... '__doc__': '''
... Module docstring.
--- 321,326 ----
... return val*3
>>> m.__dict__.update({
! ... 'sample_func': sample_func,
! ... 'SampleClass': SampleClass,
... '__doc__': '''
... Module docstring.
***************
*** 318,340 ****
>>> finder = doctest.DocTestFinder()
! >>> # The '(None)' is to prevent it from filtering out objects
! >>> # that were not defined in module m.
! >>> tests = finder.find(m, module='(None)')
>>> tests.sort()
>>> for t in tests:
! ... print '%4s %2s %s' % (t.lineno, len(t.examples), t.name)
! 1 1 some_module
! None 1 some_module.A
! None 3 some_module.A.NestedClass
! 57 1 some_module.A.NestedClass.__init__
! 6 1 some_module.A.__init__
! 35 2 some_module.A.a_classmethod
! None 1 some_module.A.a_property
! 27 1 some_module.A.a_staticmethod
! 13 1 some_module.A.double
! 20 1 some_module.A.get
! 1 1 some_module.c
! None 2 some_module.d
! 1 1 some_module.double
Duplicate Removal
--- 333,356 ----
>>> finder = doctest.DocTestFinder()
! >>> # Use module=test.test_doctest, to prevent doctest from
! >>> # ignoring the objects since they weren't defined in m.
! >>> import test.test_doctest
! >>> tests = finder.find(m, module=test.test_doctest)
>>> tests.sort()
>>> for t in tests:
! ... print '%2s %s' % (len(t.examples), t.name)
! 1 some_module
! 1 some_module.SampleClass
! 3 some_module.SampleClass.NestedClass
! 1 some_module.SampleClass.NestedClass.__init__
! 1 some_module.SampleClass.__init__
! 2 some_module.SampleClass.a_classmethod
! 1 some_module.SampleClass.a_property
! 1 some_module.SampleClass.a_staticmethod
! 1 some_module.SampleClass.double
! 1 some_module.SampleClass.get
! 1 some_module.c
! 2 some_module.d
! 1 some_module.sample_func
Duplicate Removal
***************
*** 372,399 ****
>>> def namefilter(prefix, base):
... return base.startswith('a_')
! >>> tests = doctest.DocTestFinder(namefilter=namefilter).find(A)
>>> tests.sort()
>>> for t in tests:
! ... print '%4s %2s %s' % (t.lineno, len(t.examples), t.name)
! None 1 A
! None 3 A.NestedClass
! 96 1 A.NestedClass.__init__
! 7 1 A.__init__
! 40 1 A.double
! 40 1 A.get
>>> def objfilter(obj):
... return isinstance(obj, (staticmethod, classmethod))
! >>> tests = doctest.DocTestFinder(objfilter=objfilter).find(A)
>>> tests.sort()
>>> for t in tests:
! ... print '%4s %2s %s' % (t.lineno, len(t.examples), t.name)
! None 1 A
! None 3 A.NestedClass
! 96 1 A.NestedClass.__init__
! 7 1 A.__init__
! None 1 A.a_property
! 40 1 A.double
! 40 1 A.get
If a given object is filtered out, then none of the objects that it
--- 388,415 ----
>>> def namefilter(prefix, base):
... return base.startswith('a_')
! >>> tests = doctest.DocTestFinder(namefilter=namefilter).find(SampleClass)
>>> tests.sort()
>>> for t in tests:
! ... print '%2s %s' % (len(t.examples), t.name)
! 1 SampleClass
! 3 SampleClass.NestedClass
! 1 SampleClass.NestedClass.__init__
! 1 SampleClass.__init__
! 1 SampleClass.double
! 1 SampleClass.get
>>> def objfilter(obj):
... return isinstance(obj, (staticmethod, classmethod))
! >>> tests = doctest.DocTestFinder(objfilter=objfilter).find(SampleClass)
>>> tests.sort()
>>> for t in tests:
! ... print '%2s %s' % (len(t.examples), t.name)
! 1 SampleClass
! 3 SampleClass.NestedClass
! 1 SampleClass.NestedClass.__init__
! 1 SampleClass.__init__
! 1 SampleClass.a_property
! 1 SampleClass.double
! 1 SampleClass.get
If a given object is filtered out, then none of the objects that it
***************
*** 402,416 ****
>>> def namefilter(prefix, base):
... return base == 'NestedClass'
! >>> tests = doctest.DocTestFinder(namefilter=namefilter).find(A)
>>> tests.sort()
>>> for t in tests:
! ... print '%4s %2s %s' % (t.lineno, len(t.examples), t.name)
! None 1 A
! 7 1 A.__init__
! 40 2 A.a_classmethod
! None 1 A.a_property
! 40 1 A.a_staticmethod
! 40 1 A.double
! 40 1 A.get
The filter functions apply to contained objects, and *not* to the
--- 418,432 ----
>>> def namefilter(prefix, base):
... return base == 'NestedClass'
! >>> tests = doctest.DocTestFinder(namefilter=namefilter).find(SampleClass)
>>> tests.sort()
>>> for t in tests:
! ... print '%2s %s' % (len(t.examples), t.name)
! 1 SampleClass
! 1 SampleClass.__init__
! 2 SampleClass.a_classmethod
! 1 SampleClass.a_property
! 1 SampleClass.a_staticmethod
! 1 SampleClass.double
! 1 SampleClass.get
The filter functions apply to contained objects, and *not* to the
***************
*** 418,423 ****
>>> def namefilter(prefix, base):
! ... return base == 'A'
! >>> tests = doctest.DocTestFinder(namefilter=namefilter).find(A)
>>> len(tests)
9
--- 434,439 ----
>>> def namefilter(prefix, base):
! ... return base == 'SampleClass'
! >>> tests = doctest.DocTestFinder(namefilter=namefilter).find(SampleClass)
>>> len(tests)
9
***************
*** 428,436 ****
using the `recurse` flag:
! >>> tests = doctest.DocTestFinder(recurse=False).find(A)
>>> tests.sort()
>>> for t in tests:
! ... print '%4s %2s %s' % (t.lineno, len(t.examples), t.name)
! None 1 A
"""
--- 444,452 ----
using the `recurse` flag:
! >>> tests = doctest.DocTestFinder(recurse=False).find(SampleClass)
>>> tests.sort()
>>> for t in tests:
! ... print '%2s %s' % (len(t.examples), t.name)
! 1 SampleClass
"""
***************
*** 457,476 ****
of tried tests.
! >>> doctest.DocTestRunner().run(test, {})
! (0, 3)
!
! The `verbose` flag makes the test runner generate more detailed
! output:
!
! >>> doctest.DocTestRunner(verbose=True).run(test, {})
! Trying: x = 12
! Expecting: nothing
! ok
! Trying: print x
! Expecting: 12
! ok
! Trying: x/2
! Expecting: 6
! ok
(0, 3)
--- 473,477 ----
of tried tests.
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
(0, 3)
***************
*** 503,506 ****
--- 504,564 ----
(1, 3)
"""
+ def verbose_flag(): r"""
+ The `verbose` flag makes the test runner generate more detailed
+ output:
+
+ >>> def f(x):
+ ... '''
+ ... >>> x = 12
+ ... >>> print x
+ ... 12
+ ... >>> x/2
+ ... 6
+ ... '''
+ >>> test = doctest.DocTestFinder().find(f)[0]
+
+ >>> doctest.DocTestRunner(verbose=True).run(test, {})
+ Trying: x = 12
+ Expecting: nothing
+ ok
+ Trying: print x
+ Expecting: 12
+ ok
+ Trying: x/2
+ Expecting: 6
+ ok
+ (0, 3)
+
+ If the `verbose` flag is unspecified, then the output will be verbose
+ iff `-v` appears in sys.argv:
+
+ >>> # Save the real sys.argv list.
+ >>> old_argv = sys.argv
+
+ >>> # If -v does not appear in sys.argv, then output isn't verbose.
+ >>> sys.argv = ['test']
+ >>> doctest.DocTestRunner().run(test, {})
+ (0, 3)
+
+ >>> # If -v does appear in sys.argv, then output is verbose.
+ >>> sys.argv = ['test', '-v']
+ >>> doctest.DocTestRunner().run(test, {})
+ Trying: x = 12
+ Expecting: nothing
+ ok
+ Trying: print x
+ Expecting: 12
+ ok
+ Trying: x/2
+ Expecting: 6
+ ok
+ (0, 3)
+
+ >>> # Restore sys.argv
+ >>> sys.argv = old_argv
+
+ In the remaining examples, the test runner's verbosity will be
+ explicitly set, to ensure that the test behavior is consistent.
+ """
def exceptions(): r"""
Tests of `DocTestRunner`'s exception handling.
***************
*** 518,522 ****
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
(0, 2)
--- 576,580 ----
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
(0, 2)
***************
*** 533,537 ****
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
(0, 2)
--- 591,595 ----
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
(0, 2)
***************
*** 547,551 ****
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
(0, 1)
--- 605,609 ----
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
(0, 1)
***************
*** 560,564 ****
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
**********************************************************************
Failure in example: raise ValueError, 'message'
--- 618,622 ----
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
**********************************************************************
Failure in example: raise ValueError, 'message'
***************
*** 585,589 ****
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
**********************************************************************
Failure in example: 1/0
--- 643,647 ----
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
**********************************************************************
Failure in example: 1/0
***************
*** 597,602 ****
(1, 1)
! >>> # Turn ellipsis back off:
! >>> doctest: -ELLIPSIS
"""
def optionflags(): r"""
--- 655,659 ----
(1, 1)
! >>> doctest: -ELLIPSIS # Turn ellipsis back off:
"""
def optionflags(): r"""
***************
*** 616,620 ****
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
(0, 1)
--- 673,677 ----
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
(0, 1)
***************
*** 622,626 ****
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.DONT_ACCEPT_TRUE_FOR_1
! >>> doctest.DocTestRunner(optionflags=flags).run(test, {})
**********************************************************************
Failure in example: True
--- 679,683 ----
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.DONT_ACCEPT_TRUE_FOR_1
! >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test, {})
**********************************************************************
Failure in example: True
***************
*** 638,642 ****
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
(0, 1)
--- 695,699 ----
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
(0, 1)
***************
*** 644,648 ****
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.DONT_ACCEPT_BLANKLINE
! >>> doctest.DocTestRunner(optionflags=flags).run(test, {})
**********************************************************************
Failure in example: print "a\n\nb"
--- 701,705 ----
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.DONT_ACCEPT_BLANKLINE
! >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test, {})
**********************************************************************
Failure in example: print "a\n\nb"
***************
*** 666,670 ****
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
**********************************************************************
Failure in example: print 1, 2, 3
--- 723,727 ----
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
**********************************************************************
Failure in example: print 1, 2, 3
***************
*** 679,683 ****
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.NORMALIZE_WHITESPACE
! >>> doctest.DocTestRunner(optionflags=flags).run(test, {})
(0, 1)
--- 736,740 ----
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.NORMALIZE_WHITESPACE
! >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test, {})
(0, 1)
***************
*** 690,694 ****
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
**********************************************************************
Failure in example: print range(15)
--- 747,751 ----
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
**********************************************************************
Failure in example: print range(15)
***************
*** 701,705 ****
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.ELLIPSIS
! >>> doctest.DocTestRunner(optionflags=flags).run(test, {})
(0, 1)
--- 758,762 ----
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.ELLIPSIS
! >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test, {})
(0, 1)
***************
*** 721,725 ****
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
**********************************************************************
Failure in example: print '\n'.join('abcdefg')
--- 778,782 ----
>>> # Without the flag:
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
**********************************************************************
Failure in example: print '\n'.join('abcdefg')
***************
*** 746,750 ****
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.UNIFIED_DIFF
! >>> doctest.DocTestRunner(optionflags=flags).run(test, {})
**********************************************************************
Failure in example: print '\n'.join('abcdefg')
--- 803,807 ----
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.UNIFIED_DIFF
! >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test, {})
**********************************************************************
Failure in example: print '\n'.join('abcdefg')
***************
*** 772,776 ****
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.CONTEXT_DIFF
! >>> doctest.DocTestRunner(optionflags=flags).run(test, {})
**********************************************************************
Failure in example: print '\n'.join('abcdefg')
--- 829,833 ----
>>> test = doctest.DocTestFinder().find(f)[0]
>>> flags = doctest.CONTEXT_DIFF
! >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test, {})
**********************************************************************
Failure in example: print '\n'.join('abcdefg')
***************
*** 800,804 ****
(1, 1)
"""
-
def option_directives(): r"""
Tests of `DocTestRunner`'s option directive mechanism.
--- 857,860 ----
***************
*** 822,826 ****
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
**********************************************************************
Failure in example: print range(10) # Should fail: no ellipsis
--- 878,882 ----
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
**********************************************************************
Failure in example: print range(10) # Should fail: no ellipsis
***************
*** 845,849 ****
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner().run(test, {})
**********************************************************************
Failure in example: print range(10) # Should fail
--- 901,905 ----
... '''
>>> test = doctest.DocTestFinder().find(f)[0]
! >>> doctest.DocTestRunner(verbose=False).run(test, {})
**********************************************************************
Failure in example: print range(10) # Should fail
***************
*** 852,865 ****
Got: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
(1, 2)
"""
def test_main():
# Check the doctest cases in doctest itself:
! #test_support.run_doctest(doctest)
# Check the doctest cases defined here:
from test import test_doctest
! test_support.run_doctest(test_doctest, verbosity=0)
if __name__ == '__main__':
! test_main()
--- 908,999 ----
Got: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
(1, 2)
+ """
+ def test_testsource(): r"""
+ >>> import test.test_doctest
+ >>> name = 'test.test_doctest.sample_func'
+ >>> print doctest.testsource(test.test_doctest, name)
+ print sample_func(22)
+ # Expected:
+ # 44
+
+ >>> name = 'test.test_doctest.SampleNewStyleClass'
+ >>> print doctest.testsource(test.test_doctest, name)
+ print '1\n2\n3'
+ # Expected:
+ # 1
+ # 2
+ # 3
+
+ >>> name = 'test.test_doctest.SampleClass.a_classmethod'
+ >>> print doctest.testsource(test.test_doctest, name)
+ print SampleClass.a_classmethod(10)
+ # Expected:
+ # 12
+ print SampleClass(0).a_classmethod(10)
+ # Expected:
+ # 12
"""
+ def test_debug(): r"""
+
+ Create a docstring that we want to debug:
+
+ >>> s = '''
+ ... >>> x = 12
+ ... >>> print x
+ ... 12
+ ... '''
+
+ Create some fake stdin input, to feed to the debugger:
+
+ >>> import tempfile
+ >>> fake_stdin = tempfile.TemporaryFile(mode='w+')
+ >>> fake_stdin.write('\n'.join(['next', 'print x', 'continue', '']))
+ >>> fake_stdin.seek(0)
+ >>> real_stdin = sys.stdin
+ >>> sys.stdin = fake_stdin
+
+ Run the debugger on the docstring, and then restore sys.stdin.
+
+ >>> doctest: +NORMALIZE_WHITESPACE
+ >>> try:
+ ... doctest.debug_src(s)
+ ... finally:
+ ... sys.stdin = real_stdin
+ ... fake_stdin.close()
+ > <string>(1)?()
+ (Pdb) 12
+ --Return--
+ > <string>(1)?()->None
+ (Pdb) 12
+ (Pdb)
+
+ """
+
+ ######################################################################
+ ## Main
+ ######################################################################
+
def test_main():
# Check the doctest cases in doctest itself:
! test_support.run_doctest(doctest, verbosity=True)
# Check the doctest cases defined here:
from test import test_doctest
! test_support.run_doctest(test_doctest, verbosity=True)
!
! import trace, sys, re, StringIO
! def test_coverage(coverdir):
! tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,],
! trace=0, count=1)
! tracer.run('reload(doctest); test_main()')
! r = tracer.results()
! print 'Writing coverage results...'
! r.write_results(show_missing=True, summary=True,
! coverdir=coverdir)
if __name__ == '__main__':
! if '-c' in sys.argv:
! test_coverage('/tmp/doctest.cover')
! else:
! test_main()
More information about the Python-checkins
mailing list