Repository navigation
Expand file tree
/
Copy pathtest_project_paths.py
More file actions
76 lines (54 loc) · 2.87 KB
/
Copy pathtest_project_paths.py
File metadata and controls
76 lines (54 loc) · 2.87 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
from __future__ import annotations
import subprocess
from pathlib import Path
import pytest
from planfile import Planfile
from planfile.core.store import PlanfileStore
from planfile.project_paths import canonical_project_root, ensure_project_root
def _git_init(path: Path) -> None:
# canonical_project_root only bounds its upward walk for an ancestor
# .planfile store when the start path is inside a Git repo. Without this,
# a stray store above /tmp (e.g. /tmp/.planfile, ~/.planfile) on the host
# machine silently wins over tmp_path, which is what this suite exists to
# rule out — see ticket-129.
path.mkdir(parents=True, exist_ok=True)
subprocess.run(["git", "init", "-q"], cwd=path, check=True)
def test_discovery_from_inside_store_uses_outer_project(tmp_path: Path) -> None:
root = tmp_path / "repo"
(root / ".planfile" / "sprints").mkdir(parents=True)
(root / ".planfile" / "config.yaml").write_text("project: repo\n", encoding="utf-8")
nested = root / ".planfile" / ".planfile" / "config.yaml"
nested.parent.mkdir(parents=True)
nested.write_text("project: nested\n", encoding="utf-8")
discovered = Planfile.auto_discover(str(root / ".planfile" / "sprints"))
assert discovered.store.project_dir == root.resolve()
assert not (root / ".planfile" / ".planfile" / "sprints").exists()
def test_auto_discover_initialises_at_repository_root_when_store_is_missing(tmp_path: Path) -> None:
root = tmp_path / "repo"
inside_future_store = root / ".planfile" / "sprints"
inside_future_store.mkdir(parents=True)
discovered = Planfile.auto_discover(str(inside_future_store))
assert discovered.store.project_dir == root.resolve()
assert (root / ".planfile" / "config.yaml").exists()
assert not (root / ".planfile" / ".planfile").exists()
def test_explicit_store_path_is_rejected_instead_of_nested_initialisation(tmp_path: Path) -> None:
root = tmp_path / "repo"
store_path = root / ".planfile"
store_path.mkdir(parents=True)
with pytest.raises(ValueError, match="project_path_inside_planfile"):
Planfile(str(store_path))
with pytest.raises(ValueError, match="project_path_inside_planfile"):
PlanfileStore(str(store_path / "sprints"))
def test_path_helpers_leave_normal_project_paths_unchanged(tmp_path: Path) -> None:
root = tmp_path / "repo"
_git_init(root)
(root / "src").mkdir()
assert canonical_project_root(root / "src") == (root / "src").resolve()
assert ensure_project_root(root) == root.resolve()
def test_discovery_without_git_does_not_adopt_an_ancestor_store(tmp_path: Path) -> None:
root = tmp_path / "repo"
(root / ".planfile" / "sprints").mkdir(parents=True)
(root / ".planfile" / "config.yaml").write_text("project: stray\n", encoding="utf-8")
nested = root / "src"
nested.mkdir()
assert canonical_project_root(nested) == nested.resolve()