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+ 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