2001-01-10 06:21:11 -04:00
|
|
|
""" Python character mapping codec test
|
|
|
|
|
|
|
|
This uses the test codec in testcodec.py and thus also tests the
|
|
|
|
encodings package lookup scheme.
|
2001-01-06 11:09:57 -04:00
|
|
|
|
|
|
|
Written by Marc-Andre Lemburg (mal@lemburg.com).
|
|
|
|
|
|
|
|
(c) Copyright 2000 Guido van Rossum.
|
|
|
|
|
|
|
|
"""#"
|
|
|
|
|
2003-02-14 07:21:53 -04:00
|
|
|
import test.test_support, unittest
|
2001-01-06 11:09:57 -04:00
|
|
|
|
2006-02-19 11:22:22 -04:00
|
|
|
import codecs
|
|
|
|
|
|
|
|
# Register a search function which knows about our codec
|
|
|
|
def codec_search_function(encoding):
|
|
|
|
if encoding == 'testcodec':
|
|
|
|
from test import testcodec
|
|
|
|
return tuple(testcodec.getregentry())
|
|
|
|
return None
|
|
|
|
|
|
|
|
codecs.register(codec_search_function)
|
|
|
|
|
|
|
|
# test codec's name (see test/testcodec.py)
|
|
|
|
codecname = 'testcodec'
|
2001-01-17 22:22:22 -04:00
|
|
|
|
2003-02-14 07:21:53 -04:00
|
|
|
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():
|
2003-05-01 14:45:56 -03:00
|
|
|
test.test_support.run_unittest(CharmapCodecTest)
|
2003-02-14 07:21:53 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|