-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_python_version.py
More file actions
78 lines (58 loc) · 2.43 KB
/
Copy pathtest_python_version.py
File metadata and controls
78 lines (58 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sys
from types import SimpleNamespace
import warnings
import pytest
import autonerves
def _set_python_version(monkeypatch, major, minor):
monkeypatch.setattr(
autonerves,
"sys",
SimpleNamespace(version_info=(major, minor), stderr=sys.stderr),
)
monkeypatch.setattr(
autonerves,
"_python_version_check_bypassed",
lambda: False,
)
@pytest.mark.parametrize("minor", [12, 13, 14])
def test_supported_python_versions_do_not_warn(monkeypatch, capsys, minor):
_set_python_version(monkeypatch, major=3, minor=minor)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
autonerves._emit_python_version_warning()
assert caught == []
assert capsys.readouterr().err == ""
def test_python_below_minimum_is_reported_as_unsupported(monkeypatch, capsys):
_set_python_version(monkeypatch, major=3, minor=11)
with pytest.warns(UserWarning, match=r"require Python >=3\.12"):
autonerves._emit_python_version_warning()
message = capsys.readouterr().err
assert "Python 3.12 or newer is required" in message
assert "unsupported by current PyAuto releases" in message
assert "pre-migration PyAuto release" in message
def test_python_above_supported_range_is_reported_as_experimental(monkeypatch, capsys):
_set_python_version(monkeypatch, major=3, minor=15)
with pytest.warns(UserWarning, match=r"experimental Python 3\.15"):
autonerves._emit_python_version_warning()
message = capsys.readouterr().err
assert "Python 3.15 detected -- this Python version is experimental" in message
assert "tests and supports Python 3.12, 3.13 and 3.14" in message
assert "Use Python 3.12, 3.13 or 3.14 for production work" in message
def test_python_version_warning_respects_yaml_bypass(monkeypatch, tmp_path, capsys):
config_path = tmp_path / "config"
config_path.mkdir()
(config_path / "general.yaml").write_text(
"version:\n python_version_check: false\n"
)
monkeypatch.chdir(tmp_path)
monkeypatch.setattr(
autonerves,
"sys",
SimpleNamespace(version_info=(3, 15)),
)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
autonerves._emit_python_version_warning()
assert autonerves._python_version_check_bypassed() is True
assert caught == []
assert capsys.readouterr().err == ""