Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tests: enforce meaningful version checks #15635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,17 @@ def _item_fail(msg: str) -> NoReturn:
version = tuple(int(x) for x in version_str.split("."))
except ValueError:
_item_fail(f"{version_str!r} is not a valid python version")
if version < defaults.PYTHON3_VERSION:
_item_fail(
f"Version check against {version}; must be >= {defaults.PYTHON3_VERSION}"
)
if compare_op == ">=":
if version <= defaults.PYTHON3_VERSION:
_item_fail(
f"{arg} always true since minimum runtime version is {defaults.PYTHON3_VERSION}"
)
version_check = sys.version_info >= version
elif compare_op == "==":
if version < defaults.PYTHON3_VERSION:
_item_fail(
f"{arg} always false since minimum runtime version is {defaults.PYTHON3_VERSION}"
)
if not 1 < len(version) < 4:
_item_fail(
f'Only minor or patch version checks are currently supported with "==": {version_str!r}'
Expand Down
34 changes: 34 additions & 0 deletions mypy/test/meta/test_parse_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,37 @@ def test_parse_invalid_section(self) -> None:
f".test:{expected_lineno}: Invalid section header [unknownsection] in case 'abc'"
)
assert expected in actual

def test_bad_ge_version_check(self) -> None:
# Arrange
data = self._dedent(
"""
[case abc]
s: str
[out version>=3.8]
abc
"""
)

# Act
actual = self._run_pytest(data)

# Assert
assert "version>=3.8 always true since minimum runtime version is (3, 8)" in actual

def test_bad_eq_version_check(self) -> None:
# Arrange
data = self._dedent(
"""
[case abc]
s: str
[out version==3.7]
abc
"""
)

# Act
actual = self._run_pytest(data)

# Assert
assert "version==3.7 always false since minimum runtime version is (3, 8)" in actual