-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_mbstrdecoder.py
More file actions
90 lines (76 loc) · 2.86 KB
/
Copy pathtest_mbstrdecoder.py
File metadata and controls
90 lines (76 loc) · 2.86 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""
import pytest
from mbstrdecoder import MultiByteStrDecoder
nan = float("nan")
inf = float("inf")
class Test_to_MultiByteStrDecoder_repr:
@pytest.mark.parametrize(
["value", "expected"],
[
["吾輩は猫である", "codec=unicode, unicode=吾輩は猫である"],
],
)
def test_normal(self, value, expected):
decoder = MultiByteStrDecoder(value)
assert str(decoder) == expected
class Test_to_MultiByteStrDecoder_unicode:
@pytest.mark.parametrize(["value", "expected"], [[b"", ""], [b"abcd", "abcd"]])
def test_normal_unicode_str(self, value, expected):
decoder = MultiByteStrDecoder(value)
assert decoder.unicode_str == expected
@pytest.mark.parametrize(
["value", "encode", "expected"],
[
["", "utf8", "unicode"],
["abcdefgh", "ascii", "ascii"],
["吾輩は猫である", "utf8", "utf_8"],
],
)
def test_normal_codec(self, value, encode, expected):
decoder = MultiByteStrDecoder(value.encode(encode))
assert decoder.codec == expected
assert decoder.unicode_str == value
@pytest.mark.parametrize(
["value", "encode", "expected", "codec_candidates"],
[
["abcdefgh", "ascii", "ascii", ["utf_32_le", "utf_32"]],
["吾輩は猫である", "utf8", "utf_8", ["utf_32_le", "ascii"]],
["吾輩は猫である", "utf8", "utf_8", None],
["吾輩は猫である", "utf8", "utf_8", []],
],
)
def test_normal_codec_candidate(self, value, encode, expected, codec_candidates):
decoder = MultiByteStrDecoder(value.encode(encode), codec_candidates)
assert decoder.codec == expected
assert decoder.unicode_str == value
@pytest.mark.parametrize(
["value", "codec"],
[
["いろはにほへと", "utf_7"],
[
"RKBTqn1G9HIZ9onY9mCklj3+8ye7WBmu0xKMqp3ORT3pMgR5m73VXAR/5YrTZTGernMYLCPYdwIMewFY+6xOZmWwCrXjfw3sO2dYLubh9EIMrc/XEvAhMFd969G2yQkyFTNf9M8Ag94QCuBk51yQLSbxgmxJTqEw6bdC4gNTI44=", # noqa
"ascii",
],
["マルチバイト文字", "utf_8"],
["ABC", "utf_8"],
["吾輩は猫である", "utf_16"],
],
)
def test_normal_encoding(self, value, codec):
decoder = MultiByteStrDecoder(value.encode(codec))
assert decoder.codec == codec
assert decoder.unicode_str == value
@pytest.mark.parametrize(
["value", "expected"],
[
[None, ValueError],
[True, ValueError],
[[], ValueError],
[1, ValueError],
],
)
def test_exception(self, value, expected):
with pytest.raises(expected):
MultiByteStrDecoder(value)