Skip to content

Commit b3faf31

Browse files
Copilotkarthiknadig
andcommitted
Fix UV environment detection tests to be self-contained
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
1 parent da76b77 commit b3faf31

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

crates/pet-venv-uv/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,34 @@ mod tests {
110110
#[test]
111111
fn test_is_venv_uv_dir_detects_uv_environment() {
112112
// This test checks if we can detect a UV environment from pyvenv.cfg
113-
let uv_env_path = PathBuf::from("/tmp/test_uv_env");
114-
assert!(is_venv_uv_dir(&uv_env_path), "Should detect UV environment");
113+
use std::fs;
114+
let test_dir = PathBuf::from("/tmp/test_uv_env_venv_uv");
115+
fs::create_dir_all(&test_dir).unwrap();
116+
let pyvenv_cfg = test_dir.join("pyvenv.cfg");
117+
let contents = "home = /usr/bin/python3.12\nimplementation = CPython\nuv = 0.8.14\nversion_info = 3.12.11\ninclude-system-site-packages = false\nprompt = test-uv-env\n";
118+
fs::write(&pyvenv_cfg, contents).unwrap();
119+
120+
assert!(is_venv_uv_dir(&test_dir), "Should detect UV environment");
121+
122+
fs::remove_dir_all(&test_dir).ok();
115123
}
116124

117125
#[test]
118126
fn test_is_venv_uv_dir_does_not_detect_regular_environment() {
119127
// This test checks if we can properly ignore regular venv environments
120-
let regular_env_path = PathBuf::from("/tmp/test_regular_env");
128+
use std::fs;
129+
let test_dir = PathBuf::from("/tmp/test_regular_env_venv_uv");
130+
fs::create_dir_all(&test_dir).unwrap();
131+
let pyvenv_cfg = test_dir.join("pyvenv.cfg");
132+
let contents = "home = /usr/bin/python3.12\ninclude-system-site-packages = false\nversion = 3.13.5\nexecutable = /usr/bin/python3.12\ncommand = python -m venv /path/to/env\n";
133+
fs::write(&pyvenv_cfg, contents).unwrap();
134+
121135
assert!(
122-
!is_venv_uv_dir(&regular_env_path),
136+
!is_venv_uv_dir(&test_dir),
123137
"Should not detect regular venv as UV environment"
124138
);
139+
140+
fs::remove_dir_all(&test_dir).ok();
125141
}
126142

127143
#[test]

0 commit comments

Comments
 (0)