[KoCo-CVS] [Commit] iconvcodec test_iconv_codec.py
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-04-20 20:48:12
|
perky 03/04/20 13:48:11 Modified: . test_iconv_codec.py Log: Don't test error callbacks on python2.2 and under Revision Changes Path 1.2 +44 -43 iconvcodec/test_iconv_codec.py Index: test_iconv_codec.py =================================================================== RCS file: /cvsroot/koco/iconvcodec/test_iconv_codec.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- test_iconv_codec.py 20 Apr 2003 18:17:56 -0000 1.1 +++ test_iconv_codec.py 20 Apr 2003 20:48:06 -0000 1.2 @@ -24,12 +24,12 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $Id: test_iconv_codec.py,v 1.1 2003/04/20 18:17:56 perky Exp $ +# $Id: test_iconv_codec.py,v 1.2 2003/04/20 20:48:06 perky Exp $ from StringIO import StringIO import sys, codecs import unittest -from encodings import iconv_codec +import iconv_codec from test import test_support teststring_euc_kr = ( @@ -121,47 +121,48 @@ else: self.assertRaises(UnicodeError, func, source, scheme) - def test_xmlcharrefreplace(self): - if self.has_iso10646: - return - - s = u"\u0b13\u0b23\u0b60 nd eggs" - self.assertEqual( - self.encode(s, "xmlcharrefreplace")[0], - "ଓଣୠ nd eggs" - ) - - def test_customreplace(self): - if self.has_iso10646: - return - - import htmlentitydefs - - names = {} - for (key, value) in htmlentitydefs.entitydefs.items(): - if len(value)==1: - names[value.decode('latin-1')] = self.decode(key)[0] - else: - names[unichr(int(value[2:-1]))] = self.decode(key)[0] - - def xmlcharnamereplace(exc): - if not isinstance(exc, UnicodeEncodeError): - raise TypeError("don't know how to handle %r" % exc) - l = [] - for c in exc.object[exc.start:exc.end]: - try: - l.append(u"&%s;" % names[c]) - except KeyError: - l.append(u"&#%d;" % ord(c)) - return (u"".join(l), exc.end) - - codecs.register_error( - "test.xmlcharnamereplace", xmlcharnamereplace) - - sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" - sout = "«ℜ» = ⟨ሴ⟩" - self.assertEqual(self.encode(sin, - "test.xmlcharnamereplace")[0], sout) + if sys.hexversion >= 0x02030000: + def test_xmlcharrefreplace(self): + if self.has_iso10646: + return + + s = u"\u0b13\u0b23\u0b60 nd eggs" + self.assertEqual( + self.encode(s, "xmlcharrefreplace")[0], + "ଓଣୠ nd eggs" + ) + + def test_customreplace(self): + if self.has_iso10646: + return + + import htmlentitydefs + + names = {} + for (key, value) in htmlentitydefs.entitydefs.items(): + if len(value)==1: + names[value.decode('latin-1')] = self.decode(key)[0] + else: + names[unichr(int(value[2:-1]))] = self.decode(key)[0] + + def xmlcharnamereplace(exc): + if not isinstance(exc, UnicodeEncodeError): + raise TypeError("don't know how to handle %r" % exc) + l = [] + for c in exc.object[exc.start:exc.end]: + try: + l.append(u"&%s;" % names[c]) + except KeyError: + l.append(u"&#%d;" % ord(c)) + return (u"".join(l), exc.end) + + codecs.register_error( + "test.xmlcharnamereplace", xmlcharnamereplace) + + sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" + sout = "«ℜ» = ⟨ሴ⟩" + self.assertEqual(self.encode(sin, + "test.xmlcharnamereplace")[0], sout) def test_streamreader(self): UTF8Writer = codecs.lookup('utf-8')[3] |