Skip to content

Commit d8694f1

Browse files
authored
fix: adapt tests for Windows (#24)
1 parent 9d73d95 commit d8694f1

4 files changed

Lines changed: 58 additions & 25 deletions

File tree

src/uvlink/project.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def get_uvlink_dir(*subpaths: str | Path) -> Path:
3333
Returns:
3434
Path: Absolute path to the uvlink data directory or provided subpath.
3535
"""
36-
base = Path(os.environ.get("XDG_DATA_HOME", "~/.local/share")).expanduser()
36+
default_path = Path.home() / ".local" / "share"
37+
base = Path(os.environ.get("XDG_DATA_HOME", default_path)).expanduser()
3738
root = base / "uvlink"
3839
for sp in subpaths:
3940
root /= Path(sp)

tests/test_cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ def test_ls(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
113113
assert "Is Linked" in result.stdout
114114

115115
# Verify cache location message
116-
assert "Cache Location:" in result.stdout
117-
assert "uvlink/cache" in result.stdout
116+
assert f"Cache Location: {cache_dir}" in result.stdout
118117

119118
# Verify both projects appear and have correct linked status
120119
output_lines = result.stdout.split("\n")

tests/test_path_utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from uvlink.path_utils import create_symlink, create_windows_junction, is_windows
6+
7+
8+
def test_create_symlink(tmp_path: Path):
9+
target_dir = tmp_path / "target"
10+
symlink_dir = tmp_path / "symlink"
11+
create_symlink(symlink=symlink_dir, target=target_dir)
12+
13+
assert symlink_dir.exists()
14+
assert symlink_dir.is_symlink() or (is_windows() and symlink_dir.is_junction())
15+
assert symlink_dir.resolve() == target_dir.resolve()
16+
17+
18+
@pytest.mark.skipif(
19+
not is_windows(), reason="Windows junctions are only applicable on Windows."
20+
)
21+
def test_create_windows_junction(tmp_path: Path):
22+
target_dir = tmp_path
23+
symlink_dir = tmp_path / "symlink"
24+
create_windows_junction(symlink=symlink_dir, target=target_dir)
25+
26+
assert symlink_dir.exists()
27+
assert symlink_dir.is_junction()
28+
assert symlink_dir.resolve() == target_dir.resolve()
29+
30+
31+
def test_create_windows_junction_invalid_target(tmp_path: Path):
32+
with pytest.raises(ValueError):
33+
create_windows_junction(
34+
symlink=tmp_path / "any", target=tmp_path / "nonexistent"
35+
)

tests/test_project.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,39 @@
44

55
import pytest
66

7-
from uvlink.path_utils import create_symlink
7+
from uvlink.path_utils import create_symlink, is_windows
88
from uvlink.project import Project
99

1010

1111
class TestProject:
1212
def test_hash_path(self):
13-
assert Project.hash_path("/") == "8a5edab28263"
13+
expected_hash = "d0023e7cb6a9" if is_windows() else "8a5edab28263"
14+
assert Project.hash_path("/") == expected_hash
15+
16+
def test_project_init_path_resolution_with_tilde(self) -> None:
17+
"""Test with tilde expansion and parent directory (e.g., "~/../xxx")."""
18+
user_home_path = Path.home()
19+
test_dir = user_home_path / "test_project"
20+
21+
# Test ~/test_project resolves correctly
22+
p2 = Project(project_dir="~/test_project")
23+
assert p2.project_dir == test_dir.resolve()
24+
assert p2.project_dir.is_absolute()
25+
26+
# Test ~/.. resolves to parent of HOME
27+
p3 = Project(project_dir="~/..")
28+
assert p3.project_dir == user_home_path.parent.resolve()
29+
assert p3.project_dir.is_absolute()
1430

1531
def test_project_init(self, tmp_path: Path) -> None:
1632
p = Project(project_dir=tmp_path)
1733
# Project.resolve() normalizes the path, so compare with resolved tmp_path
1834
assert p.project_dir == tmp_path.resolve()
1935
assert p.project_name == tmp_path.name
2036
assert p.venv_type == ".venv"
21-
assert "uvlink/cache" in str(p.project_cache_dir)
37+
assert "uvlink/cache" in p.project_cache_dir.as_posix()
2238

23-
def test_project_init_path_resolution(
24-
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
25-
) -> None:
39+
def test_project_init_path_resolution(self, tmp_path: Path) -> None:
2640
"""Test that Project resolves relative paths and parent directory references."""
2741
# Create a subdirectory to test relative paths with parent directory references
2842
subdir = tmp_path / "subdir" / "nested"
@@ -37,22 +51,6 @@ def test_project_init_path_resolution(
3751
assert p1.project_dir.is_absolute()
3852
assert p1.project_name == tmp_path.name
3953

40-
# Test with tilde expansion and parent directory (e.g., "~/../xxx")
41-
# Mock HOME to be tmp_path for reliable testing
42-
monkeypatch.setenv("HOME", str(tmp_path))
43-
test_dir = tmp_path / "test_project"
44-
test_dir.mkdir(exist_ok=True)
45-
46-
# Test ~/test_project resolves correctly
47-
p2 = Project(project_dir="~/test_project")
48-
assert p2.project_dir == test_dir.resolve()
49-
assert p2.project_dir.is_absolute()
50-
51-
# Test ~/.. resolves to parent of HOME
52-
p3 = Project(project_dir="~/..")
53-
assert p3.project_dir == tmp_path.parent.resolve()
54-
assert p3.project_dir.is_absolute()
55-
5654
# Test symlink resolution
5755
# Create a target directory and a symlink pointing to it
5856
target_dir = tmp_path / "target"

0 commit comments

Comments
 (0)