99from test .test_support import TESTFN
1010import unittest , StringIO , codecs , sys , os
1111
12+ ALL_CJKENCODINGS = [
13+ # _codecs_cn
14+ 'gb2312' , 'gbk' , 'gb18030' , 'hz' ,
15+ # _codecs_hk
16+ 'big5hkscs' ,
17+ # _codecs_jp
18+ 'cp932' , 'shift_jis' , 'euc_jp' , 'euc_jisx0213' , 'shift_jisx0213' ,
19+ 'euc_jis_2004' , 'shift_jis_2004' ,
20+ # _codecs_kr
21+ 'cp949' , 'euc_kr' , 'johab' ,
22+ # _codecs_tw
23+ 'big5' , 'cp950' ,
24+ # _codecs_iso2022
25+ 'iso2022_jp' , 'iso2022_jp_1' , 'iso2022_jp_2' , 'iso2022_jp_2004' ,
26+ 'iso2022_jp_3' , 'iso2022_jp_ext' , 'iso2022_kr' ,
27+ ]
28+
1229class Test_MultibyteCodec (unittest .TestCase ):
1330
1431 def test_nullcoding (self ):
15- self .assertEqual ('' .decode ('gb18030' ), u'' )
16- self .assertEqual (unicode ('' , 'gb18030' ), u'' )
17- self .assertEqual (u'' .encode ('gb18030' ), '' )
32+ for enc in ALL_CJKENCODINGS :
33+ self .assertEqual ('' .decode (enc ), u'' )
34+ self .assertEqual (unicode ('' , enc ), u'' )
35+ self .assertEqual (u'' .encode (enc ), '' )
1836
1937 def test_str_decode (self ):
20- self .assertEqual ('abcd' .encode ('gb18030' ), 'abcd' )
38+ for enc in ALL_CJKENCODINGS :
39+ self .assertEqual ('abcd' .encode (enc ), 'abcd' )
2140
2241 def test_errorcallback_longindex (self ):
2342 dec = codecs .getdecoder ('euc-kr' )
@@ -27,9 +46,10 @@ def test_errorcallback_longindex(self):
2746 'apple\x92 ham\x93 spam' , 'test.cjktest' )
2847
2948 def test_codingspec (self ):
30- print >> open (TESTFN , 'w' ), '# coding: euc-kr'
3149 try :
32- exec open (TESTFN )
50+ for enc in ALL_CJKENCODINGS :
51+ print >> open (TESTFN , 'w' ), '# coding:' , enc
52+ exec open (TESTFN )
3353 finally :
3454 os .unlink (TESTFN )
3555
0 commit comments