1 """ Python character mapping codec test
3 This uses the test codec in testcodec.py and thus also tests the
4 encodings package lookup scheme.
6 Written by Marc-Andre Lemburg (mal@lemburg.com).
8 (c) Copyright 2000 Guido van Rossum.
12 import test
.test_support
, unittest
16 # Register a search function which knows about our codec
17 def codec_search_function(encoding
):
18 if encoding
== 'testcodec':
19 from test
import testcodec
20 return tuple(testcodec
.getregentry())
23 codecs
.register(codec_search_function
)
25 # test codec's name (see test/testcodec.py)
26 codecname
= 'testcodec'
28 class CharmapCodecTest(unittest
.TestCase
):
29 def test_constructorx(self
):
30 self
.assertEquals(unicode('abc', codecname
), u
'abc')
31 self
.assertEquals(unicode('xdef', codecname
), u
'abcdef')
32 self
.assertEquals(unicode('defx', codecname
), u
'defabc')
33 self
.assertEquals(unicode('dxf', codecname
), u
'dabcf')
34 self
.assertEquals(unicode('dxfx', codecname
), u
'dabcfabc')
36 def test_encodex(self
):
37 self
.assertEquals(u
'abc'.encode(codecname
), 'abc')
38 self
.assertEquals(u
'xdef'.encode(codecname
), 'abcdef')
39 self
.assertEquals(u
'defx'.encode(codecname
), 'defabc')
40 self
.assertEquals(u
'dxf'.encode(codecname
), 'dabcf')
41 self
.assertEquals(u
'dxfx'.encode(codecname
), 'dabcfabc')
43 def test_constructory(self
):
44 self
.assertEquals(unicode('ydef', codecname
), u
'def')
45 self
.assertEquals(unicode('defy', codecname
), u
'def')
46 self
.assertEquals(unicode('dyf', codecname
), u
'df')
47 self
.assertEquals(unicode('dyfy', codecname
), u
'df')
49 def test_maptoundefined(self
):
50 self
.assertRaises(UnicodeError, unicode, 'abc\001', codecname
)
53 test
.test_support
.run_unittest(CharmapCodecTest
)
55 if __name__
== "__main__":