Skip to content

Commit 3dc489f

Browse files
committed
Tests for python version enforcement
1 parent c1a07c2 commit 3dc489f

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

test/test_environment.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from asv.util import shlex_quote as quote
1111

1212
from . import tools
13-
from .tools import (PYTHON_VER1, PYTHON_VER2, DUMMY1_VERSION, DUMMY2_VERSIONS, WIN, HAS_PYPY,
13+
from .tools import (HAS_MAMBA, PYTHON_VER1, PYTHON_VER2, DUMMY1_VERSION, DUMMY2_VERSIONS, WIN, HAS_PYPY,
1414
HAS_CONDA, HAS_VIRTUALENV, HAS_PYTHON_VER2, generate_test_repo)
1515

1616

@@ -958,3 +958,34 @@ def test__parse_matrix_entries():
958958
assert python == "2.6"
959959
assert requirements == {"foo": "9"}
960960
assert tagged_env_vars == {("build", "A"): "B", ("nobuild", "C"): "D"}
961+
962+
963+
@pytest.mark.parametrize("env_type", [
964+
pytest.param("conda", marks=pytest.mark.skipif(not HAS_CONDA, reason="Requires conda")),
965+
pytest.param("mamba", marks=pytest.mark.skipif(not HAS_MAMBA, reason="Requires mamba"))
966+
])
967+
@pytest.mark.skipif(not HAS_PYTHON_VER2,
968+
reason="Requires two usable Python versions")
969+
def test_no_env_file_python_version(tmpdir, env_type):
970+
"""Test the Python version is correct when no env file is present"""
971+
conf = config.Config()
972+
conf.env_dir = str(tmpdir.join("env"))
973+
conf.environment_type = env_type
974+
conf.pythons = [PYTHON_VER1, PYTHON_VER2]
975+
conf.matrix = {}
976+
977+
environments = list(environment.get_environments(conf, None))
978+
assert len(environments) == 2
979+
980+
for env in environments:
981+
env.create()
982+
983+
# Get the Python version from the environment
984+
output = env.run(['--version'])
985+
# Python version output format is typically "Python X.Y.Z"
986+
installed_version = output.split()[1]
987+
# Extract just the major.minor version
988+
installed_version = '.'.join(installed_version.split('.')[:2])
989+
990+
assert installed_version == env.python, \
991+
f"Expected Python version {env.python}, but got {installed_version}"

test/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from asv.plugins.conda import _find_conda
3737

3838
# Two Python versions for testing
39-
PYTHON_VER1, PYTHON_VER2 = '3.8', platform.python_version()
39+
PYTHON_VER1, PYTHON_VER2 = '3.8', ".".join(platform.python_version_tuple()[:2])
4040

4141
# Installable library versions to use in tests
4242
DUMMY1_VERSION = "0.14"

0 commit comments

Comments
 (0)