13
13
main ,
14
14
)
15
15
16
+ _TEST_SOURCE_TEMPLATE = """
17
+ def func1() -> None:
18
+ # {}
19
+ pass
20
+
21
+ def func2() -> None:
22
+ # {}
23
+ pass
24
+ """ .lstrip ()
25
+
16
26
17
27
@pytest .mark .parametrize (
18
28
("input_text" , "expected_output" ),
@@ -34,15 +44,16 @@ def test_sort_ignore_list(input_text: str, expected_output: str) -> None:
34
44
35
45
def test_process_file (tmpdir : pytest .TempdirFactory ) -> None :
36
46
"""Test _process_file function."""
37
- test_file = Path (str (tmpdir )) / "test.pyi"
38
- test_content = """def func1() -> None:
39
- # type: ignore[attr-defined, no-any-return]
40
- pass
47
+ test_content = _TEST_SOURCE_TEMPLATE .format (
48
+ "type: ignore[attr-defined, no-any-return]" ,
49
+ "pyright: ignore[reportUnknownMemberType,reportUnknownVariableType]" ,
50
+ )
51
+ expected_content = _TEST_SOURCE_TEMPLATE .format (
52
+ "type: ignore[attr-defined, no-any-return]" ,
53
+ "pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]" ,
54
+ )
41
55
42
- def func2() -> None:
43
- # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
44
- pass
45
- """
56
+ test_file = Path (str (tmpdir )) / "test.pyi"
46
57
test_file .write_text (test_content , encoding = "utf-8" )
47
58
48
59
# Check-only mode
@@ -53,15 +64,6 @@ def func2() -> None:
53
64
# Processing mode
54
65
modified = _process_file (test_file )
55
66
assert modified is True
56
-
57
- expected_content = """def func1() -> None:
58
- # type: ignore[attr-defined, no-any-return]
59
- pass
60
-
61
- def func2() -> None:
62
- # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
63
- pass
64
- """
65
67
assert test_file .read_text (encoding = "utf-8" ) == expected_content
66
68
67
69
# Re-processing
@@ -94,15 +96,15 @@ def test_process_directory(tmpdir: pytest.TempdirFactory) -> None:
94
96
encoding = "utf-8" ,
95
97
)
96
98
test_files [2 ].write_text (
97
- "# pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]" ,
99
+ "# " + " pyright: ignore[reportUnknownVariableType,reportUnknownMemberType ]" ,
98
100
encoding = "utf-8" ,
99
101
)
100
102
test_files [3 ].write_text (
101
- "# type: ignore[attr-defined, no-any-return]" ,
103
+ "# type: ignore[no-any-return, attr-defined ]" ,
102
104
encoding = "utf-8" ,
103
105
)
104
106
test_files [4 ].write_text (
105
- "# type: ignore[attr-defined, no-any-return]" ,
107
+ "# type: ignore[no-any-return, attr-defined ]" ,
106
108
encoding = "utf-8" ,
107
109
)
108
110
@@ -133,15 +135,15 @@ def test_process_directory(tmpdir: pytest.TempdirFactory) -> None:
133
135
)
134
136
assert (
135
137
test_files [2 ].read_text (encoding = "utf-8" )
136
- == "# pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]"
138
+ == "# " + " pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]"
137
139
)
138
140
assert (
139
141
test_files [3 ].read_text (encoding = "utf-8" )
140
- == "# type: ignore[attr-defined, no-any-return]"
142
+ == "# type: ignore[no-any-return, attr-defined ]"
141
143
)
142
144
assert (
143
145
test_files [4 ].read_text (encoding = "utf-8" )
144
- == "# type: ignore[attr-defined, no-any-return]"
146
+ == "# type: ignore[no-any-return, attr-defined ]"
145
147
)
146
148
147
149
@@ -152,7 +154,7 @@ def test_main_success(
152
154
"""Test main function with valid path."""
153
155
test_file = Path (str (tmpdir )) / "test.pyi"
154
156
test_file .write_text (
155
- "# type: ignore[attr-defined, no-any-return]" ,
157
+ "# type: ignore[no-any-return, attr-defined ]" ,
156
158
encoding = "utf-8" ,
157
159
)
158
160
@@ -174,7 +176,7 @@ def test_main_check_mode(
174
176
"""Test main function in check-only mode."""
175
177
test_file = Path (str (tmpdir )) / "test.pyi"
176
178
test_file .write_text (
177
- "# type: ignore[attr-defined, no-any-return]" ,
179
+ "# type: ignore[no-any-return, attr-defined ]" ,
178
180
encoding = "utf-8" ,
179
181
)
180
182
@@ -185,7 +187,7 @@ def test_main_check_mode(
185
187
186
188
assert (
187
189
test_file .read_text (encoding = "utf-8" )
188
- == "# type: ignore[attr-defined, no-any-return]"
190
+ == "# type: ignore[no-any-return, attr-defined ]"
189
191
)
190
192
191
193
@@ -205,7 +207,10 @@ def test_main_custom_pattern(
205
207
"""Test main function with custom pattern."""
206
208
temp_dir = Path (str (tmpdir ))
207
209
test_py = temp_dir / "test.py"
208
- test_py .write_text ("# type: ignore[attr-defined, no-any-return]" , encoding = "utf-8" )
210
+ test_py .write_text (
211
+ "# type: ignore[attr-defined, no-any-return]" ,
212
+ encoding = "utf-8" ,
213
+ )
209
214
210
215
monkeypatch .setattr (
211
216
sys ,
0 commit comments