From b0d1fc85a9a3d8462056473ecc8fcf3db4e99d63 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 5 Jun 2024 11:25:10 -0400 Subject: [PATCH] Use standard path filters for `uv venv` tests (#4046) Over in #4045 the existing filters were insufficient. We should use the same strategy we use for our standard `TestContext` instead. --- crates/uv/tests/common/mod.rs | 2 +- crates/uv/tests/venv.rs | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/crates/uv/tests/common/mod.rs b/crates/uv/tests/common/mod.rs index 68f053986caa..6f790c9fe646 100644 --- a/crates/uv/tests/common/mod.rs +++ b/crates/uv/tests/common/mod.rs @@ -313,7 +313,7 @@ impl TestContext { } /// Generate various escaped regex patterns for the given path. - fn path_patterns(path: impl AsRef) -> Vec { + pub(crate) fn path_patterns(path: impl AsRef) -> Vec { let mut patterns = Vec::new(); // We can only canonicalize paths that exist already diff --git a/crates/uv/tests/venv.rs b/crates/uv/tests/venv.rs index 579a992302e9..7ce5c1beff4b 100644 --- a/crates/uv/tests/venv.rs +++ b/crates/uv/tests/venv.rs @@ -7,7 +7,7 @@ use anyhow::Result; use assert_cmd::prelude::*; use assert_fs::fixture::ChildPath; use assert_fs::prelude::*; -use fs_err::PathExt; +#[cfg(windows)] use uv_fs::Simplified; use uv_interpreter::PythonVersion; @@ -28,7 +28,10 @@ impl VenvTestContext { let temp_dir = assert_fs::TempDir::new().unwrap(); let python_path = python_path_with_versions(&temp_dir, python_versions) .expect("Failed to create Python test path"); - let venv = temp_dir.child(".venv"); + + // Canonicalize the virtual environment path for consistent snapshots across platforms + let venv = ChildPath::new(temp_dir.canonicalize().unwrap().join(".venv")); + let python_versions = python_versions .iter() .map(|version| { @@ -55,22 +58,17 @@ impl VenvTestContext { .env("UV_TEST_PYTHON_PATH", self.python_path.clone()) .env("UV_NO_WRAP", "1") .env("UV_STACK_SIZE", (2 * 1024 * 1024).to_string()) - .current_dir(self.temp_dir.path()); + .current_dir(self.temp_dir.as_os_str()); command } fn filters(&self) -> Vec<(String, String)> { - // On windows, a directory can have multiple names (https://superuser.com/a/1666770), e.g. - // `C:\Users\KONSTA~1` and `C:\Users\Konstantin` are the same. - let venv_full = regex::escape(&self.venv.display().to_string()); - let mut filters = vec![(venv_full, ".venv".to_string())]; - - // For mac, otherwise it shows some /var/folders/ path. - if let Ok(canonicalized) = self.venv.path().fs_err_canonicalize() { - let venv_full = regex::escape(&canonicalized.simplified_display().to_string()); - filters.push((venv_full, ".venv".to_string())); - } - + let mut filters = Vec::new(); + filters.extend( + TestContext::path_patterns(&self.temp_dir) + .into_iter() + .map(|pattern| (pattern, "[TEMP_DIR]/".to_string())), + ); filters.push(( r"interpreter at: .+".to_string(), "interpreter at: [PATH]".to_string(),