Skip to content

Commit

Permalink
Use standard path filters for uv venv tests (#4046)
Browse files Browse the repository at this point in the history
Over in #4045 the existing filters were insufficient. We should use the
same strategy we use for our standard `TestContext` instead.
  • Loading branch information
zanieb authored Jun 5, 2024
1 parent f2dc08b commit b0d1fc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl TestContext {
}

/// Generate various escaped regex patterns for the given path.
fn path_patterns(path: impl AsRef<Path>) -> Vec<String> {
pub(crate) fn path_patterns(path: impl AsRef<Path>) -> Vec<String> {
let mut patterns = Vec::new();

// We can only canonicalize paths that exist already
Expand Down
26 changes: 12 additions & 14 deletions crates/uv/tests/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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| {
Expand All @@ -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(),
Expand Down

0 comments on commit b0d1fc8

Please sign in to comment.