[KoCo-CVS] [Commit] KoreanCodecs/test test_mackorean.py test_all.py test_cp949.py
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-01-10 03:15:25
|
perky 03/01/09 19:15:25 Modified: test test_all.py test_cp949.py Added: test test_mackorean.py Log: Add MacKorean unit tests. Revision Changes Path 1.7 +2 -1 KoreanCodecs/test/test_all.py Index: test_all.py =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/test/test_all.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- test_all.py 9 Jan 2003 21:31:44 -0000 1.6 +++ test_all.py 10 Jan 2003 03:15:25 -0000 1.7 @@ -16,13 +16,14 @@ # along with KoreanCodecs; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: test_all.py,v 1.6 2003/01/09 21:31:44 perky Exp $ +# $Id: test_all.py,v 1.7 2003/01/10 03:15:25 perky Exp $ # import CodecTestBase from test_cp949 import TestCP949_CExtension, TestCP949_PurePython from test_euc_kr import TestEUCKR_CExtension, TestEUCKR_PurePython +from test_mackorean import TestMacKorean_PurePython from test_iso_2022_kr import TestISO_2022_KR from test_johab import TestJOHAB from test_qwerty2bul import TestQWERTY2BUL 1.8 +6 -4 KoreanCodecs/test/test_cp949.py Index: test_cp949.py =================================================================== RCS file: /cvsroot/koco/KoreanCodecs/test/test_cp949.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- test_cp949.py 9 Jan 2003 22:07:23 -0000 1.7 +++ test_cp949.py 10 Jan 2003 03:15:25 -0000 1.8 @@ -16,11 +16,14 @@ # along with KoreanCodecs; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: test_cp949.py,v 1.7 2003/01/09 22:07:23 perky Exp $ +# $Id: test_cp949.py,v 1.8 2003/01/10 03:15:25 perky Exp $ # import CodecTestBase +def unichrs(s): + return u''.join(map(unichr, map(eval, s.split('+')))) + class Shield: class TestCP949Base(CodecTestBase.TestStreamReader, CodecTestBase.CodecTestBase): encoding = 'cp949' @@ -42,15 +45,14 @@ if len(data) != 2: continue - cp949val, unival = map(eval, data) - + cp949val = eval(data[0]) if cp949val <= 0x7F: cp949ch = chr(cp949val & 0xff) elif cp949val >= 0x100: cp949ch = chr(cp949val >> 8) + chr(cp949val & 0xff) else: continue - unich = unichr(unival) + unich = unichrs(data[1]) self.assertEqual(unich.encode('cp949'), cp949ch) self.assertEqual(unicode(cp949ch, 'cp949'), unich) 1.1 KoreanCodecs/test/test_mackorean.py Index: test_mackorean.py =================================================================== # This file is part of KoreanCodecs. # # Copyright(C) 2002-2003 Hye-Shik Chang <pe...@Fr...>. # # KoreanCodecs is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # KoreanCodecs is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with KoreanCodecs; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: test_mackorean.py,v 1.1 2003/01/10 03:15:25 perky Exp $ # import CodecTestBase def unichrs(s): return u''.join(map(unichr, map(eval, s.split('+')))) class Shield: class TestMacKorean_Base(CodecTestBase.TestStreamReader, CodecTestBase.CodecTestBase): encoding = 'mackorean' textfile_chunk = ('texts/mackorean', 'texts/mackorean.utf-8') errortests = ( # invalid bytes # \x90 is expected as one byte character in MacKorean. ("abc\x90\x90\xc1\xc4", "strict", None), ("abc\xc8", "strict", None), ("abc\x90\x90\xc1\xc4", "replace", u"abc\ufffd\ufffd\uc894"), ("abc\x90\x90\xc1\xc4\xc8", "replace", u"abc\ufffd\ufffd\uc894\ufffd"), ("abc\x90\x90\xc1\xc4", "ignore", u"abc\uc894"), ("\xc1\x64", "strict", None), # cp949 code H-AE-H ) def test_mapping(self): for line in open('mappings/MacKorean.txt'): if not line: break data = line.split('#')[0].strip().split() if len(data) != 2: continue macval = eval(data[0]) if macval <= 0x7F: macch = chr(macval & 0xff) elif macval >= 0x100: macch = chr(macval >> 8) + chr(macval & 0xff) else: continue unich = unichrs(data[1]) self.assertEqual(unich.encode('mackorean'), macch) self.assertEqual(unicode(macch, 'mackorean'), unich) #class TestMacKorean_CExtension(Shield.TestMacKorean_Base): # encoding = 'korean.c.mackorean' class TestMacKorean_PurePython(Shield.TestMacKorean_Base): encoding = 'korean.python.mackorean' if __name__ == '__main__': CodecTestBase.main() # ex: ts=8 sts=4 et |