perky 03/01/13 00:38:37
Modified: test CodecTestBase.py test_johab.py
Log:
Add PEP293 unit test framework
Revision Changes Path
1.11 +44 -1 KoreanCodecs/test/CodecTestBase.py
Index: CodecTestBase.py
===================================================================
RCS file: /cvsroot/koco/KoreanCodecs/test/CodecTestBase.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CodecTestBase.py 12 Jan 2003 22:54:13 -0000 1.10
+++ CodecTestBase.py 13 Jan 2003 08:38:36 -0000 1.11
@@ -16,7 +16,7 @@
# along with KoreanCodecs; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# $Id: CodecTestBase.py,v 1.10 2003/01/12 22:54:13 perky Exp $
+# $Id: CodecTestBase.py,v 1.11 2003/01/13 08:38:36 perky Exp $
#
import StringIO
@@ -43,6 +43,7 @@
errortests = None # must set. error test tuple
roundtriptest = 1 # set if roundtrip is possible with unicode
+ has_iso10646 = 0 # set if this encoding contains whole iso10646 map
def setUp(self):
if not self.textfile_chunk:
@@ -77,6 +78,48 @@
except UnicodeError:
continue
self.fail('UnicodeError expected')
+
+
+class TestCodecErrorCallback:
+
+ if sys.hexversion >= 0x2030000:
+ def test_xmlcharrefreplace(self):
+ s = u"\u30b9\u30d1\u30e2 \xe4nd eggs"
+ self.assertEqual(
+ s.encode(self.encoding, "xmlcharrefreplace"),
+ "スパモ änd eggs"
+ )
+
+ def test_xmlcharnamereplace(self):
+ import htmlentitydefs
+
+ names = {}
+ for (key, value) in htmlentitydefs.entitydefs.items():
+ if len(value)==1:
+ names[unicode(value, 'latin-1')] = \
+ unicode(key, self.encoding)
+ else:
+ names[unichr(int(value[2:-1]))] = \
+ unicode(key, self.encoding)
+
+ 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\u20ac\u232a"
+ sout = "«ℜ» = ⟨ሴ€⟩"
+ self.assertEqual(sin.encode(self.encoding,
+ "test.xmlcharnamereplace"), sout)
class TestStreamReader:
1.5 +5 -2 KoreanCodecs/test/test_johab.py
Index: test_johab.py
===================================================================
RCS file: /cvsroot/koco/KoreanCodecs/test/test_johab.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- test_johab.py 12 Jan 2003 22:54:13 -0000 1.4
+++ test_johab.py 13 Jan 2003 08:38:36 -0000 1.5
@@ -16,12 +16,15 @@
# along with KoreanCodecs; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# $Id: test_johab.py,v 1.4 2003/01/12 22:54:13 perky Exp $
+# $Id: test_johab.py,v 1.5 2003/01/13 08:38:36 perky Exp $
#
import CodecTestBase
-class TestJOHAB(CodecTestBase.TestStreamReader, CodecTestBase.CodecTestBase):
+class TestJOHAB(CodecTestBase.TestCodecErrorCallback,
+ #CodecTestBase.TestStreamWriter,
+ CodecTestBase.TestStreamReader,
+ CodecTestBase.CodecTestBase):
encoding = 'korean.johab'
errortests = (
# invalid bytes
|