@@ -7,17 +7,17 @@ use std::fs;
77use tempfile:: TempDir ;
88
99use pet_core:: pyvenv_cfg:: PyVenvCfg ;
10+ use pet_core:: Locator ;
1011use pet_core:: { env:: PythonEnv , python_environment:: PythonEnvironmentKind } ;
1112use pet_venv:: { is_venv, is_venv_dir, is_venv_uv, is_venv_uv_dir, Venv } ;
12- use pet_core:: Locator ;
1313
1414/// Test that we can detect regular venv environments
1515#[ test]
1616fn test_detect_regular_venv ( ) {
1717 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
1818 let venv_dir = temp_dir. path ( ) . join ( "test_venv" ) ;
1919 fs:: create_dir_all ( & venv_dir) . unwrap ( ) ;
20-
20+
2121 // Create a regular pyvenv.cfg (without UV)
2222 let pyvenv_cfg_content = r#"home = /usr/bin
2323implementation = CPython
@@ -27,29 +27,33 @@ prompt = test_venv
2727"# ;
2828 let pyvenv_cfg_path = venv_dir. join ( "pyvenv.cfg" ) ;
2929 fs:: write ( & pyvenv_cfg_path, pyvenv_cfg_content) . unwrap ( ) ;
30-
30+
3131 // Create a dummy python executable
3232 let scripts_dir = if cfg ! ( windows) { "Scripts" } else { "bin" } ;
3333 let bin_dir = venv_dir. join ( scripts_dir) ;
3434 fs:: create_dir_all ( & bin_dir) . unwrap ( ) ;
35- let python_exe = bin_dir. join ( if cfg ! ( windows) { "python.exe" } else { "python" } ) ;
35+ let python_exe = bin_dir. join ( if cfg ! ( windows) {
36+ "python.exe"
37+ } else {
38+ "python"
39+ } ) ;
3640 fs:: write ( & python_exe, "dummy" ) . unwrap ( ) ;
37-
41+
3842 // Test PyVenvCfg detection
3943 let cfg = PyVenvCfg :: find ( & venv_dir) . unwrap ( ) ;
4044 assert ! ( !cfg. is_uv( ) ) ;
4145 assert_eq ! ( cfg. version, "3.12.11" ) ;
4246 assert_eq ! ( cfg. prompt, Some ( "test_venv" . to_string( ) ) ) ;
43-
47+
4448 // Test directory detection
4549 assert ! ( is_venv_dir( & venv_dir) ) ;
4650 assert ! ( !is_venv_uv_dir( & venv_dir) ) ;
47-
51+
4852 // Test with PythonEnv
4953 let python_env = PythonEnv :: new ( python_exe. clone ( ) , None , None ) ;
5054 assert ! ( is_venv( & python_env) ) ;
5155 assert ! ( !is_venv_uv( & python_env) ) ;
52-
56+
5357 // Test locator
5458 let locator = Venv :: new ( ) ;
5559 let result = locator. try_from ( & python_env) . unwrap ( ) ;
@@ -63,7 +67,7 @@ fn test_detect_uv_venv() {
6367 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
6468 let venv_dir = temp_dir. path ( ) . join ( "test_uv_venv" ) ;
6569 fs:: create_dir_all ( & venv_dir) . unwrap ( ) ;
66-
70+
6771 // Create a UV pyvenv.cfg (with UV entry)
6872 let pyvenv_cfg_content = r#"home = /usr/bin
6973implementation = CPython
@@ -74,30 +78,34 @@ prompt = test_uv_venv
7478"# ;
7579 let pyvenv_cfg_path = venv_dir. join ( "pyvenv.cfg" ) ;
7680 fs:: write ( & pyvenv_cfg_path, pyvenv_cfg_content) . unwrap ( ) ;
77-
81+
7882 // Create a dummy python executable
7983 let scripts_dir = if cfg ! ( windows) { "Scripts" } else { "bin" } ;
8084 let bin_dir = venv_dir. join ( scripts_dir) ;
8185 fs:: create_dir_all ( & bin_dir) . unwrap ( ) ;
82- let python_exe = bin_dir. join ( if cfg ! ( windows) { "python.exe" } else { "python" } ) ;
86+ let python_exe = bin_dir. join ( if cfg ! ( windows) {
87+ "python.exe"
88+ } else {
89+ "python"
90+ } ) ;
8391 fs:: write ( & python_exe, "dummy" ) . unwrap ( ) ;
84-
92+
8593 // Test PyVenvCfg detection
8694 let cfg = PyVenvCfg :: find ( & venv_dir) . unwrap ( ) ;
8795 assert ! ( cfg. is_uv( ) ) ;
8896 assert_eq ! ( cfg. uv_version, Some ( "0.8.14" . to_string( ) ) ) ;
8997 assert_eq ! ( cfg. version, "3.12.11" ) ;
9098 assert_eq ! ( cfg. prompt, Some ( "test_uv_venv" . to_string( ) ) ) ;
91-
99+
92100 // Test directory detection
93101 assert ! ( is_venv_dir( & venv_dir) ) ;
94102 assert ! ( is_venv_uv_dir( & venv_dir) ) ;
95-
103+
96104 // Test with PythonEnv
97105 let python_env = PythonEnv :: new ( python_exe. clone ( ) , None , None ) ;
98106 assert ! ( is_venv( & python_env) ) ;
99107 assert ! ( is_venv_uv( & python_env) ) ;
100-
108+
101109 // Test locator
102110 let locator = Venv :: new ( ) ;
103111 let result = locator. try_from ( & python_env) . unwrap ( ) ;
@@ -111,15 +119,15 @@ fn test_uv_version_parsing() {
111119 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
112120 let venv_dir = temp_dir. path ( ) . join ( "test_uv_version" ) ;
113121 fs:: create_dir_all ( & venv_dir) . unwrap ( ) ;
114-
122+
115123 // Test different UV version formats
116124 let test_cases = vec ! [
117125 ( "uv = 0.8.14" , Some ( "0.8.14" . to_string( ) ) ) ,
118126 ( "uv=0.8.14" , Some ( "0.8.14" . to_string( ) ) ) ,
119127 ( "uv = 1.0.0-beta" , Some ( "1.0.0-beta" . to_string( ) ) ) ,
120128 ( "uv= 2.1.3 " , Some ( "2.1.3" . to_string( ) ) ) ,
121129 ] ;
122-
130+
123131 for ( uv_line, expected) in test_cases {
124132 let pyvenv_cfg_content = format ! (
125133 r#"home = /usr/bin
@@ -133,7 +141,7 @@ prompt = test_uv
133141 ) ;
134142 let pyvenv_cfg_path = venv_dir. join ( "pyvenv.cfg" ) ;
135143 fs:: write ( & pyvenv_cfg_path, pyvenv_cfg_content) . unwrap ( ) ;
136-
144+
137145 let cfg = PyVenvCfg :: find ( & venv_dir) . unwrap ( ) ;
138146 assert_eq ! ( cfg. uv_version, expected, "Failed for UV line: {}" , uv_line) ;
139147 assert ! ( cfg. is_uv( ) ) ;
@@ -145,8 +153,8 @@ prompt = test_uv
145153fn test_locator_supported_categories ( ) {
146154 let locator = Venv :: new ( ) ;
147155 let categories = locator. supported_categories ( ) ;
148-
156+
149157 assert ! ( categories. contains( & PythonEnvironmentKind :: Venv ) ) ;
150158 assert ! ( categories. contains( & PythonEnvironmentKind :: VenvUv ) ) ;
151159 assert_eq ! ( categories. len( ) , 2 ) ;
152- }
160+ }
0 commit comments