mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #10123: Don't use non-ascii filenames in test_doctest tests. Add a
new test specific to unicode (non-ascii name and filename).
This commit is contained in:
parent
2a531395cd
commit
9d396399da
2 changed files with 52 additions and 12 deletions
|
@ -4,6 +4,7 @@ Test script for doctest.
|
|||
|
||||
from test import support
|
||||
import doctest
|
||||
import os
|
||||
|
||||
|
||||
# NOTE: There are some additional tests relating to interaction with
|
||||
|
@ -372,7 +373,7 @@ We'll simulate a __file__ attr that ends in pyc:
|
|||
>>> tests = finder.find(sample_func)
|
||||
|
||||
>>> print(tests) # doctest: +ELLIPSIS
|
||||
[<DocTest sample_func from ...:16 (1 example)>]
|
||||
[<DocTest sample_func from ...:17 (1 example)>]
|
||||
|
||||
The exact name depends on how test_doctest was invoked, so allow for
|
||||
leading path components.
|
||||
|
@ -1703,7 +1704,7 @@ def test_pdb_set_trace():
|
|||
... >>> import pdb; pdb.set_trace()
|
||||
... '''
|
||||
>>> parser = doctest.DocTestParser()
|
||||
>>> test = parser.get_doctest(doc, {}, "foo-bär@baz", "foo-bär@baz.py", 0)
|
||||
>>> test = parser.get_doctest(doc, {}, "foo-bar@baz", "foo-bar@baz.py", 0)
|
||||
>>> runner = doctest.DocTestRunner(verbose=False)
|
||||
|
||||
To demonstrate this, we'll create a fake standard input that
|
||||
|
@ -1719,7 +1720,7 @@ def test_pdb_set_trace():
|
|||
>>> try: runner.run(test)
|
||||
... finally: sys.stdin = real_stdin
|
||||
--Return--
|
||||
> <doctest foo-bär@baz[2]>(1)<module>()->None
|
||||
> <doctest foo-bar@baz[2]>(1)<module>()->None
|
||||
-> import pdb; pdb.set_trace()
|
||||
(Pdb) print(x)
|
||||
42
|
||||
|
@ -1736,7 +1737,7 @@ def test_pdb_set_trace():
|
|||
... >>> x=1
|
||||
... >>> calls_set_trace()
|
||||
... '''
|
||||
>>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0)
|
||||
>>> test = parser.get_doctest(doc, globals(), "foo-bar@baz", "foo-bar@baz.py", 0)
|
||||
>>> real_stdin = sys.stdin
|
||||
>>> sys.stdin = _FakeInput([
|
||||
... 'print(y)', # print data defined in the function
|
||||
|
@ -1755,7 +1756,7 @@ def test_pdb_set_trace():
|
|||
(Pdb) print(y)
|
||||
2
|
||||
(Pdb) up
|
||||
> <doctest foo-bär@baz[1]>(1)<module>()
|
||||
> <doctest foo-bar@baz[1]>(1)<module>()
|
||||
-> calls_set_trace()
|
||||
(Pdb) print(x)
|
||||
1
|
||||
|
@ -1773,7 +1774,7 @@ def test_pdb_set_trace():
|
|||
... ... import pdb; pdb.set_trace()
|
||||
... >>> f(3)
|
||||
... '''
|
||||
>>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0)
|
||||
>>> test = parser.get_doctest(doc, globals(), "foo-bar@baz", "foo-bar@baz.py", 0)
|
||||
>>> real_stdin = sys.stdin
|
||||
>>> sys.stdin = _FakeInput([
|
||||
... 'list', # list source from example 2
|
||||
|
@ -1787,7 +1788,7 @@ def test_pdb_set_trace():
|
|||
... finally: sys.stdin = real_stdin
|
||||
... # doctest: +NORMALIZE_WHITESPACE
|
||||
--Return--
|
||||
> <doctest foo-bär@baz[1]>(3)g()->None
|
||||
> <doctest foo-bar@baz[1]>(3)g()->None
|
||||
-> import pdb; pdb.set_trace()
|
||||
(Pdb) list
|
||||
1 def g(x):
|
||||
|
@ -1796,7 +1797,7 @@ def test_pdb_set_trace():
|
|||
[EOF]
|
||||
(Pdb) next
|
||||
--Return--
|
||||
> <doctest foo-bär@baz[0]>(2)f()->None
|
||||
> <doctest foo-bar@baz[0]>(2)f()->None
|
||||
-> g(x*2)
|
||||
(Pdb) list
|
||||
1 def f(x):
|
||||
|
@ -1804,14 +1805,14 @@ def test_pdb_set_trace():
|
|||
[EOF]
|
||||
(Pdb) next
|
||||
--Return--
|
||||
> <doctest foo-bär@baz[2]>(1)<module>()->None
|
||||
> <doctest foo-bar@baz[2]>(1)<module>()->None
|
||||
-> f(3)
|
||||
(Pdb) list
|
||||
1 -> f(3)
|
||||
[EOF]
|
||||
(Pdb) continue
|
||||
**********************************************************************
|
||||
File "foo-bär@baz.py", line 7, in foo-bär@baz
|
||||
File "foo-bar@baz.py", line 7, in foo-bar@baz
|
||||
Failed example:
|
||||
f(3)
|
||||
Expected nothing
|
||||
|
@ -1845,7 +1846,7 @@ def test_pdb_set_trace_nested():
|
|||
... '''
|
||||
>>> parser = doctest.DocTestParser()
|
||||
>>> runner = doctest.DocTestRunner(verbose=False)
|
||||
>>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0)
|
||||
>>> test = parser.get_doctest(doc, globals(), "foo-bar@baz", "foo-bar@baz.py", 0)
|
||||
>>> real_stdin = sys.stdin
|
||||
>>> sys.stdin = _FakeInput([
|
||||
... 'print(y)', # print data defined in the function
|
||||
|
@ -1898,7 +1899,7 @@ def test_pdb_set_trace_nested():
|
|||
(Pdb) print(y)
|
||||
1
|
||||
(Pdb) up
|
||||
> <doctest foo-bär@baz[1]>(1)<module>()
|
||||
> <doctest foo-bar@baz[1]>(1)<module>()
|
||||
-> calls_set_trace()
|
||||
(Pdb) print(foo)
|
||||
*** NameError: name 'foo' is not defined
|
||||
|
@ -2433,6 +2434,39 @@ out of the binary module.
|
|||
TestResults(failed=0, attempted=0)
|
||||
"""
|
||||
|
||||
try:
|
||||
os.fsencode("foo-bär@baz.py")
|
||||
except UnicodeEncodeError:
|
||||
# Skip the test: the filesystem encoding is unable to encode the filename
|
||||
pass
|
||||
else:
|
||||
def test_unicode(): """
|
||||
Check doctest with a non-ascii filename:
|
||||
|
||||
>>> doc = '''
|
||||
... >>> raise Exception('clé')
|
||||
... '''
|
||||
...
|
||||
>>> parser = doctest.DocTestParser()
|
||||
>>> test = parser.get_doctest(doc, {}, "foo-bär@baz", "foo-bär@baz.py", 0)
|
||||
>>> test
|
||||
<DocTest foo-bär@baz from foo-bär@baz.py:0 (1 example)>
|
||||
>>> runner = doctest.DocTestRunner(verbose=False)
|
||||
>>> runner.run(test) # doctest: +ELLIPSIS
|
||||
**********************************************************************
|
||||
File "foo-bär@baz.py", line 2, in foo-bär@baz
|
||||
Failed example:
|
||||
raise Exception('clé')
|
||||
Exception raised:
|
||||
Traceback (most recent call last):
|
||||
File ...
|
||||
compileflags, 1), test.globs)
|
||||
File "<doctest foo-bär@baz[0]>", line 1, in <module>
|
||||
raise Exception('clé')
|
||||
Exception: clé
|
||||
TestResults(failed=1, attempted=1)
|
||||
"""
|
||||
|
||||
######################################################################
|
||||
## Main
|
||||
######################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue