summaryrefslogtreecommitdiff
path: root/Lib/test/test_StringIO.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-10-22 21:26:01 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2011-10-22 21:26:01 +0200
commit5a77fe92bd26db11684e4922707d80f654be31dc (patch)
tree47fcd8c286d773367b084741c88df5a8accbfa8e /Lib/test/test_StringIO.py
parentf678e822406a5063b294036f5521c2294a6e20bd (diff)
downloadcpython-git-5a77fe92bd26db11684e4922707d80f654be31dc.tar.gz
Issue #1548891: The cStringIO.StringIO() constructor now encodes unicode
arguments with the system default encoding just like the write() method does, instead of converting it to a raw buffer.
Diffstat (limited to 'Lib/test/test_StringIO.py')
-rw-r--r--Lib/test/test_StringIO.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py
index 1459e617a6..bf0c733db7 100644
--- a/Lib/test/test_StringIO.py
+++ b/Lib/test/test_StringIO.py
@@ -134,6 +134,27 @@ class TestcStringIO(TestGenericStringIO):
f = self.MODULE.StringIO(a)
self.assertEqual(f.getvalue(), '\x00\x01\x02')
+ def test_unicode(self):
+
+ if not test_support.have_unicode: return
+
+ # The cStringIO module converts Unicode strings to character
+ # strings when writing them to cStringIO objects.
+ # Check that this works.
+
+ f = self.MODULE.StringIO()
+ f.write(u'abcde')
+ s = f.getvalue()
+ self.assertEqual(s, 'abcde')
+ self.assertEqual(type(s), str)
+
+ f = self.MODULE.StringIO(u'abcde')
+ s = f.getvalue()
+ self.assertEqual(s, 'abcde')
+ self.assertEqual(type(s), str)
+
+ self.assertRaises(UnicodeEncodeError, self.MODULE.StringIO, u'\xf4')
+
import sys
if sys.platform.startswith('java'):