blob: 87768646fe469d6c2dd477957753b2412dd3e88f [file] [log] [blame]
Victor Stinneree497972011-05-31 00:01:24 +02001# Codec encoding tests for ISO 2022 encodings.
2
3from test import support
R David Murray75d9aca2012-04-09 09:37:52 -04004from test import multibytecodec_support
Victor Stinneree497972011-05-31 00:01:24 +02005import unittest
6
7COMMON_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 Murray75d9aca2012-04-09 09:37:52 -040014class Test_ISO2022_JP(multibytecodec_support.TestBase, unittest.TestCase):
Victor Stinneree497972011-05-31 00:01:24 +020015 encoding = 'iso2022_jp'
R David Murray75d9aca2012-04-09 09:37:52 -040016 tstring = multibytecodec_support.load_teststring('iso2022_jp')
Victor Stinneree497972011-05-31 00:01:24 +020017 codectests = COMMON_CODEC_TESTS + (
18 (b'ab\x1BNdef', 'replace', 'ab\x1BNdef'),
19 )
20
R David Murray75d9aca2012-04-09 09:37:52 -040021class Test_ISO2022_JP2(multibytecodec_support.TestBase, unittest.TestCase):
Victor Stinneree497972011-05-31 00:01:24 +020022 encoding = 'iso2022_jp_2'
R David Murray75d9aca2012-04-09 09:37:52 -040023 tstring = multibytecodec_support.load_teststring('iso2022_jp')
Victor Stinneree497972011-05-31 00:01:24 +020024 codectests = COMMON_CODEC_TESTS + (
25 (b'ab\x1BNdef', 'replace', 'abdef'),
26 )
27
R David Murray75d9aca2012-04-09 09:37:52 -040028class Test_ISO2022_KR(multibytecodec_support.TestBase, unittest.TestCase):
Victor Stinneree497972011-05-31 00:01:24 +020029 encoding = 'iso2022_kr'
R David Murray75d9aca2012-04-09 09:37:52 -040030 tstring = multibytecodec_support.load_teststring('iso2022_kr')
Victor Stinneree497972011-05-31 00:01:24 +020031 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 Ware9fe6d862013-12-08 00:20:35 -060037 @unittest.skip('iso2022_kr.txt cannot be used to test "chunk coding"')
Victor Stinneree497972011-05-31 00:01:24 +020038 def test_chunkcoding(self):
39 pass
40
41def test_main():
42 support.run_unittest(__name__)
43
44if __name__ == "__main__":
45 test_main()