[Zope3-checkins] SVN: zope.testing/trunk/ Filenames of doctest examples now contain the line number and not only the example number. So a stack trace in pdb tells the exact line number of the current example. This fixes https://bugs.launchpad.net/bugs/339813
Michael Howitz
mh at gocept.com
Sat Apr 25 11:16:38 EDT 2009
Log message for revision 99488:
Filenames of doctest examples now contain the line number and not only the example number. So a stack trace in pdb tells the exact line number of the current example. This fixes https://bugs.launchpad.net/bugs/339813
Changed:
U zope.testing/trunk/CHANGES.txt
U zope.testing/trunk/src/zope/testing/doctest.py
U zope.testing/trunk/src/zope/testing/testrunner/testrunner-colors.txt
U zope.testing/trunk/src/zope/testing/testrunner/testrunner-edge-cases.txt
U zope.testing/trunk/src/zope/testing/testrunner/testrunner-errors.txt
-=-
Modified: zope.testing/trunk/CHANGES.txt
===================================================================
--- zope.testing/trunk/CHANGES.txt 2009-04-25 13:27:01 UTC (rev 99487)
+++ zope.testing/trunk/CHANGES.txt 2009-04-25 15:16:37 UTC (rev 99488)
@@ -4,8 +4,12 @@
3.7.4 (unreleased)
==================
-- ...
+- Filenames of doctest examples now contain the line number and not
+ only the example number. So a stack trace in pdb tells the exact
+ line number of the current example. This fixes
+ https://bugs.launchpad.net/bugs/339813
+
3.7.3 (2009-04-22)
==================
Modified: zope.testing/trunk/src/zope/testing/doctest.py
===================================================================
--- zope.testing/trunk/src/zope/testing/doctest.py 2009-04-25 13:27:01 UTC (rev 99487)
+++ zope.testing/trunk/src/zope/testing/doctest.py 2009-04-25 15:16:37 UTC (rev 99488)
@@ -357,7 +357,7 @@
try:
pdb.Pdb.__init__(self, stdin=sys.stdin, stdout=out)
except TypeError:
- pdb.Pdb.__init__(self)
+ pdb.Pdb.__init__(self)
def set_trace(self):
self.__debugger_used = True
@@ -1345,7 +1345,10 @@
# Use a special filename for compile(), so we can retrieve
# the source code during interactive debugging (see
# __patched_linecache_getlines).
- filename = '<doctest %s[%d]>' % (test.name, examplenum)
+ # Line number counting starts with 0 so we add one to get
+ # the real line number.
+ filename = '<doctest %s[line %d, example %d]>' % (
+ test.name, example.lineno+1, examplenum)
# Run the example in the given context (globs), and record
# any exception that gets raised. (But don't intercept
@@ -1428,9 +1431,10 @@
self.failures += f
self.tries += t
- __LINECACHE_FILENAME_RE = re.compile(r'<doctest '
- r'(?P<name>[\w\.]+)'
- r'\[(?P<examplenum>\d+)\]>$')
+ __LINECACHE_FILENAME_RE = re.compile(
+ r'<doctest (?P<name>[\w\.]+)\[line \d+, example (?P<examplenum>\d+)\]>$'
+ )
+
def __patched_linecache_getlines(self, filename, module_globals=None):
m = self.__LINECACHE_FILENAME_RE.match(filename)
if m and m.group('name') == self.test.name:
Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-colors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-colors.txt 2009-04-25 13:27:01 UTC (rev 99487)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-colors.txt 2009-04-25 15:16:37 UTC (rev 99488)
@@ -118,7 +118,7 @@
{red} Traceback (most recent call last):{normal}
{red} File ".../doctest.py", line 1356, in __run{normal}
{red} compileflags, 1) in test.globs{normal}
- {red} File "<doctest sample2.sampletests_e.eek[0]>", line 1, in ?{normal}
+ {red} File "<doctest sample2.sampletests_e.eek[line 2, example 0]>", line 1, in ?{normal}
{red} f(){normal}
{red} File "testrunner-ex/sample2/sampletests_e.py", line 19, in f{normal}
{red} g(){normal}
@@ -154,9 +154,9 @@
{red} Traceback (most recent call last):{normal}
{red} File ".../doctest.py", line 1356, in __run{normal}
{red} compileflags, 1) in test.globs{normal}
- {red} File "<doctest e.txt[1]>", line 1, in ?{normal}
+ {red} File "<doctest e.txt[line 4, example 1]>", line 1, in ?{normal}
{red} f(){normal}
- {red} File "<doctest e.txt[0]>", line 2, in f{normal}
+ {red} File "<doctest e.txt[line 1, example 0]>", line 2, in f{normal}
{red} return x{normal}
{red} NameError: global name 'x' is not defined{normal}
<BLANKLINE>
Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-edge-cases.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-edge-cases.txt 2009-04-25 13:27:01 UTC (rev 99487)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-edge-cases.txt 2009-04-25 15:16:37 UTC (rev 99488)
@@ -117,7 +117,7 @@
> doctest.py(351)set_trace()->None
-> pdb.Pdb.set_trace(self)
(Pdb) n
- > <doctest sample3.sampletests_d.set_trace3[1]>(3)...()
+ > <doctest sample3.sampletests_d.set_trace3[line 3, example 1]>(3)...()
-> y = x
(Pdb) p x
1
@@ -139,7 +139,7 @@
> doctest.py(351)set_trace()->None
-> pdb.Pdb.set_trace(self)
(Pdb) n
- > <doctest set_trace5.txt[1]>(3)...()
+ > <doctest set_trace5.txt[line 2, example 1]>(3)...()
-> y = x
(Pdb) p x
1
@@ -227,7 +227,7 @@
<BLANKLINE>
exceptions.ValueError:
<BLANKLINE>
- > <doctest sample3.sampletests_d.post_mortem3[1]>(1)...()
+ > <doctest sample3.sampletests_d.post_mortem3[line 3, example 1]>(1)...()
(Pdb) p x
1
(Pdb) c
@@ -292,7 +292,7 @@
<BLANKLINE>
exceptions.ValueError:
<BLANKLINE>
- > <doctest post_mortem5.txt[1]>(1)...()
+ > <doctest post_mortem5.txt[line 2, example 1]>(1)...()
(Pdb) p x
1
(Pdb) c
Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-errors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-errors.txt 2009-04-25 13:27:01 UTC (rev 99487)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-errors.txt 2009-04-25 15:16:37 UTC (rev 99488)
@@ -16,7 +16,7 @@
... for f in files:
... shutil.copy(os.path.join(root, f),
... os.path.join(directory_with_tests, root[n:], f))
-
+
>>> from zope.testing import testrunner
>>> defaults = [
... '--path', directory_with_tests,
@@ -44,7 +44,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_e.eek[0]>", line 1, in ?
+ File "<doctest sample2.sampletests_e.eek[line 2, example 0]>", line 1, in ?
f()
File "testrunner-ex/sample2/sampletests_e.py", line 19, in f
g()
@@ -78,9 +78,9 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest e.txt[1]>", line 1, in ?
+ File "<doctest e.txt[line 4, example 1]>", line 1, in ?
f()
- File "<doctest e.txt[0]>", line 2, in f
+ File "<doctest e.txt[line 1, example 0]>", line 2, in f
return x
NameError: global name 'x' is not defined
<BLANKLINE>
@@ -129,7 +129,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_e.eek[0]>", line 1, in ?
+ File "<doctest sample2.sampletests_e.eek[line 2, example 0]>", line 1, in ?
f()
File "testrunner-ex/sample2/sampletests_e.py", line 19, in f
g()
@@ -164,9 +164,9 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest e.txt[1]>", line 1, in ?
+ File "<doctest e.txt[line 4, example 1]>", line 1, in ?
f()
- File "<doctest e.txt[0]>", line 2, in f
+ File "<doctest e.txt[line 1, example 0]>", line 2, in f
return x
NameError: global name 'x' is not defined
<BLANKLINE>
@@ -218,7 +218,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_e.eek[0]>", line 1, in ?
+ File "<doctest sample2.sampletests_e.eek[line 2, example 0]>", line 1, in ?
f()
File "testrunner-ex/sample2/sampletests_e.py", line 19, in f
g()
@@ -260,9 +260,9 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest e.txt[1]>", line 1, in ?
+ File "<doctest e.txt[line 4, example 1]>", line 1, in ?
f()
- File "<doctest e.txt[0]>", line 2, in f
+ File "<doctest e.txt[line 1, example 0]>", line 2, in f
return x
NameError: global name 'x' is not defined
<BLANKLINE>
@@ -389,7 +389,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_1.eek[0]>", line 1, in ?
+ File "<doctest sample2.sampletests_1.eek[line 2, example 0]>", line 1, in ?
x = y
NameError: name 'y' is not defined
----------------------------------------------------------------------
@@ -401,7 +401,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_1.eek[1]>", line 1, in ?
+ File "<doctest sample2.sampletests_1.eek[line 4, example 1]>", line 1, in ?
x
NameError: name 'x' is not defined
----------------------------------------------------------------------
@@ -413,7 +413,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_1.eek[2]>", line 1, in ?
+ File "<doctest sample2.sampletests_1.eek[line 7, example 2]>", line 1, in ?
z = x + 1
NameError: name 'x' is not defined
<BLANKLINE>
@@ -446,7 +446,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_1.eek[0]>", line 1, in ?
+ File "<doctest sample2.sampletests_1.eek[line 2, example 0]>", line 1, in ?
x = y
NameError: name 'y' is not defined
<BLANKLINE>
@@ -479,7 +479,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_1.eek[0]>", line 1, in ?
+ File "<doctest sample2.sampletests_1.eek[line 2, example 0]>", line 1, in ?
x = y
NameError: name 'y' is not defined
<BLANKLINE>
@@ -515,7 +515,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_1.eek[0]>", line 1, in ?
+ File "<doctest sample2.sampletests_1.eek[line 2, example 0]>", line 1, in ?
x = y
NameError: name 'y' is not defined
----------------------------------------------------------------------
@@ -527,7 +527,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_1.eek[1]>", line 1, in ?
+ File "<doctest sample2.sampletests_1.eek[line 4, example 1]>", line 1, in ?
x
NameError: name 'x' is not defined
----------------------------------------------------------------------
@@ -539,7 +539,7 @@
Traceback (most recent call last):
File ".../doctest.py", line 1256, in __run
compileflags, 1) in test.globs
- File "<doctest sample2.sampletests_1.eek[2]>", line 1, in ?
+ File "<doctest sample2.sampletests_1.eek[line 7, example 2]>", line 1, in ?
z = x + 1
NameError: name 'x' is not defined
<BLANKLINE>
@@ -816,7 +816,7 @@
Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
True
-
+
Reporting Errors to Calling Processes
-------------------------------------
More information about the Zope3-Checkins
mailing list