Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test_autonerves/test_setup_colab.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ def test_existing_dir_skips_clone(self, tmp_path, capsys):

def test_clones_release_tag_when_available(self, tmp_path):
target = str(tmp_path / "ws")
with mock.patch.object(setup_colab, "_installed_version", return_value="2026.7.6.649"):
with mock.patch.object(setup_colab, "_installed_version", return_value="2026.7.22.1"):
with mock.patch.object(
subprocess, "run", return_value=mock.Mock(returncode=0)
) as run:
setup_colab._clone_workspace("repo_url", target, "autolens")
run.assert_called_once()
args = run.call_args[0][0]
assert args[:4] == ["git", "clone", "--depth", "1"]
assert ["--branch", "2026.7.6.649"] == args[4:6]
assert ["--branch", "2026.7.22.1"] == args[4:6]

def test_falls_back_to_default_branch_when_tag_missing(self, tmp_path):
target = str(tmp_path / "ws")
Expand Down
60 changes: 30 additions & 30 deletions test_autonerves/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,61 @@ def _write_general_yaml(tmp_path, body):


def test_match_via_version_txt(tmp_path):
(tmp_path / "version.txt").write_text("2026.4.13.6\n")
check_version("2026.4.13.6", workspace_root=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.4.13.6\n")
(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.4.13.6" in msg
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.4.13.6", workspace_root=tmp_path)
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.4.13.6", workspace_root=tmp_path)
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.4.13.6", workspace_root=tmp_path)
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.4.13.6\n")
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
monkeypatch.chdir(tmp_path)
check_version("2026.4.13.6")
check_version("2026.7.22.1")


def test_match_via_general_yaml(tmp_path):
_write_general_yaml(
tmp_path,
"""
version:
workspace_version: 2026.4.13.6
workspace_version: 2026.7.22.1
workspace_version_check: True
""",
)
check_version("2026.4.13.6", workspace_root=tmp_path)
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.4.13.6
workspace_version: 2026.7.22.1
workspace_version_check: True
""",
)
Expand All @@ -80,7 +80,7 @@ def test_yaml_bypass_skips_mismatch(tmp_path):
tmp_path,
"""
version:
workspace_version: 2026.4.13.6
workspace_version: 2026.7.22.1
workspace_version_check: False
""",
)
Expand All @@ -95,19 +95,19 @@ def test_yaml_bypass_skips_missing_version_key(tmp_path):
workspace_version_check: False
""",
)
check_version("2026.4.13.6", workspace_root=tmp_path)
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.4.13.6
workspace_version: 2026.7.22.1
""",
)
(tmp_path / "version.txt").write_text("2025.1.1.1\n")
check_version("2026.4.13.6", workspace_root=tmp_path)
check_version("2026.7.22.1", workspace_root=tmp_path)


def test_version_txt_used_when_yaml_lacks_workspace_version(tmp_path):
Expand All @@ -118,8 +118,8 @@ def test_version_txt_used_when_yaml_lacks_workspace_version(tmp_path):
python_version_check: True
""",
)
(tmp_path / "version.txt").write_text("2026.4.13.6\n")
check_version("2026.4.13.6", workspace_root=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_yaml_without_version_key_falls_through_to_warning(tmp_path):
Expand All @@ -131,42 +131,42 @@ def test_yaml_without_version_key_falls_through_to_warning(tmp_path):
""",
)
with pytest.warns(UserWarning):
check_version("2026.4.13.6", workspace_root=tmp_path)
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.4.13.6\n")
check_version("2026.4.13.6", workspace_root=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_newer_library_within_window_passes_silently(tmp_path):
(tmp_path / "version.txt").write_text("2026.4.13.6\n")
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
with warnings.catch_warnings():
warnings.simplefilter("error")
check_version("2026.4.20.1", workspace_root=tmp_path)
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.4.13.6\n")
(tmp_path / "version.txt").write_text("2026.7.22.1\n")
with pytest.warns(UserWarning, match="git pull"):
check_version("2026.6.1.1", workspace_root=tmp_path)
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.4.13.6
minimum_library_version: 2026.7.22.1
workspace_version: 2027.1.1.1
""",
)
with warnings.catch_warnings():
warnings.simplefilter("error")
check_version("2026.4.20.1", workspace_root=tmp_path)
check_version("2026.7.29.1", workspace_root=tmp_path)


def test_below_minimum_library_version_raises_with_upgrade_advice(tmp_path):
Expand All @@ -176,7 +176,7 @@ def test_below_minimum_library_version_raises_with_upgrade_advice(tmp_path):
workspace_root,
"""
version:
minimum_library_version: 2026.4.13.6
minimum_library_version: 2026.7.22.1
""",
)
with pytest.raises(WorkspaceVersionMismatchError) as info:
Expand All @@ -187,12 +187,12 @@ def test_below_minimum_library_version_raises_with_upgrade_advice(tmp_path):


def test_unparseable_library_version_warns_not_raises(tmp_path):
(tmp_path / "version.txt").write_text("2026.4.13.6\n")
(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.4.13.6", workspace_root=tmp_path)
check_version("2026.7.22.1", workspace_root=tmp_path)
Loading