File size: 1,734 Bytes
e8055cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Tests for backup.py -- target resolution and dry-run behavior without network."""

import pytest

import backup


def test_resolve_targets_expands_all_without_uploading_unknowns():
    assert backup._resolve_targets("A") == ["A"]
    assert backup._resolve_targets("all") == list(backup.TARGETS)
    with pytest.raises(ValueError, match="unknown target"):
        backup._resolve_targets("missing")


def test_local_paths_keep_results_under_results_host(monkeypatch, tmp_path):
    workspace = tmp_path / "workspace"
    host = tmp_path / "host"
    monkeypatch.setattr(backup, "WORKSPACE_ROOT", workspace)
    monkeypatch.setattr(backup, "RESULTS_HOST_ROOT", host)

    assert backup._local_path("results/A") == host / "results/A"
    assert backup._local_path("harness") == workspace / "harness"


def test_backup_dry_run_skips_empty_targets_and_never_imports_hub(
    monkeypatch, tmp_path, capsys
):
    workspace = tmp_path / "workspace"
    host = tmp_path / "host"
    (workspace / "harness").mkdir(parents=True)
    (workspace / "harness" / "run.py").write_text("# source\n")
    monkeypatch.setattr(backup, "WORKSPACE_ROOT", workspace)
    monkeypatch.setattr(backup, "RESULTS_HOST_ROOT", host)
    monkeypatch.setattr(backup, "TARGETS", {"code": ["harness"], "A": ["results/A"]})

    uploaded = backup.backup("owner/dataset", "all", dry_run=True)

    assert uploaded == ["code"]
    output = capsys.readouterr().out
    assert "[A] skipped" in output
    assert "would upload" in output
    assert str(workspace / "harness") in output


def test_target_root_rejects_mixed_workspace_and_results_roots():
    with pytest.raises(ValueError, match="mixes incompatible"):
        backup._target_root(["results/A", "tests"])