blob: 00ea1c39dd6fb66f36c1032e9aea3af9a9b47059 [file] [log] [blame]
Victor Stinneree497972011-05-31 00:01:24 +02001# Codec encoding tests for ISO 2022 encodings.
2
R David Murray75d9aca2012-04-09 09:37:52 -04003from test import multibytecodec_support
Victor Stinneree497972011-05-31 00:01:24 +02004import unittest
5
6COMMON_CODEC_TESTS = (
7 # invalid bytes
8 (b'ab\xFFcd', 'replace', 'ab\uFFFDcd'),
9 (b'ab\x1Bdef', 'replace', 'ab\x1Bdef'),
10 (b'ab\x1B$def', 'replace', 'ab\uFFFD'),
11 )
12
R David Murray75d9aca2012-04-09 09:37:52 -040013class Test_ISO2022_JP(multibytecodec_support.TestBase, unittest.TestCase):
Victor Stinneree497972011-05-31 00:01:24 +020014 encoding = 'iso2022_jp'
R David Murray75d9aca2012-04-09 09:37:52 -040015 tstring = multibytecodec_support.load_teststring('iso2022_jp')
Victor Stinneree497972011-05-31 00:01:24 +020016 codectests = COMMON_CODEC_TESTS + (
17 (b'ab\x1BNdef', 'replace', 'ab\x1BNdef'),
18 )
19
R David Murray75d9aca2012-04-09 09:37:52 -040020class Test_ISO2022_JP2(multibytecodec_support.TestBase, unittest.TestCase):
Victor Stinneree497972011-05-31 00:01:24 +020021 encoding = 'iso2022_jp_2'
R David Murray75d9aca2012-04-09 09:37:52 -040022 tstring = multibytecodec_support.load_teststring('iso2022_jp')
Victor Stinneree497972011-05-31 00:01:24 +020023 codectests = COMMON_CODEC_TESTS + (
24 (b'ab\x1BNdef', 'replace', 'abdef'),
25 )
26
R David Murray75d9aca2012-04-09 09:37:52 -040027class Test_ISO2022_KR(multibytecodec_support.TestBase, unittest.TestCase):
Victor Stinneree497972011-05-31 00:01:24 +020028 encoding = 'iso2022_kr'
R David Murray75d9aca2012-04-09 09:37:52 -040029 tstring = multibytecodec_support.load_teststring('iso2022_kr')
Victor Stinneree497972011-05-31 00:01:24 +020030 codectests = COMMON_CODEC_TESTS + (
31 (b'ab\x1BNdef', 'replace', 'ab\x1BNdef'),
32 )
33
34 # iso2022_kr.txt cannot be used to test "chunk coding": the escape
35 # sequence is only written on the first line
Zachary Ware9fe6d862013-12-08 00:20:35 -060036 @unittest.skip('iso2022_kr.txt cannot be used to test "chunk coding"')
Victor Stinneree497972011-05-31 00:01:24 +020037 def test_chunkcoding(self):
38 pass
39
Victor Stinneree497972011-05-31 00:01:24 +020040if __name__ == "__main__":
Zachary Ware38c707e2015-04-13 15:00:43 -050041 unittest.main()