summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_charmapcodec.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2003-02-14 11:21:53 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2003-02-14 11:21:53 (GMT)
commitbb2734ab65970eba1d361932f12843799496d1ea (patch)
tree367bc351da68dfcfafafa701a2961256782853d7 /Lib/test/test_charmapcodec.py
parent002a5de2026d460d328f6c06725083485cd38fd1 (diff)
downloadcpython-bb2734ab65970eba1d361932f12843799496d1ea.zip
cpython-bb2734ab65970eba1d361932f12843799496d1ea.tar.gz
cpython-bb2734ab65970eba1d361932f12843799496d1ea.tar.bz2
Port test_charmapcodec to PyUnit. From SF patch #662807
Diffstat (limited to 'Lib/test/test_charmapcodec.py')
-rw-r--r--Lib/test/test_charmapcodec.py60
1 files changed, 32 insertions, 28 deletions
diff --git a/Lib/test/test_charmapcodec.py b/Lib/test/test_charmapcodec.py
index af7d434..337d6e5 100644
--- a/Lib/test/test_charmapcodec.py
+++ b/Lib/test/test_charmapcodec.py
@@ -9,35 +9,39 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
"""#"
-def check(a, b):
- if a != b:
- print '*** check failed: %s != %s' % (repr(a), repr(b))
- else:
- print '%s == %s: OK' % (a, b)
+import test.test_support, unittest
# test codec's full path name (see test/testcodec.py)
codecname = 'test.testcodec'
-check(unicode('abc', codecname), u'abc')
-check(unicode('xdef', codecname), u'abcdef')
-check(unicode('defx', codecname), u'defabc')
-check(unicode('dxf', codecname), u'dabcf')
-check(unicode('dxfx', codecname), u'dabcfabc')
-
-check(u'abc'.encode(codecname), 'abc')
-check(u'xdef'.encode(codecname), 'abcdef')
-check(u'defx'.encode(codecname), 'defabc')
-check(u'dxf'.encode(codecname), 'dabcf')
-check(u'dxfx'.encode(codecname), 'dabcfabc')
-
-check(unicode('ydef', codecname), u'def')
-check(unicode('defy', codecname), u'def')
-check(unicode('dyf', codecname), u'df')
-check(unicode('dyfy', codecname), u'df')
-
-try:
- unicode('abc\001', codecname)
-except UnicodeError:
- print '\\001 maps to undefined: OK'
-else:
- print '*** check failed: \\001 does not map to undefined'
+class CharmapCodecTest(unittest.TestCase):
+ def test_constructorx(self):
+ self.assertEquals(unicode('abc', codecname), u'abc')
+ self.assertEquals(unicode('xdef', codecname), u'abcdef')
+ self.assertEquals(unicode('defx', codecname), u'defabc')
+ self.assertEquals(unicode('dxf', codecname), u'dabcf')
+ self.assertEquals(unicode('dxfx', codecname), u'dabcfabc')
+
+ def test_encodex(self):
+ self.assertEquals(u'abc'.encode(codecname), 'abc')
+ self.assertEquals(u'xdef'.encode(codecname), 'abcdef')
+ self.assertEquals(u'defx'.encode(codecname), 'defabc')
+ self.assertEquals(u'dxf'.encode(codecname), 'dabcf')
+ self.assertEquals(u'dxfx'.encode(codecname), 'dabcfabc')
+
+ def test_constructory(self):
+ self.assertEquals(unicode('ydef', codecname), u'def')
+ self.assertEquals(unicode('defy', codecname), u'def')
+ self.assertEquals(unicode('dyf', codecname), u'df')
+ self.assertEquals(unicode('dyfy', codecname), u'df')
+
+ def test_maptoundefined(self):
+ self.assertRaises(UnicodeError, unicode, 'abc\001', codecname)
+
+def test_main():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(CharmapCodecTest))
+ test.test_support.run_suite(suite)
+
+if __name__ == "__main__":
+ test_main()