summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_multibytecodec.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_multibytecodec.py')
-rw-r--r--Lib/test/test_multibytecodec.py106
1 files changed, 53 insertions, 53 deletions
diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py
index c5615a8..8ea4bf9 100644
--- a/Lib/test/test_multibytecodec.py
+++ b/Lib/test/test_multibytecodec.py
@@ -30,9 +30,9 @@ class Test_MultibyteCodec(unittest.TestCase):
def test_nullcoding(self):
for enc in ALL_CJKENCODINGS:
- self.assertEqual(''.decode(enc), u'')
- self.assertEqual(unicode('', enc), u'')
- self.assertEqual(u''.encode(enc), '')
+ self.assertEqual(''.decode(enc), '')
+ self.assertEqual(str('', enc), '')
+ self.assertEqual(''.encode(enc), '')
def test_str_decode(self):
for enc in ALL_CJKENCODINGS:
@@ -40,7 +40,7 @@ class Test_MultibyteCodec(unittest.TestCase):
def test_errorcallback_longindex(self):
dec = codecs.getdecoder('euc-kr')
- myreplace = lambda exc: (u'', sys.maxint+1)
+ myreplace = lambda exc: ('', sys.maxint+1)
codecs.register_error('test.cjktest', myreplace)
self.assertRaises(IndexError, dec,
'apple\x92ham\x93spam', 'test.cjktest')
@@ -58,14 +58,14 @@ class Test_IncrementalEncoder(unittest.TestCase):
def test_stateless(self):
# cp949 encoder isn't stateful at all.
encoder = codecs.getincrementalencoder('cp949')()
- self.assertEqual(encoder.encode(u'\ud30c\uc774\uc36c \ub9c8\uc744'),
+ self.assertEqual(encoder.encode('\ud30c\uc774\uc36c \ub9c8\uc744'),
'\xc6\xc4\xc0\xcc\xbd\xe3 \xb8\xb6\xc0\xbb')
self.assertEqual(encoder.reset(), None)
- self.assertEqual(encoder.encode(u'\u2606\u223c\u2606', True),
+ self.assertEqual(encoder.encode('\u2606\u223c\u2606', True),
'\xa1\xd9\xa1\xad\xa1\xd9')
self.assertEqual(encoder.reset(), None)
- self.assertEqual(encoder.encode(u'', True), '')
- self.assertEqual(encoder.encode(u'', False), '')
+ self.assertEqual(encoder.encode('', True), '')
+ self.assertEqual(encoder.encode('', False), '')
self.assertEqual(encoder.reset(), None)
def test_stateful(self):
@@ -75,29 +75,29 @@ class Test_IncrementalEncoder(unittest.TestCase):
# U+0300 => ABDC
encoder = codecs.getincrementalencoder('jisx0213')()
- self.assertEqual(encoder.encode(u'\u00e6\u0300'), '\xab\xc4')
- self.assertEqual(encoder.encode(u'\u00e6'), '')
- self.assertEqual(encoder.encode(u'\u0300'), '\xab\xc4')
- self.assertEqual(encoder.encode(u'\u00e6', True), '\xa9\xdc')
+ self.assertEqual(encoder.encode('\u00e6\u0300'), '\xab\xc4')
+ self.assertEqual(encoder.encode('\u00e6'), '')
+ self.assertEqual(encoder.encode('\u0300'), '\xab\xc4')
+ self.assertEqual(encoder.encode('\u00e6', True), '\xa9\xdc')
self.assertEqual(encoder.reset(), None)
- self.assertEqual(encoder.encode(u'\u0300'), '\xab\xdc')
+ self.assertEqual(encoder.encode('\u0300'), '\xab\xdc')
- self.assertEqual(encoder.encode(u'\u00e6'), '')
+ self.assertEqual(encoder.encode('\u00e6'), '')
self.assertEqual(encoder.encode('', True), '\xa9\xdc')
self.assertEqual(encoder.encode('', True), '')
def test_stateful_keep_buffer(self):
encoder = codecs.getincrementalencoder('jisx0213')()
- self.assertEqual(encoder.encode(u'\u00e6'), '')
- self.assertRaises(UnicodeEncodeError, encoder.encode, u'\u0123')
- self.assertEqual(encoder.encode(u'\u0300\u00e6'), '\xab\xc4')
- self.assertRaises(UnicodeEncodeError, encoder.encode, u'\u0123')
+ self.assertEqual(encoder.encode('\u00e6'), '')
+ self.assertRaises(UnicodeEncodeError, encoder.encode, '\u0123')
+ self.assertEqual(encoder.encode('\u0300\u00e6'), '\xab\xc4')
+ self.assertRaises(UnicodeEncodeError, encoder.encode, '\u0123')
self.assertEqual(encoder.reset(), None)
- self.assertEqual(encoder.encode(u'\u0300'), '\xab\xdc')
- self.assertEqual(encoder.encode(u'\u00e6'), '')
- self.assertRaises(UnicodeEncodeError, encoder.encode, u'\u0123')
- self.assertEqual(encoder.encode(u'', True), '\xa9\xdc')
+ self.assertEqual(encoder.encode('\u0300'), '\xab\xdc')
+ self.assertEqual(encoder.encode('\u00e6'), '')
+ self.assertRaises(UnicodeEncodeError, encoder.encode, '\u0123')
+ self.assertEqual(encoder.encode('', True), '\xa9\xdc')
class Test_IncrementalDecoder(unittest.TestCase):
@@ -106,52 +106,52 @@ class Test_IncrementalDecoder(unittest.TestCase):
# cp949 decoder is simple with only 1 or 2 bytes sequences.
decoder = codecs.getincrementaldecoder('cp949')()
self.assertEqual(decoder.decode('\xc6\xc4\xc0\xcc\xbd'),
- u'\ud30c\uc774')
+ '\ud30c\uc774')
self.assertEqual(decoder.decode('\xe3 \xb8\xb6\xc0\xbb'),
- u'\uc36c \ub9c8\uc744')
- self.assertEqual(decoder.decode(''), u'')
+ '\uc36c \ub9c8\uc744')
+ self.assertEqual(decoder.decode(''), '')
def test_dbcs_keep_buffer(self):
decoder = codecs.getincrementaldecoder('cp949')()
- self.assertEqual(decoder.decode('\xc6\xc4\xc0'), u'\ud30c')
+ self.assertEqual(decoder.decode('\xc6\xc4\xc0'), '\ud30c')
self.assertRaises(UnicodeDecodeError, decoder.decode, '', True)
- self.assertEqual(decoder.decode('\xcc'), u'\uc774')
+ self.assertEqual(decoder.decode('\xcc'), '\uc774')
- self.assertEqual(decoder.decode('\xc6\xc4\xc0'), u'\ud30c')
+ self.assertEqual(decoder.decode('\xc6\xc4\xc0'), '\ud30c')
self.assertRaises(UnicodeDecodeError, decoder.decode, '\xcc\xbd', True)
- self.assertEqual(decoder.decode('\xcc'), u'\uc774')
+ self.assertEqual(decoder.decode('\xcc'), '\uc774')
def test_iso2022(self):
decoder = codecs.getincrementaldecoder('iso2022-jp')()
ESC = '\x1b'
- self.assertEqual(decoder.decode(ESC + '('), u'')
- self.assertEqual(decoder.decode('B', True), u'')
- self.assertEqual(decoder.decode(ESC + '$'), u'')
- self.assertEqual(decoder.decode('B@$'), u'\u4e16')
- self.assertEqual(decoder.decode('@$@'), u'\u4e16')
- self.assertEqual(decoder.decode('$', True), u'\u4e16')
+ self.assertEqual(decoder.decode(ESC + '('), '')
+ self.assertEqual(decoder.decode('B', True), '')
+ self.assertEqual(decoder.decode(ESC + '$'), '')
+ self.assertEqual(decoder.decode('B@$'), '\u4e16')
+ self.assertEqual(decoder.decode('@$@'), '\u4e16')
+ self.assertEqual(decoder.decode('$', True), '\u4e16')
self.assertEqual(decoder.reset(), None)
- self.assertEqual(decoder.decode('@$'), u'@$')
- self.assertEqual(decoder.decode(ESC + '$'), u'')
+ self.assertEqual(decoder.decode('@$'), '@$')
+ self.assertEqual(decoder.decode(ESC + '$'), '')
self.assertRaises(UnicodeDecodeError, decoder.decode, '', True)
- self.assertEqual(decoder.decode('B@$'), u'\u4e16')
+ self.assertEqual(decoder.decode('B@$'), '\u4e16')
class Test_StreamWriter(unittest.TestCase):
- if len(u'\U00012345') == 2: # UCS2
+ if len('\U00012345') == 2: # UCS2
def test_gb18030(self):
s= StringIO.StringIO()
c = codecs.getwriter('gb18030')(s)
- c.write(u'123')
+ c.write('123')
self.assertEqual(s.getvalue(), '123')
- c.write(u'\U00012345')
+ c.write('\U00012345')
self.assertEqual(s.getvalue(), '123\x907\x959')
- c.write(u'\U00012345'[0])
+ c.write('\U00012345'[0])
self.assertEqual(s.getvalue(), '123\x907\x959')
- c.write(u'\U00012345'[1] + u'\U00012345' + u'\uac00\u00ac')
+ c.write('\U00012345'[1] + '\U00012345' + '\uac00\u00ac')
self.assertEqual(s.getvalue(),
'123\x907\x959\x907\x959\x907\x959\x827\xcf5\x810\x851')
- c.write(u'\U00012345'[0])
+ c.write('\U00012345'[0])
self.assertEqual(s.getvalue(),
'123\x907\x959\x907\x959\x907\x959\x827\xcf5\x810\x851')
self.assertRaises(UnicodeError, c.reset)
@@ -161,20 +161,20 @@ class Test_StreamWriter(unittest.TestCase):
def test_utf_8(self):
s= StringIO.StringIO()
c = codecs.getwriter('utf-8')(s)
- c.write(u'123')
+ c.write('123')
self.assertEqual(s.getvalue(), '123')
- c.write(u'\U00012345')
+ c.write('\U00012345')
self.assertEqual(s.getvalue(), '123\xf0\x92\x8d\x85')
# Python utf-8 codec can't buffer surrogate pairs yet.
if 0:
- c.write(u'\U00012345'[0])
+ c.write('\U00012345'[0])
self.assertEqual(s.getvalue(), '123\xf0\x92\x8d\x85')
- c.write(u'\U00012345'[1] + u'\U00012345' + u'\uac00\u00ac')
+ c.write('\U00012345'[1] + '\U00012345' + '\uac00\u00ac')
self.assertEqual(s.getvalue(),
'123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85'
'\xea\xb0\x80\xc2\xac')
- c.write(u'\U00012345'[0])
+ c.write('\U00012345'[0])
self.assertEqual(s.getvalue(),
'123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85'
'\xea\xb0\x80\xc2\xac')
@@ -182,7 +182,7 @@ class Test_StreamWriter(unittest.TestCase):
self.assertEqual(s.getvalue(),
'123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85'
'\xea\xb0\x80\xc2\xac\xed\xa0\x88')
- c.write(u'\U00012345'[1])
+ c.write('\U00012345'[1])
self.assertEqual(s.getvalue(),
'123\xf0\x92\x8d\x85\xf0\x92\x8d\x85\xf0\x92\x8d\x85'
'\xea\xb0\x80\xc2\xac\xed\xa0\x88\xed\xbd\x85')
@@ -199,13 +199,13 @@ class Test_StreamWriter(unittest.TestCase):
class Test_ISO2022(unittest.TestCase):
def test_g2(self):
iso2022jp2 = '\x1b(B:hu4:unit\x1b.A\x1bNi de famille'
- uni = u':hu4:unit\xe9 de famille'
+ uni = ':hu4:unit\xe9 de famille'
self.assertEqual(iso2022jp2.decode('iso2022-jp-2'), uni)
def test_iso2022_jp_g0(self):
- self.failIf('\x0e' in u'\N{SOFT HYPHEN}'.encode('iso-2022-jp-2'))
+ self.failIf('\x0e' in '\N{SOFT HYPHEN}'.encode('iso-2022-jp-2'))
for encoding in ('iso-2022-jp-2004', 'iso-2022-jp-3'):
- e = u'\u3406'.encode(encoding)
+ e = '\u3406'.encode(encoding)
self.failIf(filter(lambda x: x >= '\x80', e))
def test_bug1572832(self):