PageRenderTime 243ms CodeModel.GetById 141ms app.highlight 6ms RepoModel.GetById 95ms app.codeStats 0ms

/Lib/test/test_charmapcodec.py

http://unladen-swallow.googlecode.com/
Python | 56 lines | 34 code | 11 blank | 11 comment | 2 complexity | 8536b26f5ad81fbfc3cb8e20e5bd891b MD5 | raw file
 1""" Python character mapping codec test
 2
 3This uses the test codec in testcodec.py and thus also tests the
 4encodings package lookup scheme.
 5
 6Written by Marc-Andre Lemburg (mal@lemburg.com).
 7
 8(c) Copyright 2000 Guido van Rossum.
 9
10"""#"
11
12import test.test_support, unittest
13
14import codecs
15
16# Register a search function which knows about our codec
17def codec_search_function(encoding):
18    if encoding == 'testcodec':
19        from test import testcodec
20        return tuple(testcodec.getregentry())
21    return None
22
23codecs.register(codec_search_function)
24
25# test codec's name (see test/testcodec.py)
26codecname = 'testcodec'
27
28class 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')
35
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')
42
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')
48
49    def test_maptoundefined(self):
50        self.assertRaises(UnicodeError, unicode, 'abc\001', codecname)
51
52def test_main():
53    test.test_support.run_unittest(CharmapCodecTest)
54
55if __name__ == "__main__":
56    test_main()