summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_doctest.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-08-01 08:22:05 (GMT)
committerGeorg Brandl <georg@python.org>2010-08-01 08:22:05 (GMT)
commit1f05e2e9baa66b3c6241c2450481eee0756381ca (patch)
treeca88e13d2923c25cd77836490e7ec5dd0b364b1b /Lib/test/test_doctest.py
parent58f15b66ffb03bfe2c9fbc111e1cc28f4cd3ddd4 (diff)
downloadcpython-1f05e2e9baa66b3c6241c2450481eee0756381ca.zip
cpython-1f05e2e9baa66b3c6241c2450481eee0756381ca.tar.gz
cpython-1f05e2e9baa66b3c6241c2450481eee0756381ca.tar.bz2
#8471: reset _SpoofOut.buf to an empty string when truncating; if Unicode had been output previously, it had been coerced to a Unicode string, potentially making subsequent prints behave differently or raise UnicodeErrors.
Diffstat (limited to 'Lib/test/test_doctest.py')
-rw-r--r--Lib/test/test_doctest.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 1051068..e51bacc 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -1581,7 +1581,33 @@ source:
>>> test = doctest.DocTestParser().get_doctest(s, {}, 's', 's.py', 0)
Traceback (most recent call last):
ValueError: line 0 of the doctest for s has an option directive on a line with no example: '# doctest: +ELLIPSIS'
-"""
+
+ """
+
+ def test_unicode_output(self): r"""
+
+Check that unicode output works:
+
+ >>> u'\xe9'
+ u'\xe9'
+
+If we return unicode, SpoofOut's buf variable becomes automagically
+converted to unicode. This means all subsequent output becomes converted
+to unicode, and if the output contains non-ascii characters that failed.
+It used to be that this state change carried on between tests, meaning
+tests would fail if unicode has been output previously in the testrun.
+This test tests that this is no longer so:
+
+ >>> print u'abc'
+ abc
+
+And then return a string with non-ascii characters:
+
+ >>> print u'\xe9'.encode('utf-8')
+ é
+
+ """
+
def test_testsource(): r"""
Unit tests for `testsource()`.