Skip to content

Commit b6b6624

Browse files
authored
tests: skip-path-normalization should be a testcase option (#15660)
The "Skip path normalization" option applies to all [out]s of a test case, so it's more correct for it to be a "case" option rather than an "out" option. This also simplifies the parsing of "out" sections' args.
1 parent 3f601c3 commit b6b6624

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

mypy/test/data.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def parse_test_case(case: DataDrivenTestCase) -> None:
6565
join = posixpath.join
6666

6767
out_section_missing = case.suite.required_out_section
68-
normalize_output = True
6968

7069
files: list[tuple[str, str]] = [] # path and contents
7170
output_files: list[tuple[str, str | Pattern[str]]] = [] # output path and contents
@@ -156,8 +155,6 @@ def _item_fail(msg: str) -> NoReturn:
156155

157156
version_check = True
158157
for arg in args:
159-
if arg == "skip-path-normalization":
160-
normalize_output = False
161158
if arg.startswith("version"):
162159
compare_op = arg[7:9]
163160
if compare_op not in {">=", "=="}:
@@ -185,7 +182,7 @@ def _item_fail(msg: str) -> NoReturn:
185182
version_check = sys.version_info[: len(version)] == version
186183
if version_check:
187184
tmp_output = [expand_variables(line) for line in item.data]
188-
if os.path.sep == "\\" and normalize_output:
185+
if os.path.sep == "\\" and case.normalize_output:
189186
tmp_output = [fix_win_path(line) for line in tmp_output]
190187
if item.id == "out" or item.id == "out1":
191188
output = tmp_output
@@ -239,7 +236,6 @@ def _item_fail(msg: str) -> NoReturn:
239236
case.expected_rechecked_modules = rechecked_modules
240237
case.deleted_paths = deleted_paths
241238
case.triggered = triggered or []
242-
case.normalize_output = normalize_output
243239
case.expected_fine_grained_targets = targets
244240
case.test_modules = test_modules
245241

@@ -269,7 +265,7 @@ class DataDrivenTestCase(pytest.Item):
269265

270266
# Whether or not we should normalize the output to standardize things like
271267
# forward vs backward slashes in file paths for Windows vs Linux.
272-
normalize_output = True
268+
normalize_output: bool
273269

274270
# Extra attributes used by some tests.
275271
last_line: int
@@ -281,10 +277,12 @@ def __init__(
281277
self,
282278
parent: DataSuiteCollector,
283279
suite: DataSuite,
280+
*,
284281
file: str,
285282
name: str,
286283
writescache: bool,
287284
only_when: str,
285+
normalize_output: bool,
288286
platform: str | None,
289287
skip: bool,
290288
xfail: bool,
@@ -296,6 +294,7 @@ def __init__(
296294
self.file = file
297295
self.writescache = writescache
298296
self.only_when = only_when
297+
self.normalize_output = normalize_output
299298
if (platform == "windows" and sys.platform != "win32") or (
300299
platform == "posix" and sys.platform == "win32"
301300
):
@@ -651,6 +650,7 @@ def pytest_pycollect_makeitem(collector: Any, name: str, obj: object) -> Any | N
651650
r"(?P<name>[a-zA-Z_0-9]+)"
652651
r"(?P<writescache>-writescache)?"
653652
r"(?P<only_when>-only_when_cache|-only_when_nocache)?"
653+
r"(?P<skip_path_normalization>-skip_path_normalization)?"
654654
r"(-(?P<platform>posix|windows))?"
655655
r"(?P<skip>-skip)?"
656656
r"(?P<xfail>-xfail)?"
@@ -694,6 +694,7 @@ def split_test_cases(
694694
platform=m.group("platform"),
695695
skip=bool(m.group("skip")),
696696
xfail=bool(m.group("xfail")),
697+
normalize_output=not m.group("skip_path_normalization"),
697698
data=data,
698699
line=line_no,
699700
)

test-data/unit/check-literal.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ reveal_type(c_bytes_wrapper_alias) # N: Revealed type is "__main__.Wrap[Liter
278278
[builtins fixtures/tuple.pyi]
279279
[out]
280280

281-
[case testLiteralUnicodeWeirdCharacters]
281+
[case testLiteralUnicodeWeirdCharacters-skip_path_normalization]
282282
from typing import Any
283283
from typing_extensions import Literal
284284

@@ -334,7 +334,7 @@ a1 = b3
334334
a1 = c3 # E: Incompatible types in assignment (expression has type "Literal['¬b ∧ λ(p)']", variable has type "Literal['\x00¬b ∧ λ(p)']")
335335
[builtins fixtures/tuple.pyi]
336336

337-
[out skip-path-normalization]
337+
[out]
338338

339339
[case testLiteralRenamingImportWorks]
340340
from typing_extensions import Literal as Foo
@@ -478,7 +478,7 @@ reveal_type(f5) # N: Revealed type is "def (x: Literal['foo']) -> Literal['foo'
478478
[builtins fixtures/tuple.pyi]
479479
[out]
480480

481-
[case testLiteralBasicStrUsageSlashes]
481+
[case testLiteralBasicStrUsageSlashes-skip_path_normalization]
482482
from typing_extensions import Literal
483483

484484
a: Literal[r"foo\nbar"]
@@ -487,7 +487,7 @@ b: Literal["foo\nbar"]
487487
reveal_type(a)
488488
reveal_type(b)
489489
[builtins fixtures/tuple.pyi]
490-
[out skip-path-normalization]
490+
[out]
491491
main:6: note: Revealed type is "Literal['foo\\nbar']"
492492
main:7: note: Revealed type is "Literal['foo\nbar']"
493493

0 commit comments

Comments
 (0)