Skip to content

Commit b9a02e7

Browse files
committed
Fix Windows compatibility in pet-venv tests
- Use Scripts directory on Windows instead of bin - Use python.exe on Windows instead of python - Compare file names instead of full paths to avoid 8.3 short path issues
1 parent c2f1404 commit b9a02e7

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

crates/pet-venv/src/lib.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ mod tests {
279279
#[test]
280280
fn test_is_venv_with_pyvenv_cfg_in_parent() {
281281
let dir = tempdir().unwrap();
282+
#[cfg(windows)]
283+
let bin_dir = dir.path().join("Scripts");
284+
#[cfg(unix)]
282285
let bin_dir = dir.path().join("bin");
283286
fs::create_dir_all(&bin_dir).unwrap();
284287

@@ -287,6 +290,9 @@ mod tests {
287290
writeln!(file, "version = 3.11.4").unwrap();
288291

289292
// Create a fake python executable
293+
#[cfg(windows)]
294+
let python_path = bin_dir.join("python.exe");
295+
#[cfg(unix)]
290296
let python_path = bin_dir.join("python");
291297
fs::File::create(&python_path).unwrap();
292298

@@ -297,9 +303,15 @@ mod tests {
297303
#[test]
298304
fn test_is_venv_without_pyvenv_cfg() {
299305
let dir = tempdir().unwrap();
306+
#[cfg(windows)]
307+
let bin_dir = dir.path().join("Scripts");
308+
#[cfg(unix)]
300309
let bin_dir = dir.path().join("bin");
301310
fs::create_dir_all(&bin_dir).unwrap();
302311

312+
#[cfg(windows)]
313+
let python_path = bin_dir.join("python.exe");
314+
#[cfg(unix)]
303315
let python_path = bin_dir.join("python");
304316
fs::File::create(&python_path).unwrap();
305317

@@ -330,6 +342,9 @@ mod tests {
330342
#[test]
331343
fn test_venv_try_from_valid_venv() {
332344
let dir = tempdir().unwrap();
345+
#[cfg(windows)]
346+
let bin_dir = dir.path().join("Scripts");
347+
#[cfg(unix)]
333348
let bin_dir = dir.path().join("bin");
334349
fs::create_dir_all(&bin_dir).unwrap();
335350

@@ -338,6 +353,9 @@ mod tests {
338353
writeln!(file, "version = 3.11.4").unwrap();
339354
writeln!(file, "prompt = my-test-env").unwrap();
340355

356+
#[cfg(windows)]
357+
let python_path = bin_dir.join("python.exe");
358+
#[cfg(unix)]
341359
let python_path = bin_dir.join("python");
342360
fs::File::create(&python_path).unwrap();
343361

@@ -349,15 +367,26 @@ mod tests {
349367
let py_env = result.unwrap();
350368
assert_eq!(py_env.kind, Some(PythonEnvironmentKind::Venv));
351369
assert_eq!(py_env.name, Some("my-test-env".to_string()));
352-
assert_eq!(py_env.executable, Some(python_path));
370+
// Compare file names rather than full paths to avoid Windows 8.3 short path issues
371+
assert!(py_env.executable.is_some());
372+
assert_eq!(
373+
py_env.executable.as_ref().unwrap().file_name(),
374+
python_path.file_name()
375+
);
353376
}
354377

355378
#[test]
356379
fn test_venv_try_from_non_venv() {
357380
let dir = tempdir().unwrap();
381+
#[cfg(windows)]
382+
let bin_dir = dir.path().join("Scripts");
383+
#[cfg(unix)]
358384
let bin_dir = dir.path().join("bin");
359385
fs::create_dir_all(&bin_dir).unwrap();
360386

387+
#[cfg(windows)]
388+
let python_path = bin_dir.join("python.exe");
389+
#[cfg(unix)]
361390
let python_path = bin_dir.join("python");
362391
fs::File::create(&python_path).unwrap();
363392

0 commit comments

Comments
 (0)