File: common_iso_2022_jp.py

package info (click to toggle)
python-japanese-codecs 1.4.4-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,936 kB
  • ctags: 3,437
  • sloc: python: 28,245; ansic: 1,365; makefile: 54; sh: 3
file content (27 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Tamito KAJIYAMA <26 September 2001>

import basetests

def test(encoding):
    file = "text.iso-2022-jp"
    basetests.roundrobin_tests(file, encoding)
    basetests.test_jis_x_0201_roman(encoding)
    basetests.test_stream(file, encoding, 1)
    basetests.test_error_handling(encoding, (
        # invalid bytes in JIS X 0208
        ("abc\033$B\x00\x00\x30\x21\033(B", "strict",  None),
        ("abc\033$B\x00\x00\x30\x21\033(B", "replace", u"abc\ufffd\u4e9c"),
        ("abc\033$B\x00\x00\x30\x21\033(B", "ignore",  u"abc\u4e9c"),
        # invalid byte in JIS X 0201 Roman
        ("abc\033(J\x80xyz\033(B", "strict",  None),
        ("abc\033(J\x80xyz\033(B", "replace", u"abc\ufffdxyz"),
        ("abc\033(J\x80xyz\033(B", "ignore",  u"abcxyz"),
        # a character that has no corresponding character in ISO-2022-JP
        (u"abc\ufffd\u4e9c", "strict",  None),
        (u"abc\ufffd\u4e9c", "replace", "abc\033$B\x22\x2e\x30\x21\033(B"),
        (u"abc\ufffd\u4e9c", "ignore",  "abc\033$B\x30\x21\033(B"),
        # unknown designation (GB 2312)
        ("abc\033$A\x30\x21\033(B", "strict",  None),
        ("abc\033$A\x30\x21\033(B", "replace", None),
        ("abc\033$A\x30\x21\033(B", "ignore",  None),
        ))