]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fixed a small bug. doctest didn't handle unicode docstrings containing
authorJim Fulton <jim@zope.com>
Wed, 13 Oct 2004 14:15:32 +0000 (14:15 +0000)
committerJim Fulton <jim@zope.com>
Wed, 13 Oct 2004 14:15:32 +0000 (14:15 +0000)
non-ascii characters.

Lib/doctest.py
Lib/test/test_doctest2.py
Lib/test/test_doctest2.txt

index 26a89144689ac39801276b51f2e55d5af5d3d4c7..a8162f31523ca302f780f3eaac1fc3ed00b24ed1 100644 (file)
@@ -962,7 +962,9 @@ class DocTestFinder:
                 if obj.__doc__ is None:
                     docstring = ''
                 else:
-                    docstring = str(obj.__doc__)
+                    docstring = obj.__doc__
+                    if not isinstance(docstring, basestring):
+                        docstring = str(docstring)
             except (TypeError, AttributeError):
                 docstring = ''
 
index 3593d4199ab34ed6a07c8db575d23a6c21499008..5b7f36f0f738d94b8f96b30a0141b374f6dccaa2 100644 (file)
@@ -1,17 +1,31 @@
-"""A module to test whether doctest recognizes some 2.2 features,
+# -*- coding: utf-8 -*-
+u"""A module to test whether doctest recognizes some 2.2 features,
 like static and class methods.
 
 >>> print 'yup'  # 1
 yup
+
+We include some (random) encoded (utf-8) text in the text surrounding
+the example.  It should be ignored:
+
+ЉЊЈЁЂ
+
 """
 
 from test import test_support
 
 class C(object):
-    """Class C.
+    u"""Class C.
 
     >>> print C()  # 2
     42
+
+
+    We include some (random) encoded (utf-8) text in the text surrounding
+    the example.  It should be ignored:
+
+        ЉЊЈЁЂ
+
     """
 
     def __init__(self):
index 0d7d1d59c11f07683cb7e771d404a4d6eab01407..2e14856c27d8b380c76a3df854268e318df3457c 100644 (file)
@@ -5,3 +5,10 @@ In this example, we'll rely on some silly setup:
   >>> import test.test_doctest
   >>> test.test_doctest.sillySetup
   True
+
+This test also has some (random) encoded (utf-8) unicode text:
+
+  ï»¿Ð\89Ð\8aÐ\88Ð\81Ð\82
+
+This doesn't cause a problem in the tect surrounding the examples, but
+we include it here (in this test text file) to make sure. :)