Skip to content

Commit

Permalink
tests: skip-path-normalization should be a testcase option (#15660)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ikonst authored Jul 17, 2023
1 parent 3f601c3 commit b6b6624
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def parse_test_case(case: DataDrivenTestCase) -> None:
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
Expand Down Expand Up @@ -156,8 +155,6 @@ def _item_fail(msg: str) -> NoReturn:

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 {">=", "=="}:
Expand Down Expand Up @@ -185,7 +182,7 @@ def _item_fail(msg: str) -> NoReturn:
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
Expand Down Expand Up @@ -239,7 +236,6 @@ def _item_fail(msg: str) -> NoReturn:
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

Expand Down Expand Up @@ -269,7 +265,7 @@ class DataDrivenTestCase(pytest.Item):

# 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
Expand All @@ -281,10 +277,12 @@ def __init__(
self,
parent: DataSuiteCollector,
suite: DataSuite,
*,
file: str,
name: str,
writescache: bool,
only_when: str,
normalize_output: bool,
platform: str | None,
skip: bool,
xfail: bool,
Expand All @@ -296,6 +294,7 @@ def __init__(
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"
):
Expand Down Expand Up @@ -651,6 +650,7 @@ def pytest_pycollect_makeitem(collector: Any, name: str, obj: object) -> Any | N
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)?"
Expand Down Expand Up @@ -694,6 +694,7 @@ def split_test_cases(
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,
)
Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-literal.test
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ reveal_type(c_bytes_wrapper_alias) # N: Revealed type is "__main__.Wrap[Liter
[builtins fixtures/tuple.pyi]
[out]

[case testLiteralUnicodeWeirdCharacters]
[case testLiteralUnicodeWeirdCharacters-skip_path_normalization]
from typing import Any
from typing_extensions import Literal

Expand Down Expand Up @@ -334,7 +334,7 @@ a1 = b3
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
Expand Down Expand Up @@ -478,7 +478,7 @@ reveal_type(f5) # N: Revealed type is "def (x: Literal['foo']) -> Literal['foo'
[builtins fixtures/tuple.pyi]
[out]

[case testLiteralBasicStrUsageSlashes]
[case testLiteralBasicStrUsageSlashes-skip_path_normalization]
from typing_extensions import Literal

a: Literal[r"foo\nbar"]
Expand All @@ -487,7 +487,7 @@ b: Literal["foo\nbar"]
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']"

Expand Down

0 comments on commit b6b6624

Please sign in to comment.