Skip to content

Commit

Permalink
test-version-check
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst committed Jul 10, 2023
1 parent 67cc059 commit 7288cbe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
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

0 comments on commit 7288cbe

Please sign in to comment.