-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_workspace.py
More file actions
198 lines (154 loc) · 5.85 KB
/
Copy pathtest_workspace.py
File metadata and controls
198 lines (154 loc) · 5.85 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import textwrap
import warnings
import pytest
from autonerves.workspace import check_version, WorkspaceVersionMismatchError
def _write_general_yaml(tmp_path, body):
config_dir = tmp_path / "config"
config_dir.mkdir(exist_ok=True)
(config_dir / "general.yaml").write_text(textwrap.dedent(body).lstrip())
def test_match_via_version_txt(tmp_path):
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_mismatch_via_version_txt_raises(tmp_path):
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
with pytest.raises(WorkspaceVersionMismatchError) as info:
check_version("2025.1.1.1", workspace_root=tmp_path)
msg = str(info.value)
assert "2026.7.22.1" in msg
assert "2025.1.1.1" in msg
assert "workspace_version_check: False" in msg
assert "main" in msg
def test_missing_sources_warns(tmp_path):
with pytest.warns(UserWarning, match="workspace_version_check: False"):
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_env_override_skips_mismatch(tmp_path, monkeypatch):
monkeypatch.setenv("PYAUTO_SKIP_WORKSPACE_VERSION_CHECK", "1")
(tmp_path / "version.txt").write_text("2025.1.1.1\n")
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_env_override_skips_missing_file(tmp_path, monkeypatch):
monkeypatch.setenv("PYAUTO_SKIP_WORKSPACE_VERSION_CHECK", "1")
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_default_root_is_cwd(tmp_path, monkeypatch):
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
monkeypatch.chdir(tmp_path)
check_version("2026.7.22.1")
def test_match_via_general_yaml(tmp_path):
_write_general_yaml(
tmp_path,
"""
version:
workspace_version: 2026.7.22.1
workspace_version_check: True
""",
)
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_mismatch_via_general_yaml_raises(tmp_path):
_write_general_yaml(
tmp_path,
"""
version:
workspace_version: 2026.7.22.1
workspace_version_check: True
""",
)
with pytest.raises(WorkspaceVersionMismatchError):
check_version("2025.1.1.1", workspace_root=tmp_path)
def test_yaml_bypass_skips_mismatch(tmp_path):
_write_general_yaml(
tmp_path,
"""
version:
workspace_version: 2026.7.22.1
workspace_version_check: False
""",
)
check_version("2025.1.1.1", workspace_root=tmp_path)
def test_yaml_bypass_skips_missing_version_key(tmp_path):
_write_general_yaml(
tmp_path,
"""
version:
workspace_version_check: False
""",
)
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_yaml_overrides_version_txt_when_both_present(tmp_path):
_write_general_yaml(
tmp_path,
"""
version:
workspace_version: 2026.7.22.1
""",
)
(tmp_path / "version.txt").write_text("2025.1.1.1\n")
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_version_txt_used_when_yaml_lacks_workspace_version(tmp_path):
_write_general_yaml(
tmp_path,
"""
version:
python_version_check: True
""",
)
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_yaml_without_version_key_falls_through_to_warning(tmp_path):
_write_general_yaml(
tmp_path,
"""
updates:
iterations_per_quick_update: 1
""",
)
with pytest.warns(UserWarning):
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_unparseable_yaml_falls_back_to_version_txt(tmp_path):
config_dir = tmp_path / "config"
config_dir.mkdir()
(config_dir / "general.yaml").write_text("::: not valid yaml :::")
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
check_version("2026.7.22.1", workspace_root=tmp_path)
def test_newer_library_within_window_passes_silently(tmp_path):
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
with warnings.catch_warnings():
warnings.simplefilter("error")
check_version("2026.7.29.1", workspace_root=tmp_path)
def test_newer_library_beyond_window_warns_stale(tmp_path):
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
with pytest.warns(UserWarning, match="git pull"):
check_version("2026.9.9.1", workspace_root=tmp_path)
def test_minimum_library_version_key_is_the_floor(tmp_path):
_write_general_yaml(
tmp_path,
"""
version:
minimum_library_version: 2026.7.22.1
workspace_version: 2027.1.1.1
""",
)
with warnings.catch_warnings():
warnings.simplefilter("error")
check_version("2026.7.29.1", workspace_root=tmp_path)
def test_below_minimum_library_version_raises_with_upgrade_advice(tmp_path):
workspace_root = tmp_path / "autolens_workspace"
workspace_root.mkdir()
_write_general_yaml(
workspace_root,
"""
version:
minimum_library_version: 2026.7.22.1
""",
)
with pytest.raises(WorkspaceVersionMismatchError) as info:
check_version("2025.1.1.1", workspace_root=workspace_root)
msg = str(info.value)
assert "pip install --upgrade autolens" in msg
assert "==" not in msg
def test_unparseable_library_version_warns_not_raises(tmp_path):
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
with pytest.warns(UserWarning, match="cannot be compared"):
check_version("1.0.dev0", workspace_root=tmp_path)
def test_unparseable_workspace_record_warns_not_raises(tmp_path):
(tmp_path / "version.txt").write_text("not-a-version\n")
with pytest.warns(UserWarning, match="cannot be compared"):
check_version("2026.7.22.1", workspace_root=tmp_path)