1
1
"""Test the format_ignores module."""
2
2
3
- # ruff: noqa: PLC2701
4
3
import errno
5
4
import sys
6
5
from pathlib import Path
14
13
main ,
15
14
)
16
15
16
+ _TEST_SOURCE_TEMPLATE = """
17
+ def func1() -> None:
18
+ # {}
19
+ pass
20
+
21
+ def func2() -> None:
22
+ # {}
23
+ pass
24
+ """ .lstrip ()
25
+
17
26
18
27
@pytest .mark .parametrize (
19
28
("input_text" , "expected_output" ),
@@ -35,15 +44,16 @@ def test_sort_ignore_list(input_text: str, expected_output: str) -> None:
35
44
36
45
def test_process_file (tmpdir : pytest .TempdirFactory ) -> None :
37
46
"""Test _process_file function."""
38
- test_file = Path (str (tmpdir )) / "test.pyi"
39
- test_content = """def func1() -> None:
40
- # type: ignore[attr-defined, no-any-return]
41
- 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
+ )
42
55
43
- def func2() -> None:
44
- # pyright: ignore[reportUnknownMemberType,reportUnknownVariableType]
45
- pass
46
- """
56
+ test_file = Path (str (tmpdir )) / "test.pyi"
47
57
test_file .write_text (test_content , encoding = "utf-8" )
48
58
49
59
# Check-only mode
@@ -54,15 +64,6 @@ def func2() -> None:
54
64
# Processing mode
55
65
modified = _process_file (test_file )
56
66
assert modified is True
57
-
58
- expected_content = """def func1() -> None:
59
- # type: ignore[attr-defined, no-any-return]
60
- pass
61
-
62
- def func2() -> None:
63
- # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
64
- pass
65
- """
66
67
assert test_file .read_text (encoding = "utf-8" ) == expected_content
67
68
68
69
# Re-processing
@@ -95,7 +96,7 @@ def test_process_directory(tmpdir: pytest.TempdirFactory) -> None:
95
96
encoding = "utf-8" ,
96
97
)
97
98
test_files [2 ].write_text (
98
- "# pyright: ignore[reportUnknownVariableType,reportUnknownMemberType]" ,
99
+ "# " + " pyright: ignore[reportUnknownVariableType,reportUnknownMemberType]" ,
99
100
encoding = "utf-8" ,
100
101
)
101
102
test_files [3 ].write_text (
@@ -134,7 +135,7 @@ def test_process_directory(tmpdir: pytest.TempdirFactory) -> None:
134
135
)
135
136
assert (
136
137
test_files [2 ].read_text (encoding = "utf-8" )
137
- == "# pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]"
138
+ == "# " + " pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]"
138
139
)
139
140
assert (
140
141
test_files [3 ].read_text (encoding = "utf-8" )
@@ -206,7 +207,10 @@ def test_main_custom_pattern(
206
207
"""Test main function with custom pattern."""
207
208
temp_dir = Path (str (tmpdir ))
208
209
test_py = temp_dir / "test.py"
209
- test_py .write_text ("# type: ignore[no-any-return, attr-defined]" , encoding = "utf-8" )
210
+ test_py .write_text (
211
+ "# type: ignore[attr-defined, no-any-return]" ,
212
+ encoding = "utf-8" ,
213
+ )
210
214
211
215
monkeypatch .setattr (
212
216
sys ,
0 commit comments