annotate Lib/test/test_charmapcodec.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 614c84670c63
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15795
63c0483eff68 Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents: 15750
diff changeset
1 """ Python character mapping codec test
63c0483eff68 Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents: 15750
diff changeset
2
63c0483eff68 Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents: 15750
diff changeset
3 This uses the test codec in testcodec.py and thus also tests the
63c0483eff68 Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents: 15750
diff changeset
4 encodings package lookup scheme.
15750
d67cfcc0683e This patch adds a new feature to the builtin charmap codec:
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
5
d67cfcc0683e This patch adds a new feature to the builtin charmap codec:
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
6 Written by Marc-Andre Lemburg (mal@lemburg.com).
d67cfcc0683e This patch adds a new feature to the builtin charmap codec:
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
7
d67cfcc0683e This patch adds a new feature to the builtin charmap codec:
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
8 (c) Copyright 2000 Guido van Rossum.
d67cfcc0683e This patch adds a new feature to the builtin charmap codec:
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
9
d67cfcc0683e This patch adds a new feature to the builtin charmap codec:
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
10 """#"
d67cfcc0683e This patch adds a new feature to the builtin charmap codec:
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
11
27892
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
12 import test.test_support, unittest
15795
63c0483eff68 Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents: 15750
diff changeset
13
36598
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
14 import codecs
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
15
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
16 # Register a search function which knows about our codec
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
17 def codec_search_function(encoding):
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
18 if encoding == 'testcodec':
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
19 from test import testcodec
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
20 return tuple(testcodec.getregentry())
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
21 return None
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
22
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
23 codecs.register(codec_search_function)
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
24
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
25 # test codec's name (see test/testcodec.py)
9d97c8338d4c Fix the encodings package codec search function to only search
Marc-André Lemburg <mal@egenix.com>
parents: 28917
diff changeset
26 codecname = 'testcodec'
15977
f16545f58345 Whitespace normalization. Leaving tokenize_tests.py alone for now.
Tim Peters <tim.peters@gmail.com>
parents: 15935
diff changeset
27
27892
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
28 class CharmapCodecTest(unittest.TestCase):
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
29 def test_constructorx(self):
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
30 self.assertEqual(unicode('abc', codecname), u'abc')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
31 self.assertEqual(unicode('xdef', codecname), u'abcdef')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
32 self.assertEqual(unicode('defx', codecname), u'defabc')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
33 self.assertEqual(unicode('dxf', codecname), u'dabcf')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
34 self.assertEqual(unicode('dxfx', codecname), u'dabcfabc')
15795
63c0483eff68 Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents: 15750
diff changeset
35
27892
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
36 def test_encodex(self):
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
37 self.assertEqual(u'abc'.encode(codecname), 'abc')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
38 self.assertEqual(u'xdef'.encode(codecname), 'abcdef')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
39 self.assertEqual(u'defx'.encode(codecname), 'defabc')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
40 self.assertEqual(u'dxf'.encode(codecname), 'dabcf')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
41 self.assertEqual(u'dxfx'.encode(codecname), 'dabcfabc')
15750
d67cfcc0683e This patch adds a new feature to the builtin charmap codec:
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
42
27892
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
43 def test_constructory(self):
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
44 self.assertEqual(unicode('ydef', codecname), u'def')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
45 self.assertEqual(unicode('defy', codecname), u'def')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
46 self.assertEqual(unicode('dyf', codecname), u'df')
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 36598
diff changeset
47 self.assertEqual(unicode('dyfy', codecname), u'df')
15795
63c0483eff68 Moved the test codec definition to a new module and updated the test and
Marc-André Lemburg <mal@egenix.com>
parents: 15750
diff changeset
48
27892
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
49 def test_maptoundefined(self):
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
50 self.assertRaises(UnicodeError, unicode, 'abc\001', codecname)
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
51
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
52 def test_main():
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27892
diff changeset
53 test.test_support.run_unittest(CharmapCodecTest)
27892
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
54
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
55 if __name__ == "__main__":
d8b06012b381 Port test_charmapcodec to PyUnit. From SF patch #662807
Walter Dörwald <walter@livinglogic.de>
parents: 19449
diff changeset
56 test_main()