|
6 | 6 |
|
7 | 7 | CODEC_NAME = "idna2008" |
8 | 8 |
|
| 9 | +# (decoded, encoded) pairs derived from CPython's Lib/test/test_codecs.py |
| 10 | +INCREMENTAL_TESTS = ( |
| 11 | + ("python.org", b"python.org"), |
| 12 | + ("python.org.", b"python.org."), |
| 13 | + ("pyth\xf6n.org", b"xn--pythn-mua.org"), |
| 14 | + ("pyth\xf6n.org.", b"xn--pythn-mua.org."), |
| 15 | +) |
| 16 | + |
9 | 17 |
|
10 | 18 | class IDNACodecTests(unittest.TestCase): |
11 | 19 | def setUp(self): |
@@ -58,16 +66,7 @@ def encode(obj): |
58 | 66 | return self.idnatests.test_encode(encode=encode) |
59 | 67 |
|
60 | 68 | def testIncrementalDecoder(self): |
61 | | - # Tests derived from Python standard library test/test_codecs.py |
62 | | - |
63 | | - incremental_tests = ( |
64 | | - ("python.org", b"python.org"), |
65 | | - ("python.org.", b"python.org."), |
66 | | - ("pyth\xf6n.org", b"xn--pythn-mua.org"), |
67 | | - ("pyth\xf6n.org.", b"xn--pythn-mua.org."), |
68 | | - ) |
69 | | - |
70 | | - for decoded, encoded in incremental_tests: |
| 69 | + for decoded, encoded in INCREMENTAL_TESTS: |
71 | 70 | self.assertEqual( |
72 | 71 | "".join(codecs.iterdecode((bytes([c]) for c in encoded), CODEC_NAME)), |
73 | 72 | decoded, |
@@ -106,15 +105,7 @@ def testIncrementalDecoder(self): |
106 | 105 | self.assertEqual(decoder.decode(b"", True), "") |
107 | 106 |
|
108 | 107 | def testIncrementalEncoder(self): |
109 | | - # Tests derived from Python standard library test/test_codecs.py |
110 | | - |
111 | | - incremental_tests = ( |
112 | | - ("python.org", b"python.org"), |
113 | | - ("python.org.", b"python.org."), |
114 | | - ("pyth\xf6n.org", b"xn--pythn-mua.org"), |
115 | | - ("pyth\xf6n.org.", b"xn--pythn-mua.org."), |
116 | | - ) |
117 | | - for decoded, encoded in incremental_tests: |
| 108 | + for decoded, encoded in INCREMENTAL_TESTS: |
118 | 109 | self.assertEqual(b"".join(codecs.iterencode(decoded, CODEC_NAME)), encoded) |
119 | 110 |
|
120 | 111 | encoder = codecs.getincrementalencoder(CODEC_NAME)() |
|
0 commit comments