Kaydet (Commit) bb2734ab authored tarafından Walter Dörwald's avatar Walter Dörwald

Port test_charmapcodec to PyUnit. From SF patch #662807

üst 002a5de2
test_charmapcodec
abc == abc: OK
abcdef == abcdef: OK
defabc == defabc: OK
dabcf == dabcf: OK
dabcfabc == dabcfabc: OK
abc == abc: OK
abcdef == abcdef: OK
defabc == defabc: OK
dabcf == dabcf: OK
dabcfabc == dabcfabc: OK
def == def: OK
def == def: OK
df == df: OK
df == df: OK
\001 maps to undefined: OK
...@@ -9,35 +9,39 @@ Written by Marc-Andre Lemburg (mal@lemburg.com). ...@@ -9,35 +9,39 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
"""#" """#"
def check(a, b): import test.test_support, unittest
if a != b:
print '*** check failed: %s != %s' % (repr(a), repr(b))
else:
print '%s == %s: OK' % (a, b)
# test codec's full path name (see test/testcodec.py) # test codec's full path name (see test/testcodec.py)
codecname = 'test.testcodec' codecname = 'test.testcodec'
check(unicode('abc', codecname), u'abc') class CharmapCodecTest(unittest.TestCase):
check(unicode('xdef', codecname), u'abcdef') def test_constructorx(self):
check(unicode('defx', codecname), u'defabc') self.assertEquals(unicode('abc', codecname), u'abc')
check(unicode('dxf', codecname), u'dabcf') self.assertEquals(unicode('xdef', codecname), u'abcdef')
check(unicode('dxfx', codecname), u'dabcfabc') self.assertEquals(unicode('defx', codecname), u'defabc')
self.assertEquals(unicode('dxf', codecname), u'dabcf')
check(u'abc'.encode(codecname), 'abc') self.assertEquals(unicode('dxfx', codecname), u'dabcfabc')
check(u'xdef'.encode(codecname), 'abcdef')
check(u'defx'.encode(codecname), 'defabc') def test_encodex(self):
check(u'dxf'.encode(codecname), 'dabcf') self.assertEquals(u'abc'.encode(codecname), 'abc')
check(u'dxfx'.encode(codecname), 'dabcfabc') self.assertEquals(u'xdef'.encode(codecname), 'abcdef')
self.assertEquals(u'defx'.encode(codecname), 'defabc')
check(unicode('ydef', codecname), u'def') self.assertEquals(u'dxf'.encode(codecname), 'dabcf')
check(unicode('defy', codecname), u'def') self.assertEquals(u'dxfx'.encode(codecname), 'dabcfabc')
check(unicode('dyf', codecname), u'df')
check(unicode('dyfy', codecname), u'df') def test_constructory(self):
self.assertEquals(unicode('ydef', codecname), u'def')
try: self.assertEquals(unicode('defy', codecname), u'def')
unicode('abc\001', codecname) self.assertEquals(unicode('dyf', codecname), u'df')
except UnicodeError: self.assertEquals(unicode('dyfy', codecname), u'df')
print '\\001 maps to undefined: OK'
else: def test_maptoundefined(self):
print '*** check failed: \\001 does not map to undefined' 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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment