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.
diff --git a/mypy/test/data.py b/mypy/test/data.py
index 66dafaf..de0267d 100644
--- a/mypy/test/data.py
+++ b/mypy/test/data.py
@@ -65,7 +65,6 @@
join = posixpath.join
out_section_missing = case.suite.required_out_section
- normalize_output = True
files: list[tuple[str, str]] = [] # path and contents
output_files: list[tuple[str, str | Pattern[str]]] = [] # output path and contents
@@ -156,8 +155,6 @@
version_check = True
for arg in args:
- if arg == "skip-path-normalization":
- normalize_output = False
if arg.startswith("version"):
compare_op = arg[7:9]
if compare_op not in {">=", "=="}:
@@ -185,7 +182,7 @@
version_check = sys.version_info[: len(version)] == version
if version_check:
tmp_output = [expand_variables(line) for line in item.data]
- if os.path.sep == "\\" and normalize_output:
+ if os.path.sep == "\\" and case.normalize_output:
tmp_output = [fix_win_path(line) for line in tmp_output]
if item.id == "out" or item.id == "out1":
output = tmp_output
@@ -239,7 +236,6 @@
case.expected_rechecked_modules = rechecked_modules
case.deleted_paths = deleted_paths
case.triggered = triggered or []
- case.normalize_output = normalize_output
case.expected_fine_grained_targets = targets
case.test_modules = test_modules
@@ -269,7 +265,7 @@
# Whether or not we should normalize the output to standardize things like
# forward vs backward slashes in file paths for Windows vs Linux.
- normalize_output = True
+ normalize_output: bool
# Extra attributes used by some tests.
last_line: int
@@ -281,10 +277,12 @@
self,
parent: DataSuiteCollector,
suite: DataSuite,
+ *,
file: str,
name: str,
writescache: bool,
only_when: str,
+ normalize_output: bool,
platform: str | None,
skip: bool,
xfail: bool,
@@ -296,6 +294,7 @@
self.file = file
self.writescache = writescache
self.only_when = only_when
+ self.normalize_output = normalize_output
if (platform == "windows" and sys.platform != "win32") or (
platform == "posix" and sys.platform == "win32"
):
@@ -651,6 +650,7 @@
r"(?P<name>[a-zA-Z_0-9]+)"
r"(?P<writescache>-writescache)?"
r"(?P<only_when>-only_when_cache|-only_when_nocache)?"
+ r"(?P<skip_path_normalization>-skip_path_normalization)?"
r"(-(?P<platform>posix|windows))?"
r"(?P<skip>-skip)?"
r"(?P<xfail>-xfail)?"
@@ -694,6 +694,7 @@
platform=m.group("platform"),
skip=bool(m.group("skip")),
xfail=bool(m.group("xfail")),
+ normalize_output=not m.group("skip_path_normalization"),
data=data,
line=line_no,
)
diff --git a/test-data/unit/check-literal.test b/test-data/unit/check-literal.test
index f63f402..4498b2d 100644
--- a/test-data/unit/check-literal.test
+++ b/test-data/unit/check-literal.test
@@ -278,7 +278,7 @@
[builtins fixtures/tuple.pyi]
[out]
-[case testLiteralUnicodeWeirdCharacters]
+[case testLiteralUnicodeWeirdCharacters-skip_path_normalization]
from typing import Any
from typing_extensions import Literal
@@ -334,7 +334,7 @@
a1 = c3 # E: Incompatible types in assignment (expression has type "Literal['¬b ∧ λ(p)']", variable has type "Literal['\x00¬b ∧ λ(p)']")
[builtins fixtures/tuple.pyi]
-[out skip-path-normalization]
+[out]
[case testLiteralRenamingImportWorks]
from typing_extensions import Literal as Foo
@@ -478,7 +478,7 @@
[builtins fixtures/tuple.pyi]
[out]
-[case testLiteralBasicStrUsageSlashes]
+[case testLiteralBasicStrUsageSlashes-skip_path_normalization]
from typing_extensions import Literal
a: Literal[r"foo\nbar"]
@@ -487,7 +487,7 @@
reveal_type(a)
reveal_type(b)
[builtins fixtures/tuple.pyi]
-[out skip-path-normalization]
+[out]
main:6: note: Revealed type is "Literal['foo\\nbar']"
main:7: note: Revealed type is "Literal['foo\nbar']"