Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_charmapcodec.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 9fe76c26ea9f |
| children |
| 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 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
41836
diff
changeset
|
12 import 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): |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
30 self.assertEqual(str(b'abc', codecname), 'abc') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
31 self.assertEqual(str(b'xdef', codecname), 'abcdef') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
32 self.assertEqual(str(b'defx', codecname), 'defabc') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
33 self.assertEqual(str(b'dxf', codecname), 'dabcf') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
34 self.assertEqual(str(b'dxfx', codecname), '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): |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
37 self.assertEqual('abc'.encode(codecname), b'abc') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
38 self.assertEqual('xdef'.encode(codecname), b'abcdef') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
39 self.assertEqual('defx'.encode(codecname), b'defabc') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
40 self.assertEqual('dxf'.encode(codecname), b'dabcf') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
41 self.assertEqual('dxfx'.encode(codecname), b'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): |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
44 self.assertEqual(str(b'ydef', codecname), 'def') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
45 self.assertEqual(str(b'defy', codecname), 'def') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
46 self.assertEqual(str(b'dyf', codecname), 'df') |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
47201
diff
changeset
|
47 self.assertEqual(str(b'dyfy', codecname), '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): |
|
41836
709f82e2a55c
Fix testcodec.py and test_charmapcodec.py
Walter Dörwald <walter@livinglogic.de>
parents:
41575
diff
changeset
|
50 self.assertRaises(UnicodeError, str, b'abc\001', codecname) |
|
27892
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(): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
41836
diff
changeset
|
53 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() |
