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