Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 1 | # Codec encoding tests for ISO 2022 encodings. |
| 2 | |
| 3 | from test import support |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 4 | from test import multibytecodec_support |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 5 | import unittest |
| 6 | |
| 7 | COMMON_CODEC_TESTS = ( |
| 8 | # invalid bytes |
| 9 | (b'ab\xFFcd', 'replace', 'ab\uFFFDcd'), |
| 10 | (b'ab\x1Bdef', 'replace', 'ab\x1Bdef'), |
| 11 | (b'ab\x1B$def', 'replace', 'ab\uFFFD'), |
| 12 | ) |
| 13 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 14 | class Test_ISO2022_JP(multibytecodec_support.TestBase, unittest.TestCase): |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 15 | encoding = 'iso2022_jp' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 16 | tstring = multibytecodec_support.load_teststring('iso2022_jp') |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 17 | codectests = COMMON_CODEC_TESTS + ( |
| 18 | (b'ab\x1BNdef', 'replace', 'ab\x1BNdef'), |
| 19 | ) |
| 20 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 21 | class Test_ISO2022_JP2(multibytecodec_support.TestBase, unittest.TestCase): |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 22 | encoding = 'iso2022_jp_2' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 23 | tstring = multibytecodec_support.load_teststring('iso2022_jp') |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 24 | codectests = COMMON_CODEC_TESTS + ( |
| 25 | (b'ab\x1BNdef', 'replace', 'abdef'), |
| 26 | ) |
| 27 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 28 | class Test_ISO2022_KR(multibytecodec_support.TestBase, unittest.TestCase): |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 29 | encoding = 'iso2022_kr' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 30 | tstring = multibytecodec_support.load_teststring('iso2022_kr') |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 31 | codectests = COMMON_CODEC_TESTS + ( |
| 32 | (b'ab\x1BNdef', 'replace', 'ab\x1BNdef'), |
| 33 | ) |
| 34 | |
| 35 | # iso2022_kr.txt cannot be used to test "chunk coding": the escape |
| 36 | # sequence is only written on the first line |
Zachary Ware | 9fe6d86 | 2013-12-08 00:20:35 -0600 | [diff] [blame] | 37 | @unittest.skip('iso2022_kr.txt cannot be used to test "chunk coding"') |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 38 | def test_chunkcoding(self): |
| 39 | pass |
| 40 | |
Victor Stinner | ee49797 | 2011-05-31 00:01:24 +0200 | [diff] [blame] | 41 | if __name__ == "__main__": |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame^] | 42 | unittest.main() |