uv/crates/puffin-cli/tests/common/mod.rs
konsti 92c780ec2f
Run custom insta filters before generic filters (#781)
I've noticed some non-deterministic test failures when a temp dir looks
like a timestamp
(2016141680).
Running the custom filters for e.g. the temp dirs before the generic
time filters should fix that.
2024-01-04 16:40:28 +01:00

32 lines
931 B
Rust

#![allow(dead_code)]
use assert_cmd::Command;
use assert_fs::assert::PathAssert;
use assert_fs::fixture::PathChild;
use assert_fs::TempDir;
use insta_cmd::get_cargo_bin;
use std::path::PathBuf;
pub(crate) const BIN_NAME: &str = "puffin";
pub(crate) const INSTA_FILTERS: &[(&str, &str)] = &[
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
(r"(\d+\.)?\d+(ms|s)", "[TIME]"),
];
/// Create a virtual environment named `.venv` in a temporary directory.
pub(crate) fn create_venv_py312(temp_dir: &TempDir, cache_dir: &TempDir) -> PathBuf {
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
venv.to_path_buf()
}