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
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
import io
from pathlib import Path
import pylint.interfaces
import pylint.testutils
CODEC_AND_MSG = [
("utf-8", tuple()),
(
"utf-16",
(
pylint.testutils.MessageTest(
msg_id="invalid-unicode-codec",
confidence=pylint.interfaces.HIGH,
# node=module,
line=1,
end_line=1,
col_offset=None,
end_col_offset=None,
),
),
),
(
"utf-32",
(
pylint.testutils.MessageTest(
msg_id="invalid-unicode-codec",
confidence=pylint.interfaces.HIGH,
# node=module,
line=1,
end_line=1,
col_offset=None,
end_col_offset=None,
),
),
),
(
"iso-8859-1",
(
pylint.testutils.MessageTest(
msg_id="bad-file-encoding",
confidence=pylint.interfaces.HIGH,
# node=module,
line=1,
end_line=1,
col_offset=None,
end_col_offset=None,
),
),
),
(
"ascii",
(
pylint.testutils.MessageTest(
msg_id="bad-file-encoding",
confidence=pylint.interfaces.HIGH,
# node=module,
line=1,
end_line=1,
col_offset=None,
end_col_offset=None,
),
),
),
]
class FakeNode:
"""Simple Faker representing a Module node.
Astroid crashes in a number of cases if we want to lint unsupported encodings.
So, this is used to test the behaviour of the encoding checker.
This shall ensure that our checks keep working once Python supports UTF16/32.
"""
file: Path
def __init__(self, content: bytes):
self.content = io.BytesIO(content)
def stream(self) -> io.BytesIO:
return self.content
|