diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-07-02 18:16:45 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-07-02 18:16:45 (GMT) |
commit | 753d16234f61dd4494a19e71a5fc196611ecbcf3 (patch) | |
tree | dc8708d1eb6c1f38fcf7709ad20e1c05ec57239f /Lib/test/test_print.py | |
parent | 1bf4765369d7a6d5f0a4ad616f8a887c8fc4af39 (diff) | |
download | cpython-753d16234f61dd4494a19e71a5fc196611ecbcf3.zip cpython-753d16234f61dd4494a19e71a5fc196611ecbcf3.tar.gz cpython-753d16234f61dd4494a19e71a5fc196611ecbcf3.tar.bz2 |
when print() gets unicode arguments, sep and end should be unicode by default #4618
Diffstat (limited to 'Lib/test/test_print.py')
-rw-r--r-- | Lib/test/test_print.py | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/Lib/test/test_print.py b/Lib/test/test_print.py index 5ed2cc0..394a2f1 100644 --- a/Lib/test/test_print.py +++ b/Lib/test/test_print.py @@ -9,12 +9,7 @@ import unittest from test import test_support import sys -if sys.version_info[0] == 3: - # 3.x - from io import StringIO -else: - # 2.x - from StringIO import StringIO +from StringIO import StringIO NotDefined = object() @@ -112,6 +107,34 @@ class TestPrint(unittest.TestCase): self.assertRaises(TypeError, print, '', end=3) self.assertRaises(AttributeError, print, '', file='') + def test_mixed_args(self): + # If an unicode arg is passed, sep and end should be unicode, too. + class Recorder(object): + + def __init__(self, must_be_unicode): + self.buf = [] + self.force_unicode = must_be_unicode + + def write(self, what): + if self.force_unicode and not isinstance(what, unicode): + raise AssertionError("{0!r} is not unicode".format(what)) + self.buf.append(what) + + buf = Recorder(True) + print(u'hi', file=buf) + self.assertEqual(u''.join(buf.buf), 'hi\n') + del buf.buf[:] + print(u'hi', u'nothing', file=buf) + self.assertEqual(u''.join(buf.buf), 'hi nothing\n') + buf = Recorder(False) + print('hi', 'bye', end=u'\n', file=buf) + self.assertTrue(isinstance(buf.buf[1], unicode)) + self.assertTrue(isinstance(buf.buf[3], unicode)) + del buf.buf[:] + print(sep=u'x', file=buf) + self.assertTrue(isinstance(buf.buf[-1], unicode)) + + def test_main(): test_support.run_unittest(TestPrint) |