Fixed a small bug. doctest didn't handle unicode docstrings containing

non-ascii characters.
This commit is contained in:
Jim Fulton 2004-10-13 14:15:32 +00:00
parent 73cc8479f0
commit 7d428788e1
3 changed files with 26 additions and 3 deletions

View File

@ -962,7 +962,9 @@ class DocTestFinder:
if obj.__doc__ is None: if obj.__doc__ is None:
docstring = '' docstring = ''
else: else:
docstring = str(obj.__doc__) docstring = obj.__doc__
if not isinstance(docstring, basestring):
docstring = str(docstring)
except (TypeError, AttributeError): except (TypeError, AttributeError):
docstring = '' docstring = ''

View 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. like static and class methods.
>>> print 'yup' # 1 >>> print 'yup' # 1
yup yup
We include some (random) encoded (utf-8) text in the text surrounding
the example. It should be ignored:
ЉЊЈЁЂ
""" """
from test import test_support from test import test_support
class C(object): class C(object):
"""Class C. u"""Class C.
>>> print C() # 2 >>> print C() # 2
42 42
We include some (random) encoded (utf-8) text in the text surrounding
the example. It should be ignored:
ЉЊЈЁЂ
""" """
def __init__(self): def __init__(self):

View File

@ -5,3 +5,10 @@ In this example, we'll rely on some silly setup:
>>> import test.test_doctest >>> import test.test_doctest
>>> test.test_doctest.sillySetup >>> test.test_doctest.sillySetup
True True
This test also has some (random) encoded (utf-8) unicode text:
ЉЊЈЁЂ
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. :)