|
1 | 1 | # coding: utf-8 |
| 2 | +import pytest |
| 3 | + |
2 | 4 | from unicodec import decode_content |
3 | 5 |
|
4 | 6 |
|
5 | | -def test_basic_usage(): |
6 | | - # type: () -> None |
| 7 | +def test_basic_usage(): # type: () -> None |
7 | 8 | assert decode_content(b"asdf") == "asdf" |
8 | 9 |
|
9 | 10 |
|
10 | | -def test_input_bytess(): |
11 | | - # type: () -> None |
| 11 | +def test_input_bytess(): # type: () -> None |
12 | 12 | # fmt: off |
13 | 13 | assert decode_content(u"крокодил".encode("utf-8")) == u"крокодил" |
14 | 14 | # fmt: on |
15 | 15 |
|
16 | 16 |
|
17 | | -def test_input_str(): |
18 | | - # type: () -> None |
| 17 | +def test_input_str(): # type: () -> None |
19 | 18 | # fmt: off |
20 | 19 | assert decode_content(u"крокодил") == u"крокодил" |
21 | 20 | # fmt: on |
22 | 21 |
|
23 | 22 |
|
24 | | -def test_arg_decode_entities_default(): |
25 | | - # type: () -> None |
| 23 | +def test_arg_decode_entities_default(): # type: () -> None |
26 | 24 | # fmt: off |
27 | 25 | assert decode_content("©") == u"©" |
28 | 26 | # fmt: on |
29 | 27 |
|
30 | 28 |
|
31 | | -def test_arg_decode_entities_false(): |
32 | | - # type: () -> None |
| 29 | +def test_arg_decode_entities_false(): # type: () -> None |
33 | 30 | assert decode_content("©", decode_entities=False) == "©" |
34 | 31 |
|
35 | 32 |
|
36 | | -def test_arg_remove_null_bytes_default(): |
37 | | - # type: () -> None |
| 33 | +def test_arg_remove_null_bytes_default(): # type: () -> None |
38 | 34 | assert decode_content("as\x00df") == "asdf" |
39 | 35 |
|
40 | 36 |
|
41 | | -def test_arg_remove_null_bytes_false(): |
42 | | - # type: () -> None |
| 37 | +def test_arg_remove_null_bytes_false(): # type: () -> None |
43 | 38 | assert decode_content("as\x00df", remove_null_bytes=False) == "as\x00df" |
44 | 39 |
|
45 | 40 |
|
46 | | -def test_arg_encoding_default(): |
47 | | - # type: () -> None |
| 41 | +def test_arg_encoding_default(): # type: () -> None |
48 | 42 | # fmt: off |
49 | 43 | assert decode_content(u"крокодил".encode("utf-8")) == u"крокодил" |
50 | 44 | # fmt: on |
51 | 45 |
|
52 | 46 |
|
53 | | -def test_arg_encoding_explicit(): |
54 | | - # type: () -> None |
| 47 | +def test_arg_encoding_explicit(): # type: () -> None |
55 | 48 | # fmt: off |
56 | 49 | assert decode_content(u"крокодил".encode("cp1251"), encoding="cp1251") == ( |
57 | 50 | u"крокодил" |
58 | 51 | ) |
59 | 52 | # fmt: on |
| 53 | + |
| 54 | + |
| 55 | +def test_errors_strict_default(): # type: () -> None |
| 56 | + with pytest.raises(UnicodeDecodeError): |
| 57 | + decode_content(b"\x80", encoding="utf-8") |
| 58 | + |
| 59 | + |
| 60 | +def test_errors_strict(): # type: () -> None |
| 61 | + with pytest.raises(UnicodeDecodeError): |
| 62 | + decode_content(b"\x80", encoding="utf-8", errors="strict") |
| 63 | + |
| 64 | + |
| 65 | +def test_errors_replace(): # type: () -> None |
| 66 | + # fmt: off |
| 67 | + assert decode_content(b"\x80", encoding="utf-8", errors="replace") == u"�" |
| 68 | + # fmt: on |
| 69 | + |
| 70 | + |
| 71 | +def test_errors_ignore(): # type: () -> None |
| 72 | + # fmt: off |
| 73 | + assert decode_content(b"\x80", encoding="utf-8", errors="ignore") == u"" |
| 74 | + # fmt: on |
0 commit comments