44
55import pytest
66
7- from uvlink .path_utils import create_symlink
7+ from uvlink .path_utils import create_symlink , is_windows
88from uvlink .project import Project
99
1010
1111class TestProject :
1212 def test_hash_path (self ):
13- assert Project .hash_path ("/" ) == "8a5edab28263"
13+ assert (
14+ Project .hash_path ("/" ) == "8a5edab28263"
15+ if not is_windows ()
16+ else "c1dfd96eea9"
17+ )
18+
19+ def test_project_init_path_resolution_with_tilde (self ) -> None :
20+ """Test with tilde expansion and parent directory (e.g., "~/../xxx")."""
21+ user_home_path = Path .home ()
22+ test_dir = user_home_path / "test_project"
23+
24+ # Test ~/test_project resolves correctly
25+ p2 = Project (project_dir = "~/test_project" )
26+ assert p2 .project_dir == test_dir .resolve ()
27+ assert p2 .project_dir .is_absolute ()
28+
29+ # Test ~/.. resolves to parent of HOME
30+ p3 = Project (project_dir = "~/.." )
31+ assert p3 .project_dir == user_home_path .parent .resolve ()
32+ assert p3 .project_dir .is_absolute ()
1433
1534 def test_project_init (self , tmp_path : Path ) -> None :
1635 p = Project (project_dir = tmp_path )
1736 # Project.resolve() normalizes the path, so compare with resolved tmp_path
1837 assert p .project_dir == tmp_path .resolve ()
1938 assert p .project_name == tmp_path .name
2039 assert p .venv_type == ".venv"
21- assert "uvlink/cache" in str ( p .project_cache_dir )
40+ assert "uvlink/cache" in p .project_cache_dir . as_posix ( )
2241
23- def test_project_init_path_resolution (
24- self , tmp_path : Path , monkeypatch : pytest .MonkeyPatch
25- ) -> None :
42+ def test_project_init_path_resolution (self , tmp_path : Path ) -> None :
2643 """Test that Project resolves relative paths and parent directory references."""
2744 # Create a subdirectory to test relative paths with parent directory references
2845 subdir = tmp_path / "subdir" / "nested"
@@ -37,22 +54,6 @@ def test_project_init_path_resolution(
3754 assert p1 .project_dir .is_absolute ()
3855 assert p1 .project_name == tmp_path .name
3956
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-
5657 # Test symlink resolution
5758 # Create a target directory and a symlink pointing to it
5859 target_dir = tmp_path / "target"
0 commit comments