summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-10-14 21:46:04 +0000
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-10-14 21:46:04 +0000
commit78112e12aab2d16e99811d58b0f455c83a360762 (patch)
tree150b23ba11eb369f2fe486cd0fedc1c9e64f2f58
parent2ecfcd29bcd5a00a826dac8513784cff2dc620f2 (diff)
downloadcpython-78112e12aab2d16e99811d58b0f455c83a360762.tar.gz
Fix the issue with non-ascii char in doctest. Issue #9409
Recorded merge of revisions 85495,85500 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85495 | florent.xicluna | 2010-10-14 22:56:20 +0200 (jeu., 14 oct. 2010) | 3 lines Fix the regex to match all kind of filenames, for interactive debugging in doctests. (issue #9409) ........ r85500 | florent.xicluna | 2010-10-14 23:35:58 +0200 (jeu., 14 oct. 2010) | 2 lines Add test case for issue #9409, non-ascii char in doctest. It passes in 3.2 but needs fixing in 2.7. ........
-rw-r--r--Lib/doctest.py4
-rw-r--r--Lib/test/test_doctest.py7
2 files changed, 8 insertions, 3 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index dd579fd69c..c37ff9e651 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -1333,7 +1333,9 @@ class DocTestRunner:
m = self.__LINECACHE_FILENAME_RE.match(filename)
if m and m.group('name') == self.test.name:
example = self.test.examples[int(m.group('examplenum'))]
- source = example.source.encode('ascii', 'backslashreplace')
+ source = example.source
+ if isinstance(source, unicode):
+ source = source.encode('ascii', 'backslashreplace')
return source.splitlines(True)
else:
return self.save_linecache_getlines(filename, module_globals)
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 84c0798719..c027acdcd6 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -1721,6 +1721,9 @@ def test_pdb_set_trace():
>>> doc = '''
... >>> x = 42
+ ... >>> raise Exception('clé')
+ ... Traceback (most recent call last):
+ ... Exception: clé
... >>> import pdb; pdb.set_trace()
... '''
>>> parser = doctest.DocTestParser()
@@ -1740,12 +1743,12 @@ def test_pdb_set_trace():
>>> try: runner.run(test)
... finally: sys.stdin = real_stdin
--Return--
- > <doctest foo-bär@baz[1]>(1)<module>()->None
+ > <doctest foo-bär@baz[2]>(1)<module>()->None
-> import pdb; pdb.set_trace()
(Pdb) print x
42
(Pdb) continue
- TestResults(failed=0, attempted=2)
+ TestResults(failed=0, attempted=3)
You can also put pdb.set_trace in a function called from a test: