diff options
author | Georg Brandl <georg@python.org> | 2006-10-12 09:47:17 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-10-12 09:47:17 (GMT) |
commit | 3c48709e3a6bc78bf2777b6b202eff0b2c323b89 (patch) | |
tree | 4b0ed840f781252c404be346e0ead3e5b5759a8c /Lib | |
parent | fcf6696255b36efd73745d4e5e8e9a1dcbd2fd40 (diff) | |
download | cpython-3c48709e3a6bc78bf2777b6b202eff0b2c323b89.zip cpython-3c48709e3a6bc78bf2777b6b202eff0b2c323b89.tar.gz cpython-3c48709e3a6bc78bf2777b6b202eff0b2c323b89.tar.bz2 |
Bug #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.
(backport from rev. 52301)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_StringIO.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index cc3367f..aa36b09 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -120,6 +120,28 @@ class TestStringIO(TestGenericStringIO): class TestcStringIO(TestGenericStringIO): MODULE = cStringIO + 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(unicode(self._line[:5])) + s = f.getvalue() + self.assertEqual(s, 'abcde') + self.assertEqual(type(s), types.StringType) + + f = self.MODULE.StringIO(unicode(self._line[:5])) + s = f.getvalue() + self.assertEqual(s, 'abcde') + self.assertEqual(type(s), types.StringType) + + self.assertRaises(UnicodeEncodeError, self.MODULE.StringIO, + unicode('\xf4', 'latin-1')) + import sys if sys.platform.startswith('java'): # Jython doesn't have a buffer object, so we just do a useless |