Thread: [KoCo-CVS] [Commit] cjkcodecs/tests test_mapping_big5.py test_mapping_cp932.py test_mapping_cp950.py
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-06-20 09:04:54
|
perky 03/06/20 02:04:53 Modified: tests test_mapping_cp932.py test_mapping_cp950.py test_multibytecodec_support.py Added: tests test_mapping_big5.py Log: - Tweaked some mapping for cp932 and cp950 to make more consistency with MS Windows. - CP932: Added single byte "UNDEFINED" characters 0x80, 0xa0, 0xfd, 0xfe, 0xff (documented on NOTES.cp932) - CP950: Changed encode mappings to another more popular for duplicated unicode points: 5341 -> A451, 5345 -> A4CA - A unittest for big5 mapping is added. - Fixed a bug that cp932 codec couldn't decode half-width katakana. Revision Changes Path 1.4 +10 -1 cjkcodecs/tests/test_mapping_cp932.py Index: test_mapping_cp932.py =================================================================== RCS file: /cvsroot/koco/cjkcodecs/tests/test_mapping_cp932.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- test_mapping_cp932.py 6 Jun 2003 05:55:31 -0000 1.3 +++ test_mapping_cp932.py 20 Jun 2003 09:04:53 -0000 1.4 @@ -27,7 +27,7 @@ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # -# $Id: test_mapping_cp932.py,v 1.3 2003/06/06 05:55:31 perky Exp $ +# $Id: test_mapping_cp932.py,v 1.4 2003/06/20 09:04:53 perky Exp $ # from test import test_support @@ -43,6 +43,15 @@ unittest.TestCase): encoding = 'cjkcodecs.cp932' mapfilename = 'CP932.TXT' + supmaps = [ + ('\x80', u'\u0080'), + ('\xa0', u'\uf8f0'), + ('\xfd', u'\uf8f1'), + ('\xfe', u'\uf8f2'), + ('\xff', u'\uf8f3'), + ] + for i in range(0xa1, 0xe0): + supmaps.append((chr(i), unichr(i+0xfec0))) def test_main(): suite = unittest.TestSuite() 1.4 +5 -1 cjkcodecs/tests/test_mapping_cp950.py Index: test_mapping_cp950.py =================================================================== RCS file: /cvsroot/koco/cjkcodecs/tests/test_mapping_cp950.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- test_mapping_cp950.py 6 Jun 2003 05:55:31 -0000 1.3 +++ test_mapping_cp950.py 20 Jun 2003 09:04:53 -0000 1.4 @@ -27,7 +27,7 @@ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # -# $Id: test_mapping_cp950.py,v 1.3 2003/06/06 05:55:31 perky Exp $ +# $Id: test_mapping_cp950.py,v 1.4 2003/06/20 09:04:53 perky Exp $ # from test import test_support @@ -44,6 +44,10 @@ unittest.TestCase): encoding = 'cjkcodecs.cp950' mapfilename = 'CP950.TXT' + pass_enctest = [ + ('\xa2\xcc', u'\u5341'), + ('\xa2\xce', u'\u5345'), + ] def test_main(): suite = unittest.TestSuite() 1.6 +16 -7 cjkcodecs/tests/test_multibytecodec_support.py Index: test_multibytecodec_support.py =================================================================== RCS file: /cvsroot/koco/cjkcodecs/tests/test_multibytecodec_support.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- test_multibytecodec_support.py 29 May 2003 09:17:38 -0000 1.5 +++ test_multibytecodec_support.py 20 Jun 2003 09:04:53 -0000 1.6 @@ -27,7 +27,7 @@ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # -# $Id: test_multibytecodec_support.py,v 1.5 2003/05/29 09:17:38 perky Exp $ +# $Id: test_multibytecodec_support.py,v 1.6 2003/06/20 09:04:53 perky Exp $ # import sys, codecs, os.path @@ -155,8 +155,9 @@ class TestBase_Mapping(unittest.TestCase): pass_enctest = [] pass_dectest = [] + supmaps = [] - def test_mapping(self): + def test_mapping_file(self): unichrs = lambda s: u''.join(map(unichr, map(eval, s.split('+')))) urt_wa = {} @@ -180,15 +181,23 @@ csetch = chr(csetval >> 8) + chr(csetval & 0xff) else: continue - unich = unichrs(data[1]) + + unich = unichrs(data[1]) if ord(unich) == 0xfffd or urt_wa.has_key(unich): continue urt_wa[unich] = csetch - if (csetch, unich) not in self.pass_enctest: - self.assertEqual(unich.encode(self.encoding), csetch) - if (csetch, unich) not in self.pass_dectest: - self.assertEqual(unicode(csetch, self.encoding), unich) + self._testpoint(csetch, unich) + + def test_mapping_supplemental(self): + for mapping in self.supmaps: + self._testpoint(*mapping) + + def _testpoint(self, csetch, unich): + if (csetch, unich) not in self.pass_enctest: + self.assertEqual(unich.encode(self.encoding), csetch) + if (csetch, unich) not in self.pass_dectest: + self.assertEqual(unicode(csetch, self.encoding), unich) def load_teststring(encoding): etxt = open(os.path.join('sampletexts', encoding) + '.txt').read() 1.1 cjkcodecs/tests/test_mapping_big5.py Index: test_mapping_big5.py =================================================================== #!/usr/bin/env python # # test_mapping_big5.py: Mapping test for BIG5 codec # # Copyright (C) 2003 Hye-Shik Chang <pe...@Fr...>. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # $Id: test_mapping_big5.py,v 1.1 2003/06/20 09:04:53 perky Exp $ # from test import test_support import test_multibytecodec_support import sys, codecs, os import unittest if not os.path.exists('BIG5.TXT'): raise test_support.TestSkipped( 'BIG5.TXT not found, download from http://www.unicode.' 'org/Public/MAPPINGS/OBSOLETE/EASTASIA/OTHER/BIG5.TXT') class TestBIG5Map(test_multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'cjkcodecs.big5' mapfilename = 'BIG5.TXT' def test_main(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestBIG5Map)) test_support.run_suite(suite) if __name__ == "__main__": test_main() # ex: ts=8 sts=4 et |