Skip to content

Commit

Permalink
Parametrize tests to cover more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Oct 15, 2024
1 parent 4aa29d5 commit dde2daf
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions tests/commands/base/test_verify_requires_python.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys
import platform

import pytest

Expand All @@ -22,21 +22,38 @@ def test_no_requires_python(base_command, my_app):
base_command.verify_required_python(my_app)


def test_requires_python_met(base_command, my_app):
"""Validation passes if requires-python specifies a version lower than the running interpreter."""
@pytest.mark.parametrize(
"requires_python",
(
spec_format.format(platform.python_version())
for spec_format in ("=={}", ">={}", "~={}", "<={}")
),
)
def test_requires_python_met(base_command, my_app, requires_python):
"""Validation passes if requires-python specifies a version compatible with the running interpreter."""

major, minor, micro, *_ = sys.version_info
spec = f">{major}.{minor - 1}.{micro}"
base_command.global_config = _get_global_config(requires_python=spec)
base_command.global_config = _get_global_config(requires_python)
base_command.verify_required_python(my_app)


def test_requires_python_unmet(base_command, my_app):
"""Validation fails if requires-python specifies a version greater than the running interpreter."""

major, minor, micro, *_ = sys.version_info
spec = f">{major}.{minor + 1}.{micro}"
base_command.global_config = _get_global_config(requires_python=spec)
@pytest.mark.parametrize(
"requires_python",
[
spec_format.format(platform.python_version())
for spec_format in (
"<{}",
">{}",
)
]
+ [
# A version earlier than any supported by Briefcase, so tests will never run with this interpreter
"==2.0"
],
)
def test_requires_python_unmet(base_command, my_app, requires_python):
"""Validation fails if requires-python specifies a version incompatible with the running interpreter."""

base_command.global_config = _get_global_config(requires_python)

with pytest.raises(UnsupportedPythonVersion):
base_command.verify_required_python(my_app)
Expand Down

0 comments on commit dde2daf

Please sign in to comment.