Changeset 391 for python/trunk/Lib/test/test_multibytecodec.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_multibytecodec.py
r2 r391 6 6 7 7 from test import test_support 8 from test import test_multibytecodec_support9 8 from test.test_support import TESTFN 10 9 import unittest, StringIO, codecs, sys, os … … 48 47 49 48 def test_codingspec(self): 50 try: 51 for enc in ALL_CJKENCODINGS: 52 print >> open(TESTFN, 'w'), '# coding:', enc 53 exec open(TESTFN) 54 finally: 55 os.unlink(TESTFN) 49 for enc in ALL_CJKENCODINGS: 50 code = '# coding: {}\n'.format(enc) 51 exec code 56 52 57 53 def test_init_segfault(self): … … 109 105 self.assertEqual(encoder.encode(u'', True), '\xa9\xdc') 110 106 107 def test_issue5640(self): 108 encoder = codecs.getincrementalencoder('shift-jis')('backslashreplace') 109 self.assertEqual(encoder.encode(u'\xff'), b'\\xff') 110 self.assertEqual(encoder.encode(u'\n'), b'\n') 111 111 112 112 class Test_IncrementalDecoder(unittest.TestCase): … … 223 223 224 224 def test_iso2022_jp_g0(self): 225 self. failIf('\x0e' inu'\N{SOFT HYPHEN}'.encode('iso-2022-jp-2'))225 self.assertNotIn('\x0e', u'\N{SOFT HYPHEN}'.encode('iso-2022-jp-2')) 226 226 for encoding in ('iso-2022-jp-2004', 'iso-2022-jp-3'): 227 227 e = u'\u3406'.encode(encoding) 228 self. failIf(filter(lambda x: x >= '\x80', e))228 self.assertFalse(filter(lambda x: x >= '\x80', e)) 229 229 230 230 def test_bug1572832(self): … … 238 238 myunichr(x).encode('iso_2022_jp', 'ignore') 239 239 240 class TestStateful(unittest.TestCase): 241 text = u'\u4E16\u4E16' 242 encoding = 'iso-2022-jp' 243 expected = b'\x1b$B@$@$' 244 expected_reset = b'\x1b$B@$@$\x1b(B' 245 246 def test_encode(self): 247 self.assertEqual(self.text.encode(self.encoding), self.expected_reset) 248 249 def test_incrementalencoder(self): 250 encoder = codecs.getincrementalencoder(self.encoding)() 251 output = b''.join( 252 encoder.encode(char) 253 for char in self.text) 254 self.assertEqual(output, self.expected) 255 256 def test_incrementalencoder_final(self): 257 encoder = codecs.getincrementalencoder(self.encoding)() 258 last_index = len(self.text) - 1 259 output = b''.join( 260 encoder.encode(char, index == last_index) 261 for index, char in enumerate(self.text)) 262 self.assertEqual(output, self.expected_reset) 263 264 class TestHZStateful(TestStateful): 265 text = u'\u804a\u804a' 266 encoding = 'hz' 267 expected = b'~{ADAD' 268 expected_reset = b'~{ADAD~}' 269 240 270 def test_main(): 241 271 test_support.run_unittest(__name__)
Note:
See TracChangeset
for help on using the changeset viewer.