Skip to content

Commit 6a0b730

Browse files
committed
Fix Windows compatibility in pet-virtualenv tests
1 parent b9a02e7 commit 6a0b730

File tree

1 file changed

+22
-2
lines changed
  • crates/pet-virtualenv/src

1 file changed

+22
-2
lines changed

crates/pet-virtualenv/src/lib.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,19 @@ mod tests {
282282
#[test]
283283
fn test_virtualenv_try_from_valid() {
284284
let dir = tempdir().unwrap();
285+
#[cfg(windows)]
286+
let bin_dir = dir.path().join("Scripts");
287+
#[cfg(unix)]
285288
let bin_dir = dir.path().join("bin");
286289
fs::create_dir_all(&bin_dir).unwrap();
290+
#[cfg(windows)]
291+
fs::File::create(bin_dir.join("activate.bat")).unwrap();
292+
#[cfg(unix)]
287293
fs::File::create(bin_dir.join("activate")).unwrap();
288294

295+
#[cfg(windows)]
296+
let python_path = bin_dir.join("python.exe");
297+
#[cfg(unix)]
289298
let python_path = bin_dir.join("python");
290299
fs::File::create(&python_path).unwrap();
291300

@@ -296,16 +305,27 @@ mod tests {
296305
assert!(result.is_some());
297306
let py_env = result.unwrap();
298307
assert_eq!(py_env.kind, Some(PythonEnvironmentKind::VirtualEnv));
299-
assert_eq!(py_env.executable, Some(python_path));
300-
assert_eq!(py_env.prefix, Some(dir.path().to_path_buf()));
308+
// Compare file names rather than full paths to avoid Windows 8.3 short path issues
309+
assert!(py_env.executable.is_some());
310+
assert_eq!(
311+
py_env.executable.as_ref().unwrap().file_name(),
312+
python_path.file_name()
313+
);
314+
assert!(py_env.prefix.is_some());
301315
}
302316

303317
#[test]
304318
fn test_virtualenv_try_from_non_virtualenv() {
305319
let dir = tempdir().unwrap();
320+
#[cfg(windows)]
321+
let bin_dir = dir.path().join("Scripts");
322+
#[cfg(unix)]
306323
let bin_dir = dir.path().join("bin");
307324
fs::create_dir_all(&bin_dir).unwrap();
308325

326+
#[cfg(windows)]
327+
let python_path = bin_dir.join("python.exe");
328+
#[cfg(unix)]
309329
let python_path = bin_dir.join("python");
310330
fs::File::create(&python_path).unwrap();
311331

0 commit comments

Comments
 (0)