[Python-checkins] r85578 - in python/branches/py3k: Lib/test/test_doctest.py Misc/NEWS

victor.stinner python-checkins at python.org
Sat Oct 16 23:54:59 CEST 2010


Author: victor.stinner
Date: Sat Oct 16 23:54:59 2010
New Revision: 85578
Log:
Issue #10123: Don't use non-ascii filenames in test_doctest tests. Add a
new test specific to unicode (non-ascii name and filename).
Modified:
 python/branches/py3k/Lib/test/test_doctest.py
 python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/test/test_doctest.py
==============================================================================
--- python/branches/py3k/Lib/test/test_doctest.py	(original)
+++ python/branches/py3k/Lib/test/test_doctest.py	Sat Oct 16 23:54:59 2010
@@ -4,6 +4,7 @@
 
 from test import support
 import doctest
+import os
 
 
 # NOTE: There are some additional tests relating to interaction with
@@ -372,7 +373,7 @@
 >>> 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 @@
 ... >>> import pdb; pdb.set_trace()
 ... '''
 >>> parser = doctest.DocTestParser()
- >>> test = parser.get_doctest(doc, {}, "foo-bär at baz", "foo-bär at baz.py", 0)
+ >>> test = parser.get_doctest(doc, {}, "foo-bar at baz", "foo-bar at baz.py", 0)
 >>> runner = doctest.DocTestRunner(verbose=False)
 
 To demonstrate this, we'll create a fake standard input that
@@ -1719,7 +1720,7 @@
 >>> try: runner.run(test)
 ... finally: sys.stdin = real_stdin
 --Return--
- > <doctest foo-bär at baz[2]>(1)<module>()->None
+ > <doctest foo-bar at baz[2]>(1)<module>()->None
 -> import pdb; pdb.set_trace()
 (Pdb) print(x)
 42
@@ -1736,7 +1737,7 @@
 ... >>> x=1
 ... >>> calls_set_trace()
 ... '''
- >>> test = parser.get_doctest(doc, globals(), "foo-bär at baz", "foo-bär at baz.py", 0)
+ >>> test = parser.get_doctest(doc, globals(), "foo-bar at baz", "foo-bar at baz.py", 0)
 >>> real_stdin = sys.stdin
 >>> sys.stdin = _FakeInput([
 ... 'print(y)', # print data defined in the function
@@ -1755,7 +1756,7 @@
 (Pdb) print(y)
 2
 (Pdb) up
- > <doctest foo-bär at baz[1]>(1)<module>()
+ > <doctest foo-bar at baz[1]>(1)<module>()
 -> calls_set_trace()
 (Pdb) print(x)
 1
@@ -1773,7 +1774,7 @@
 ... ... import pdb; pdb.set_trace()
 ... >>> f(3)
 ... '''
- >>> test = parser.get_doctest(doc, globals(), "foo-bär at baz", "foo-bär at baz.py", 0)
+ >>> test = parser.get_doctest(doc, globals(), "foo-bar at baz", "foo-bar at baz.py", 0)
 >>> real_stdin = sys.stdin
 >>> sys.stdin = _FakeInput([
 ... 'list', # list source from example 2
@@ -1787,7 +1788,7 @@
 ... finally: sys.stdin = real_stdin
 ... # doctest: +NORMALIZE_WHITESPACE
 --Return--
- > <doctest foo-bär at baz[1]>(3)g()->None
+ > <doctest foo-bar at baz[1]>(3)g()->None
 -> import pdb; pdb.set_trace()
 (Pdb) list
 1 def g(x):
@@ -1796,7 +1797,7 @@
 [EOF]
 (Pdb) next
 --Return--
- > <doctest foo-bär at baz[0]>(2)f()->None
+ > <doctest foo-bar at baz[0]>(2)f()->None
 -> g(x*2)
 (Pdb) list
 1 def f(x):
@@ -1804,14 +1805,14 @@
 [EOF]
 (Pdb) next
 --Return--
- > <doctest foo-bär at baz[2]>(1)<module>()->None
+ > <doctest foo-bar at baz[2]>(1)<module>()->None
 -> f(3)
 (Pdb) list
 1 -> f(3)
 [EOF]
 (Pdb) continue
 **********************************************************************
- File "foo-bär at baz.py", line 7, in foo-bär at baz
+ File "foo-bar at baz.py", line 7, in foo-bar at baz
 Failed example:
 f(3)
 Expected nothing
@@ -1845,7 +1846,7 @@
 ... '''
 >>> parser = doctest.DocTestParser()
 >>> runner = doctest.DocTestRunner(verbose=False)
- >>> test = parser.get_doctest(doc, globals(), "foo-bär at baz", "foo-bär at baz.py", 0)
+ >>> test = parser.get_doctest(doc, globals(), "foo-bar at baz", "foo-bar at baz.py", 0)
 >>> real_stdin = sys.stdin
 >>> sys.stdin = _FakeInput([
 ... 'print(y)', # print data defined in the function
@@ -1898,7 +1899,7 @@
 (Pdb) print(y)
 1
 (Pdb) up
- > <doctest foo-bär at baz[1]>(1)<module>()
+ > <doctest foo-bar at baz[1]>(1)<module>()
 -> calls_set_trace()
 (Pdb) print(foo)
 *** NameError: name 'foo' is not defined
@@ -2433,6 +2434,39 @@
 TestResults(failed=0, attempted=0)
 """
 
+try:
+ os.fsencode("foo-bär at 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 at baz", "foo-bär at baz.py", 0)
+ >>> test
+ <DocTest foo-bär at baz from foo-bär at baz.py:0 (1 example)>
+ >>> runner = doctest.DocTestRunner(verbose=False)
+ >>> runner.run(test) # doctest: +ELLIPSIS
+ **********************************************************************
+ File "foo-bär at baz.py", line 2, in foo-bär at baz
+ Failed example:
+ raise Exception('clé')
+ Exception raised:
+ Traceback (most recent call last):
+ File ...
+ compileflags, 1), test.globs)
+ File "<doctest foo-bär at baz[0]>", line 1, in <module>
+ raise Exception('clé')
+ Exception: clé
+ TestResults(failed=1, attempted=1)
+ """
+
 ######################################################################
 ## Main
 ######################################################################
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sat Oct 16 23:54:59 2010
@@ -98,6 +98,12 @@
 
 - Issue #7287: Demo/imputil/knee.py was removed.
 
+Tests
+-----
+
+- Issue #10123: Don't use non-ascii filenames in test_doctest tests. Add a
+ new test specific to unicode (non-ascii name and filename).
+
 Build
 -----
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /