ยปCore Development>Code coverage>Lib/test/test_charmapcodec.py

Python code coverage for Lib/test/test_charmapcodec.py

#countcontent
1n/a""" Python character mapping codec test
2n/a
3n/aThis uses the test codec in testcodec.py and thus also tests the
4n/aencodings package lookup scheme.
5n/a
6n/aWritten by Marc-Andre Lemburg (mal@lemburg.com).
7n/a
8n/a(c) Copyright 2000 Guido van Rossum.
9n/a
10n/a"""#"
11n/a
12n/aimport unittest
13n/a
14n/aimport codecs
15n/a
16n/a# Register a search function which knows about our codec
17n/adef codec_search_function(encoding):
18n/a if encoding == 'testcodec':
19n/a from test import testcodec
20n/a return tuple(testcodec.getregentry())
21n/a return None
22n/a
23n/acodecs.register(codec_search_function)
24n/a
25n/a# test codec's name (see test/testcodec.py)
26n/acodecname = 'testcodec'
27n/a
28n/aclass CharmapCodecTest(unittest.TestCase):
29n/a def test_constructorx(self):
30n/a self.assertEqual(str(b'abc', codecname), 'abc')
31n/a self.assertEqual(str(b'xdef', codecname), 'abcdef')
32n/a self.assertEqual(str(b'defx', codecname), 'defabc')
33n/a self.assertEqual(str(b'dxf', codecname), 'dabcf')
34n/a self.assertEqual(str(b'dxfx', codecname), 'dabcfabc')
35n/a
36n/a def test_encodex(self):
37n/a self.assertEqual('abc'.encode(codecname), b'abc')
38n/a self.assertEqual('xdef'.encode(codecname), b'abcdef')
39n/a self.assertEqual('defx'.encode(codecname), b'defabc')
40n/a self.assertEqual('dxf'.encode(codecname), b'dabcf')
41n/a self.assertEqual('dxfx'.encode(codecname), b'dabcfabc')
42n/a
43n/a def test_constructory(self):
44n/a self.assertEqual(str(b'ydef', codecname), 'def')
45n/a self.assertEqual(str(b'defy', codecname), 'def')
46n/a self.assertEqual(str(b'dyf', codecname), 'df')
47n/a self.assertEqual(str(b'dyfy', codecname), 'df')
48n/a
49n/a def test_maptoundefined(self):
50n/a self.assertRaises(UnicodeError, str, b'abc\001', codecname)
51n/a
52n/aif __name__ == "__main__":
53n/a unittest.main()