summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_doctest.py
diff options
context:
space:
mode:
authorEdward Loper <edloper@gradient.cis.upenn.edu>2004-08-17 16:37:12 (GMT)
committerEdward Loper <edloper@gradient.cis.upenn.edu>2004-08-17 16:37:12 (GMT)
commitb51b23405b6cf82ab4ec20f3d5ef4b895bd0786f (patch)
tree69730ef8142ad40994b77bb1ac4524c318219150 /Lib/test/test_doctest.py
parentf04d8a88989f04b8ccb7ca4992190d0eff4352a1 (diff)
downloadcpython-b51b23405b6cf82ab4ec20f3d5ef4b895bd0786f.zip
cpython-b51b23405b6cf82ab4ec20f3d5ef4b895bd0786f.tar.gz
cpython-b51b23405b6cf82ab4ec20f3d5ef4b895bd0786f.tar.bz2
Fixed bug in line-number finding for examples (DocTestParser wasn't
updating line numbers correctly for bare prompts & examples containing only comments).
Diffstat (limited to 'Lib/test/test_doctest.py')
-rw-r--r--Lib/test/test_doctest.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 8e651d0..dec9110 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -253,7 +253,6 @@ will raise a ValueError:
"""
-# [XX] test that it's getting line numbers right.
def test_DocTestFinder(): r"""
Unit tests for the `DocTestFinder` class.
@@ -450,6 +449,30 @@ using the `recurse` flag:
>>> for t in tests:
... print '%2s %s' % (len(t.examples), t.name)
1 SampleClass
+
+Line numbers
+~~~~~~~~~~~~
+DocTestFinder finds the line number of each example:
+
+ >>> def f(x):
+ ... '''
+ ... >>> x = 12
+ ...
+ ... some text
+ ...
+ ... >>> # examples are not created for comments & bare prompts.
+ ... >>>
+ ... ...
+ ...
+ ... >>> for x in range(10):
+ ... ... print x,
+ ... 0 1 2 3 4 5 6 7 8 9
+ ... >>> x/2
+ ... 6
+ ... '''
+ >>> test = doctest.DocTestFinder().find(f)[0]
+ >>> [e.lineno for e in test.examples]
+ [1, 9, 12]
"""
class test_DocTestRunner:
@@ -892,7 +915,7 @@ comment of the form ``# doctest: -OPTION``:
... optionflags=doctest.ELLIPSIS).run(test)
**********************************************************************
Failure in example: print range(10) # doctest: -ELLIPSIS
- from line #6 of f
+ from line #5 of f
Expected: [0, 1, ..., 9]
Got: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
(1, 2)