mirror of
https://github.com/python/cpython.git
synced 2025-07-28 21:55:21 +00:00
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.
This commit is contained in:
parent
b2e81e307d
commit
5597e261b2
3 changed files with 28 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue