diff --git a/crates/puffin/tests/common/mod.rs b/crates/puffin/tests/common/mod.rs index 5bb6845a5..f5b2d831f 100644 --- a/crates/puffin/tests/common/mod.rs +++ b/crates/puffin/tests/common/mod.rs @@ -1,4 +1,5 @@ -#![allow(dead_code)] +// The `unreachable_pub` is to silence false positives in RustRover. +#![allow(dead_code, unreachable_pub)] use std::path::{Path, PathBuf}; @@ -8,10 +9,13 @@ use assert_fs::fixture::PathChild; use assert_fs::TempDir; use insta_cmd::get_cargo_bin; -pub(crate) const BIN_NAME: &str = "puffin"; +pub const BIN_NAME: &str = "puffin"; -pub(crate) const INSTA_FILTERS: &[(&str, &str)] = &[ - (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), +// Exclude any packages uploaded after this date. +pub static EXCLUDE_NEWER: &str = "2023-11-18T12:00:00Z"; + +pub const INSTA_FILTERS: &[(&str, &str)] = &[ + (r"--cache-dir [^\s]+", "--cache-dir [CACHE_DIR]"), // Operation times (r"(\d+\.)?\d+(ms|s)", "[TIME]"), // Puffin versions @@ -28,7 +32,45 @@ pub(crate) const INSTA_FILTERS: &[(&str, &str)] = &[ ), ]; -pub(crate) fn venv_to_interpreter(venv: &Path) -> PathBuf { +#[derive(Debug)] +pub struct TestContext { + pub temp_dir: TempDir, + pub cache_dir: TempDir, + pub venv: PathBuf, +} + +impl TestContext { + pub fn new(python_version: &str) -> Self { + let temp_dir = TempDir::new().expect("Failed to create temp dir"); + let cache_dir = TempDir::new().expect("Failed to create temp dir"); + let venv = create_venv(&temp_dir, &cache_dir, python_version); + Self { + temp_dir, + cache_dir, + venv, + } + } + + /// Set shared defaults between tests: + /// * Set the current directory to a temporary directory (`temp_dir`). + /// * Set the cache dir to a different temporary directory (`cache_dir`). + /// * Set a cutoff for versions used in the resolution so the snapshots don't change after a new release. + /// * Set the venv to a fresh `.venv` in `temp_dir`. + pub fn compile(&self) -> std::process::Command { + let mut cmd = std::process::Command::new(get_cargo_bin(BIN_NAME)); + cmd.arg("pip") + .arg("compile") + .arg("--cache-dir") + .arg(self.cache_dir.path()) + .arg("--exclude-newer") + .arg(EXCLUDE_NEWER) + .env("VIRTUAL_ENV", self.venv.as_os_str()) + .current_dir(self.temp_dir.path()); + cmd + } +} + +pub fn venv_to_interpreter(venv: &Path) -> PathBuf { if cfg!(unix) { venv.join("bin").join("python") } else if cfg!(windows) { @@ -38,14 +80,9 @@ pub(crate) fn venv_to_interpreter(venv: &Path) -> PathBuf { } } -/// Create a virtual environment named `.venv` in a temporary directory. -pub(crate) fn create_venv_py312(temp_dir: &TempDir, cache_dir: &TempDir) -> PathBuf { - create_venv(temp_dir, cache_dir, "3.12") -} - /// Create a virtual environment named `.venv` in a temporary directory with the given /// Python version. Expected format for `python` is "python". -pub(crate) fn create_venv(temp_dir: &TempDir, cache_dir: &TempDir, python: &str) -> PathBuf { +pub fn create_venv(temp_dir: &TempDir, cache_dir: &TempDir, python: &str) -> PathBuf { let venv = temp_dir.child(".venv"); Command::new(get_cargo_bin(BIN_NAME)) .arg("venv") diff --git a/crates/puffin/tests/pip_compile.rs b/crates/puffin/tests/pip_compile.rs index e1be974cd..9d8a59c0d 100644 --- a/crates/puffin/tests/pip_compile.rs +++ b/crates/puffin/tests/pip_compile.rs @@ -14,42 +14,41 @@ use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; use itertools::Itertools; use url::Url; -use crate::common::create_venv; -use common::{create_venv_py312, BIN_NAME, INSTA_FILTERS}; +use common::{TestContext, BIN_NAME, INSTA_FILTERS}; + +use crate::common::EXCLUDE_NEWER; mod common; -// Exclude any packages uploaded after this date. -static EXCLUDE_NEWER: &str = "2023-11-18T12:00:00Z"; +/// Run [`assert_cmd_snapshot!`] with our default filters. +macro_rules! puffin_snapshot { + ($spawnable:expr, @$snapshot:literal) => {{ + puffin_snapshot!(INSTA_FILTERS.to_vec(), $spawnable, @$snapshot); + }}; + ($filters:expr, $spawnable:expr, @$snapshot:literal) => {{ + insta::with_settings!({ + filters => $filters + }, { + assert_cmd_snapshot!($spawnable, @$snapshot); + }); + }}; +} /// Resolve a specific version of Django from a `requirements.in` file. #[test] fn compile_requirements_in() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("django==5.0b1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context + .compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in asgiref==3.7.2 # via django django==5.0b1 @@ -58,28 +57,18 @@ fn compile_requirements_in() -> Result<()> { ----- stderr ----- Resolved 3 packages in [TIME] - "###); - }); + "###); Ok(()) } #[test] -fn missing_requirements_in() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let requirements_in = temp_dir.child("requirements.in"); +fn missing_requirements_in() { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -87,13 +76,10 @@ fn missing_requirements_in() -> Result<()> { ----- stderr ----- error: failed to open file `requirements.in` Caused by: No such file or directory (os error 2) - "###); - } + "### ); requirements_in.assert(predicates::path::missing()); - - Ok(()) } #[test] @@ -102,10 +88,7 @@ fn missing_venv() -> Result<()> { let cache_dir = TempDir::new()?; let venv = temp_dir.child(".venv"); - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .arg("pip") .arg("compile") .arg("requirements.in") @@ -120,8 +103,8 @@ fn missing_venv() -> Result<()> { ----- stderr ----- error: failed to open file `requirements.in` Caused by: No such file or directory (os error 2) - "###); - }); + "### + ); venv.assert(predicates::path::missing()); @@ -131,11 +114,8 @@ fn missing_venv() -> Result<()> { /// Resolve a specific version of Django from a `pyproject.toml` file. #[test] fn compile_pyproject_toml() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -148,24 +128,13 @@ dependencies = [ "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("pyproject.toml") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("pyproject.toml"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile pyproject.toml --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z pyproject.toml asgiref==3.7.2 # via django django==5.0b1 @@ -174,8 +143,8 @@ dependencies = [ ----- stderr ----- Resolved 3 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -183,36 +152,22 @@ dependencies = [ /// Resolve a package from a `requirements.in` file, with a `constraints.txt` file. #[test] fn compile_constraints_txt() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("django==5.0b1")?; - let constraints_txt = temp_dir.child("constraints.txt"); + let constraints_txt = context.temp_dir.child("constraints.txt"); constraints_txt.write_str("sqlparse<0.4.4")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--constraint") - .arg("constraints.txt") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("constraints.txt"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --constraint constraints.txt --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --constraint constraints.txt asgiref==3.7.2 # via django django==5.0b1 @@ -221,8 +176,8 @@ fn compile_constraints_txt() -> Result<()> { ----- stderr ----- Resolved 3 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -230,40 +185,26 @@ fn compile_constraints_txt() -> Result<()> { /// Resolve a package from a `requirements.in` file, with an inline constraint. #[test] fn compile_constraints_inline() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("django==5.0b1")?; requirements_in.write_str("-c constraints.txt")?; - let constraints_txt = temp_dir.child("constraints.txt"); + let constraints_txt = context.temp_dir.child("constraints.txt"); constraints_txt.write_str("sqlparse<0.4.4")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in ----- stderr ----- Resolved 0 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -272,39 +213,25 @@ fn compile_constraints_inline() -> Result<()> { /// uses markers. #[test] fn compile_constraints_markers() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("anyio")?; // Constrain a transitive dependency based on the Python version - let constraints_txt = temp_dir.child("constraints.txt"); + let constraints_txt = context.temp_dir.child("constraints.txt"); // If constraints are ignored, these will conflict constraints_txt.write_str("sniffio==1.2.0;python_version<='3.7'")?; constraints_txt.write_str("sniffio==1.3.0;python_version>'3.7'")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--constraint") - .arg("constraints.txt") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("constraints.txt"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --constraint constraints.txt --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --constraint constraints.txt anyio==4.0.0 idna==3.4 # via anyio @@ -313,8 +240,8 @@ fn compile_constraints_markers() -> Result<()> { ----- stderr ----- Resolved 3 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -322,11 +249,8 @@ fn compile_constraints_markers() -> Result<()> { /// Resolve a package from an optional dependency group in a `pyproject.toml` file. #[test] fn compile_pyproject_toml_extra() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -340,26 +264,15 @@ optional-dependencies.foo = [ "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("pyproject.toml") .arg("--extra") - .arg("foo") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("foo"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile pyproject.toml --extra foo --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z pyproject.toml --extra foo asgiref==3.7.2 # via django django==5.0b1 @@ -368,8 +281,8 @@ optional-dependencies.foo = [ ----- stderr ----- Resolved 3 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -377,11 +290,8 @@ optional-dependencies.foo = [ /// Resolve a package from an extra with unnormalized names in a `pyproject.toml` file. #[test] fn compile_pyproject_toml_extra_name_normalization() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -395,26 +305,15 @@ optional-dependencies."FrIeNdLy-._.-bArD" = [ "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("pyproject.toml") .arg("--extra") - .arg("FRiENDlY-...-_-BARd") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("FRiENDlY-...-_-BARd"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile pyproject.toml --extra FRiENDlY-...-_-BARd --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z pyproject.toml --extra FRiENDlY-...-_-BARd asgiref==3.7.2 # via django django==5.0b1 @@ -423,8 +322,8 @@ optional-dependencies."FrIeNdLy-._.-bArD" = [ ----- stderr ----- Resolved 3 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -432,11 +331,8 @@ optional-dependencies."FrIeNdLy-._.-bArD" = [ /// Request an extra that does not exist as a dependency group in a `pyproject.toml` file. #[test] fn compile_pyproject_toml_extra_missing() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -450,29 +346,18 @@ optional-dependencies.foo = [ "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("pyproject.toml") .arg("--extra") - .arg("bar") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("bar"), @r###" success: false exit_code: 2 ----- stdout ----- ----- stderr ----- error: Requested extra not found: bar - "###); - }); + "### + ); Ok(()) } @@ -480,11 +365,8 @@ optional-dependencies.foo = [ /// Request multiple extras that do not exist as a dependency group in a `pyproject.toml` file. #[test] fn compile_pyproject_toml_extras_missing() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -498,33 +380,22 @@ optional-dependencies.foo = [ "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("pyproject.toml") .arg("--extra") .arg("foo") .arg("--extra") .arg("bar") .arg("--extra") - .arg("foobar") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("foobar"), @r###" success: false exit_code: 2 ----- stdout ----- ----- stderr ----- error: Requested extras not found: bar, foobar - "###); - }); + "### + ); Ok(()) } @@ -532,27 +403,13 @@ optional-dependencies.foo = [ /// Request extras when using a `requirements.in` file which does not support extras. #[test] fn compile_requirements_file_extra() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("django==5.0b1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .arg("--all-extras") - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), + .arg("--all-extras"), @r###" success: false exit_code: 2 @@ -560,8 +417,8 @@ fn compile_requirements_file_extra() -> Result<()> { ----- stderr ----- error: Requesting extras requires a pyproject.toml input file. - "###); - }); + "### + ); Ok(()) } @@ -569,11 +426,8 @@ fn compile_requirements_file_extra() -> Result<()> { /// Request an extra with a name that does not conform to the specification. #[test] fn invalid_extra_name() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -587,21 +441,10 @@ optional-dependencies.foo = [ "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("pyproject.toml") .arg("--extra") - .arg("invalid name!") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("invalid name!"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -610,8 +453,8 @@ optional-dependencies.foo = [ error: invalid value 'invalid name!' for '--extra ': Extra names must start and end with a letter or digit and may only contain -, _, ., and alphanumeric characters For more information, try '--help'. - "###); - }); + "### + ); Ok(()) } @@ -619,33 +462,19 @@ optional-dependencies.foo = [ /// Resolve a specific version of Black at Python 3.12. #[test] fn compile_python_312() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--python-version") - .arg("3.12") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("3.12"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --python-version 3.12 --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --python-version 3.12 black==23.10.1 click==8.1.7 # via black @@ -660,8 +489,8 @@ fn compile_python_312() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -669,11 +498,8 @@ fn compile_python_312() -> Result<()> { /// Resolve a specific version of Black at Python 3.7. #[test] fn compile_python_37() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; let filters: Vec<_> = [ @@ -687,21 +513,10 @@ fn compile_python_37() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(filters, context.compile() .arg("requirements.in") .arg("--python-version") - .arg("3.7") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("3.7"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -714,7 +529,6 @@ fn compile_python_37() -> Result<()> { And because you require black==23.10.1, we can conclude that the requirements are unsatisfiable. "###); - }); Ok(()) } @@ -722,21 +536,14 @@ fn compile_python_37() -> Result<()> { /// Resolve a specific version of Black against an invalid Python version. #[test] fn compile_python_invalid_version() -> Result<()> { - let temp_dir = TempDir::new()?; - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--python-version") - .arg("3.7.x") - .current_dir(&temp_dir), @r###" + .arg("3.7.x"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -745,8 +552,8 @@ fn compile_python_invalid_version() -> Result<()> { error: invalid value '3.7.x' for '--python-version ': after parsing 3.7, found ".x" after it, which is not part of a valid version For more information, try '--help'. - "###); - }); + "### + ); Ok(()) } @@ -754,21 +561,14 @@ fn compile_python_invalid_version() -> Result<()> { /// Resolve a specific version of Black against an invalid Python version. #[test] fn compile_python_dev_version() -> Result<()> { - let temp_dir = TempDir::new()?; - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--python-version") - .arg("3.7-dev") - .current_dir(&temp_dir), @r###" + .arg("3.7-dev"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -777,8 +577,8 @@ fn compile_python_dev_version() -> Result<()> { error: invalid value '3.7-dev' for '--python-version ': Python version 3.7-dev is a development release For more information, try '--help'. - "###); - }); + "### + ); Ok(()) } @@ -787,38 +587,25 @@ fn compile_python_dev_version() -> Result<()> { /// incompatible sdist #[test] fn compile_numpy_py38() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); + let context = TestContext::new("3.8"); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("numpy")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .arg("--no-build") - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--no-build"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --no-build numpy==1.24.4 ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -826,31 +613,17 @@ fn compile_numpy_py38() -> Result<()> { /// Resolve a specific Flask wheel via a URL dependency. #[test] fn compile_wheel_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -869,8 +642,8 @@ fn compile_wheel_url_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -880,31 +653,17 @@ fn compile_wheel_url_dependency() -> Result<()> { /// Exercises the `prepare_metadata_for_build_wheel` hooks. #[test] fn compile_sdist_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ https://files.pythonhosted.org/packages/d8/09/c1a7354d3925a3c6c8cfdebf4245bae67d633ffda1ba415add06ffc839c5/flask-3.0.0.tar.gz")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -923,8 +682,8 @@ fn compile_sdist_url_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -933,11 +692,8 @@ fn compile_sdist_url_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_https_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git")?; // In addition to the standard filters, remove the `main` commit, which will change frequently. @@ -945,24 +701,13 @@ fn compile_git_https_dependency() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(filters, context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -982,7 +727,6 @@ fn compile_git_https_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] "###); - }); Ok(()) } @@ -991,31 +735,17 @@ fn compile_git_https_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_branch_https_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@1.0.x")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in click==8.1.7 # via flask flask @ git+https://github.com/pallets/flask.git@d92b64aa275841b0c9aea3903aba72fbc4275d91 @@ -1032,8 +762,8 @@ fn compile_git_branch_https_dependency() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1042,31 +772,17 @@ fn compile_git_branch_https_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_tag_https_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@3.0.0")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -1085,8 +801,8 @@ fn compile_git_tag_https_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1095,33 +811,19 @@ fn compile_git_tag_https_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_long_commit_https_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str( "flask @ git+https://github.com/pallets/flask.git@d92b64aa275841b0c9aea3903aba72fbc4275d91", )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in click==8.1.7 # via flask flask @ git+https://github.com/pallets/flask.git@d92b64aa275841b0c9aea3903aba72fbc4275d91 @@ -1138,8 +840,8 @@ fn compile_git_long_commit_https_dependency() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1148,31 +850,17 @@ fn compile_git_long_commit_https_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_short_commit_https_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@d92b64a")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in click==8.1.7 # via flask flask @ git+https://github.com/pallets/flask.git@d92b64aa275841b0c9aea3903aba72fbc4275d91 @@ -1189,8 +877,8 @@ fn compile_git_short_commit_https_dependency() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1199,32 +887,18 @@ fn compile_git_short_commit_https_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_refs_https_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in .write_str("flask @ git+https://github.com/pallets/flask.git@refs/pull/5313/head")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -1243,8 +917,8 @@ fn compile_git_refs_https_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1253,37 +927,23 @@ fn compile_git_refs_https_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_subdirectory_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("example-pkg-a @ git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_a")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in example-pkg-a @ git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_a ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1292,39 +952,25 @@ fn compile_git_subdirectory_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_concurrent_access() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in .write_str("example-pkg-a @ git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_a\nexample-pkg-b @ git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_b")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in example-pkg-a @ git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_a example-pkg-b @ git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_b ----- stderr ----- Resolved 2 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1333,27 +979,13 @@ fn compile_git_concurrent_access() -> Result<()> { #[test] #[cfg(feature = "git")] fn compile_git_mismatched_name() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in .write_str("flask @ git+https://github.com/pallets/flask.git@2.0.0\ndask @ git+https://github.com/pallets/flask.git@3.0.0")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -1361,8 +993,8 @@ fn compile_git_mismatched_name() -> Result<()> { ----- stderr ----- error: Failed to download and build: dask @ git+https://github.com/pallets/flask.git@3.0.0 Caused by: Package metadata name `flask` does not match given name `dask` - "###); - }); + "### + ); Ok(()) } @@ -1371,31 +1003,17 @@ fn compile_git_mismatched_name() -> Result<()> { /// duplicate dependency from `PyPI`. #[test] fn mixed_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask==3.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/c3/fc/254c3e9b5feb89ff5b9076a23218dafbc99c96ac5941e900b71206e6313b/werkzeug-3.0.1-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -1414,8 +1032,8 @@ fn mixed_url_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1424,26 +1042,12 @@ fn mixed_url_dependency() -> Result<()> { /// should result in a conflict. #[test] fn conflicting_direct_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("werkzeug==3.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -1453,8 +1057,8 @@ fn conflicting_direct_url_dependency() -> Result<()> { ╰─▶ Because there is no version of werkzeug==3.0.0 and you require werkzeug==3.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + "### + ); Ok(()) } @@ -1463,37 +1067,23 @@ fn conflicting_direct_url_dependency() -> Result<()> { /// should prefer the direct URL dependency. #[test] fn compatible_direct_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("werkzeug==2.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in werkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1501,26 +1091,12 @@ fn compatible_direct_url_dependency() -> Result<()> { /// Request Werkzeug via two different URLs at different versions, which should result in a conflict. #[test] fn conflicting_repeated_url_dependency_version_mismatch() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("werkzeug @ https://files.pythonhosted.org/packages/bd/24/11c3ea5a7e866bf2d97f0501d0b4b1c9bbeade102bb4b588f0d2919a5212/Werkzeug-2.0.1-py3-none-any.whl\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -1531,8 +1107,8 @@ fn conflicting_repeated_url_dependency_version_mismatch() -> Result<()> { package `werkzeug`: - https://files.pythonhosted.org/packages/bd/24/11c3ea5a7e866bf2d97f0501d0b4b1c9bbeade102bb4b588f0d2919a5212/Werkzeug-2.0.1-py3-none-any.whl - https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl - "###); - }); + "### + ); Ok(()) } @@ -1542,26 +1118,12 @@ fn conflicting_repeated_url_dependency_version_mismatch() -> Result<()> { #[test] #[cfg(feature = "git")] fn conflicting_repeated_url_dependency_version_match() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("werkzeug @ git+https://github.com/pallets/werkzeug.git@2.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -1572,8 +1134,8 @@ fn conflicting_repeated_url_dependency_version_match() -> Result<()> { package `werkzeug`: - git+https://github.com/pallets/werkzeug.git@2.0.0 - https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl - "###); - }); + "### + ); Ok(()) } @@ -1581,26 +1143,12 @@ fn conflicting_repeated_url_dependency_version_match() -> Result<()> { /// Request Flask, but include a URL dependency for a conflicting version of Werkzeug. #[test] fn conflicting_transitive_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask==3.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -1611,8 +1159,8 @@ fn conflicting_transitive_url_dependency() -> Result<()> { is available, we can conclude that flask==3.0.0 cannot be used. And because you require flask==3.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + "### + ); Ok(()) } @@ -1622,34 +1170,20 @@ fn conflicting_transitive_url_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn disallowed_transitive_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("transitive_url_dependency @ https://github.com/astral-sh/ruff/files/14078476/transitive_url_dependency.zip")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 2 ----- stdout ----- ----- stderr ----- error: Package `werkzeug` attempted to resolve via URL: git+https://github.com/pallets/werkzeug@2.0.0. URL dependencies must be expressed as direct requirements or constraints. Consider adding `werkzeug @ git+https://github.com/pallets/werkzeug@2.0.0` to your dependencies or constraints file. - "###); - }); + "### + ); Ok(()) } @@ -1659,44 +1193,30 @@ fn disallowed_transitive_url_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn allowed_transitive_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("transitive_url_dependency @ https://github.com/astral-sh/ruff/files/14078476/transitive_url_dependency.zip")?; - let constraints_txt = temp_dir.child("constraints.txt"); + let constraints_txt = context.temp_dir.child("constraints.txt"); constraints_txt.write_str("werkzeug @ git+https://github.com/pallets/werkzeug@2.0.0")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--constraint") - .arg("constraints.txt") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("constraints.txt"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --constraint constraints.txt --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --constraint constraints.txt transitive-url-dependency @ https://github.com/astral-sh/ruff/files/14078476/transitive_url_dependency.zip werkzeug @ git+https://github.com/pallets/werkzeug@af160e0b6b7ddd81c22f1652c728ff5ac72d5c74 # via transitive-url-dependency ----- stderr ----- Resolved 2 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1707,44 +1227,30 @@ fn allowed_transitive_url_dependency() -> Result<()> { #[test] #[cfg(feature = "git")] fn allowed_transitive_canonical_url_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("transitive_url_dependency @ https://github.com/astral-sh/ruff/files/14078476/transitive_url_dependency.zip")?; - let constraints_txt = temp_dir.child("constraints.txt"); + let constraints_txt = context.temp_dir.child("constraints.txt"); constraints_txt.write_str("werkzeug @ git+https://github.com/pallets/werkzeug.git@2.0.0")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--constraint") - .arg("constraints.txt") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("constraints.txt"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --constraint constraints.txt --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --constraint constraints.txt transitive-url-dependency @ https://github.com/astral-sh/ruff/files/14078476/transitive_url_dependency.zip werkzeug @ git+https://github.com/pallets/werkzeug@af160e0b6b7ddd81c22f1652c728ff5ac72d5c74 # via transitive-url-dependency ----- stderr ----- Resolved 2 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1752,11 +1258,8 @@ fn allowed_transitive_canonical_url_dependency() -> Result<()> { /// Resolve packages from all optional dependency groups in a `pyproject.toml` file. #[test] fn compile_pyproject_toml_all_extras() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -1773,25 +1276,14 @@ optional-dependencies.bar = [ "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("pyproject.toml") - .arg("--all-extras") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--all-extras"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile pyproject.toml --all-extras --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z pyproject.toml --all-extras anyio==4.0.0 # via httpcore asgiref==3.7.2 @@ -1813,8 +1305,8 @@ optional-dependencies.bar = [ ----- stderr ----- Resolved 9 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -1822,11 +1314,8 @@ optional-dependencies.bar = [ /// Resolve packages from all optional dependency groups in a `pyproject.toml` file. #[test] fn compile_does_not_allow_both_extra_and_all_extras() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -1843,22 +1332,11 @@ optional-dependencies.bar = [ "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("pyproject.toml") .arg("--all-extras") .arg("--extra") - .arg("foo") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), + .arg("foo"), @r###" success: false exit_code: 2 @@ -1867,11 +1345,11 @@ optional-dependencies.bar = [ ----- stderr ----- error: the argument '--all-extras' cannot be used with '--extra ' - Usage: puffin pip compile --all-extras --cache-dir [CACHE_DIR] + Usage: puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer --all-extras ... For more information, try '--help'. - "###); - }); + "### + ); Ok(()) } @@ -1879,11 +1357,8 @@ optional-dependencies.bar = [ /// Compile requirements that cannot be solved due to conflict in a `pyproject.toml` fil;e. #[test] fn compile_unsolvable_requirements() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -1894,19 +1369,8 @@ dependencies = ["django==5.0b1", "django==5.0a1"] "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("pyproject.toml") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("pyproject.toml"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -1915,8 +1379,8 @@ dependencies = ["django==5.0b1", "django==5.0a1"] × No solution found when resolving dependencies: ╰─▶ my-project cannot be used because there are conflicting versions for `django`: `django==5.0b1` does not intersect with `django==5.0a1` - "###); - }); + "### + ); Ok(()) } @@ -1925,11 +1389,8 @@ dependencies = ["django==5.0b1", "django==5.0a1"] /// a requirement with a version that is not available online. #[test] fn compile_unsolvable_requirements_version_not_available() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let pyproject_toml = temp_dir.child("pyproject.toml"); + let context = TestContext::new("3.12"); + let pyproject_toml = context.temp_dir.child("pyproject.toml"); pyproject_toml.write_str( r#"[build-system] requires = ["setuptools", "wheel"] @@ -1940,19 +1401,8 @@ dependencies = ["django==300.1.4"] "#, )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("pyproject.toml") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("pyproject.toml"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -1962,8 +1412,8 @@ dependencies = ["django==300.1.4"] ╰─▶ Because there is no version of django==300.1.4 and my-project depends on django==300.1.4, we can conclude that the requirements are unsatisfiable. - "###); - }); + "### + ); Ok(()) } @@ -1971,17 +1421,11 @@ dependencies = ["django==300.1.4"] /// Resolve at a specific time in the past #[test] fn compile_exclude_newer() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("tqdm")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .arg("pip") .arg("compile") .arg("requirements.in") @@ -1990,9 +1434,9 @@ fn compile_exclude_newer() -> Result<()> { // 4.64.1: 2022-09-03T11:10:27.148080Z .arg("2022-04-04T12:00:00Z") .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg(context.cache_dir.path()) + .env("VIRTUAL_ENV", context.venv.as_os_str()) + .current_dir(context.temp_dir.path()), @r###" success: true exit_code: 0 ----- stdout ----- @@ -2002,24 +1446,21 @@ fn compile_exclude_newer() -> Result<()> { ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - // Use a date as input instead. - // We interpret a date as including this day - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + // Use a date as input instead. + // We interpret a date as including this day + puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .arg("pip") .arg("compile") .arg("requirements.in") .arg("--exclude-newer") .arg("2022-04-04") .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg(context.cache_dir.path()) + .env("VIRTUAL_ENV", context.venv.as_os_str()) + .current_dir(context.temp_dir.path()), @r###" success: true exit_code: 0 ----- stdout ----- @@ -2029,23 +1470,20 @@ fn compile_exclude_newer() -> Result<()> { ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - // Check the error message for invalid datetime - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + // Check the error message for invalid datetime + puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .arg("pip") .arg("compile") .arg("requirements.in") .arg("--exclude-newer") .arg("2022-04-04+02:00") .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg(context.cache_dir.path()) + .env("VIRTUAL_ENV", context.venv.as_os_str()) + .current_dir(context.temp_dir.path()), @r###" success: false exit_code: 2 ----- stdout ----- @@ -2054,8 +1492,8 @@ fn compile_exclude_newer() -> Result<()> { error: invalid value '2022-04-04+02:00' for '--exclude-newer ': Neither a valid date (trailing input) not a valid datetime (input contains invalid characters) For more information, try '--help'. - "###); - }); + "### + ); Ok(()) } @@ -2063,17 +1501,14 @@ fn compile_exclude_newer() -> Result<()> { /// Resolve a local path dependency on a specific wheel. #[test] fn compile_wheel_path_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - + let context = TestContext::new("3.12"); // Download a wheel. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?; - let flask_wheel = temp_dir.child("flask-3.0.0-py3-none-any.whl"); + let flask_wheel = context.temp_dir.child("flask-3.0.0-py3-none-any.whl"); let mut flask_wheel_file = std::fs::File::create(&flask_wheel)?; std::io::copy(&mut response.bytes()?.as_ref(), &mut flask_wheel_file)?; - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str(&format!( "flask @ {}", Url::from_file_path(flask_wheel.path()).unwrap() @@ -2084,24 +1519,13 @@ fn compile_wheel_path_dependency() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(filters, context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -2121,30 +1545,18 @@ fn compile_wheel_path_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] "###); - }); // Run the same operation, but this time with a relative path. - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ file:flask-3.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -2163,31 +1575,20 @@ fn compile_wheel_path_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); // Run the same operation, but this time with a relative path. - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ file://flask-3.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -2206,31 +1607,20 @@ fn compile_wheel_path_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); // Run the same operation, but this time with a relative path. - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ ./flask-3.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -2249,8 +1639,8 @@ fn compile_wheel_path_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -2258,17 +1648,14 @@ fn compile_wheel_path_dependency() -> Result<()> { /// Resolve a local path dependency on a specific source distribution. #[test] fn compile_source_distribution_path_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - + let context = TestContext::new("3.12"); // Download a source distribution. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/d8/09/c1a7354d3925a3c6c8cfdebf4245bae67d633ffda1ba415add06ffc839c5/flask-3.0.0.tar.gz")?; - let flask_wheel = temp_dir.child("flask-3.0.0.tar.gz"); + let flask_wheel = context.temp_dir.child("flask-3.0.0.tar.gz"); let mut flask_wheel_file = std::fs::File::create(&flask_wheel)?; std::io::copy(&mut response.bytes()?.as_ref(), &mut flask_wheel_file)?; - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str(&format!( "flask @ {}", Url::from_file_path(flask_wheel.path()).unwrap() @@ -2279,24 +1666,13 @@ fn compile_source_distribution_path_dependency() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(filters, context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -2316,7 +1692,6 @@ fn compile_source_distribution_path_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] "###); - }); Ok(()) } @@ -2324,11 +1699,8 @@ fn compile_source_distribution_path_dependency() -> Result<()> { /// Resolve a local path dependency to a non-existent file. #[test] fn compile_wheel_path_dependency_missing() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ file:///path/to/flask-3.0.0-py3-none-any.whl")?; // In addition to the standard filters, remove the temporary directory from the snapshot. @@ -2336,19 +1708,8 @@ fn compile_wheel_path_dependency_missing() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(filters, context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -2356,7 +1717,6 @@ fn compile_wheel_path_dependency_missing() -> Result<()> { ----- stderr ----- error: Distribution not found at: file://[TEMP_DIR]/flask-3.0.0-py3-none-any.whl "###); - }); Ok(()) } @@ -2364,37 +1724,23 @@ fn compile_wheel_path_dependency_missing() -> Result<()> { /// Resolve a yanked version of `attrs` by specifying the version directly. #[test] fn compile_yanked_version_direct() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("attrs==21.1.0")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in attrs==21.1.0 ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -2402,26 +1748,12 @@ fn compile_yanked_version_direct() -> Result<()> { /// Fail to resolve `attrs` due to the indirect use of a yanked version (`21.1.0`). #[test] fn compile_yanked_version_indirect() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("attrs>20.3.0,<21.2.0")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 1 ----- stdout ----- @@ -2431,8 +1763,8 @@ fn compile_yanked_version_indirect() -> Result<()> { ╰─▶ Because there are no versions of attrs that satisfy attrs>20.3.0,<21.2.0 and you require attrs>20.3.0,<21.2.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + "### + ); Ok(()) } @@ -2441,36 +1773,22 @@ fn compile_yanked_version_indirect() -> Result<()> { /// requirement with an incompatible version. #[test] fn override_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask==3.0.0")?; - let overrides_txt = temp_dir.child("overrides.txt"); + let overrides_txt = context.temp_dir.child("overrides.txt"); overrides_txt.write_str("werkzeug==2.3.0")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--override") - .arg("overrides.txt") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("overrides.txt"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --override overrides.txt --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --override overrides.txt blinker==1.7.0 # via flask click==8.1.7 @@ -2489,8 +1807,8 @@ fn override_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -2499,38 +1817,24 @@ fn override_dependency() -> Result<()> { /// override it with a multi-line override. #[test] fn override_multi_dependency() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - let overrides_txt = temp_dir.child("overrides.txt"); + let overrides_txt = context.temp_dir.child("overrides.txt"); overrides_txt.write_str( "tomli>=1.1.0; python_version >= '3.11'\ntomli<1.0.0; python_version < '3.11'", )?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--override") - .arg("overrides.txt") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("overrides.txt"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --override overrides.txt --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --override overrides.txt black==23.10.1 click==8.1.7 # via black @@ -2547,8 +1851,8 @@ fn override_multi_dependency() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -2556,31 +1860,17 @@ fn override_multi_dependency() -> Result<()> { /// Request an extra that doesn't exist on the specified package. #[test] fn missing_registry_extra() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black[tensorboard]==23.10.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in black==23.10.1 click==8.1.7 # via black @@ -2596,8 +1886,8 @@ fn missing_registry_extra() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] warning: The package `black==23.10.1` does not have an extra named `tensorboard`. - "###); - }); + "### + ); Ok(()) } @@ -2605,31 +1895,17 @@ fn missing_registry_extra() -> Result<()> { /// Request an extra that doesn't exist on the specified package. #[test] fn missing_url_extra() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask[tensorboard] @ https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -2649,8 +1925,8 @@ fn missing_url_extra() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] warning: The package `flask @ https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl` does not have an extra named `tensorboard`. - "###); - }); + "### + ); Ok(()) } @@ -2659,31 +1935,17 @@ fn missing_url_extra() -> Result<()> { /// requirements file. #[test] fn preserve_url() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ https://files.PYTHONHOSTED.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -2702,8 +1964,8 @@ fn preserve_url() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -2712,37 +1974,23 @@ fn preserve_url() -> Result<()> { /// the requirements file. #[test] fn preserve_env_var() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - + let context = TestContext::new("3.12"); // Download a wheel. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?; - let flask_wheel = temp_dir.child("flask-3.0.0-py3-none-any.whl"); + let flask_wheel = context.temp_dir.child("flask-3.0.0-py3-none-any.whl"); let mut flask_wheel_file = std::fs::File::create(flask_wheel)?; std::io::copy(&mut response.bytes()?.as_ref(), &mut flask_wheel_file)?; - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask @ file://${PROJECT_ROOT}/flask-3.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in blinker==1.7.0 # via flask click==8.1.7 @@ -2761,8 +2009,8 @@ fn preserve_env_var() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -2770,11 +2018,8 @@ fn preserve_env_var() -> Result<()> { #[test] #[cfg(feature = "maturin")] fn compile_editable() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str(indoc! {r" -e ../../scripts/editable-installs/poetry_editable -e ${PROJECT_ROOT}/../../scripts/editable-installs/maturin_editable @@ -2788,23 +2033,20 @@ fn compile_editable() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME)) .arg("pip") .arg("compile") .arg(requirements_in.path()) .arg("--cache-dir") - .arg(cache_dir.path()) + .arg(context.cache_dir.path()) .arg("--exclude-newer") .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()), @r###" + .env("VIRTUAL_ENV", context.venv.as_os_str()), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile requirements.in --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z aiohttp==3.9.0 # via black aiosignal==1.3.1 @@ -2834,7 +2076,6 @@ fn compile_editable() -> Result<()> { Built 3 editables in [TIME] Resolved 12 packages in [TIME] "###); - }); Ok(()) } @@ -2842,11 +2083,8 @@ fn compile_editable() -> Result<()> { #[test] #[ignore] fn cache_errors_are_non_fatal() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); // No git dep, git has its own locking strategy requirements_in.write_str(indoc! {r" # pypi wheel @@ -2859,7 +2097,8 @@ fn cache_errors_are_non_fatal() -> Result<()> { })?; // Pick a file from each kind of cache - let interpreter_cache = cache_dir + let interpreter_cache = context + .cache_dir .path() .join("interpreter-v0") .read_dir()? @@ -2877,28 +2116,20 @@ fn cache_errors_are_non_fatal() -> Result<()> { ]; let check = || { - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + puffin_snapshot!(context.compile() .arg("pip") .arg("compile") .arg(requirements_in.path()) - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) // It's sufficient to check that we resolve to a fix number of packages - .stdout(std::process::Stdio::null()) - .env("VIRTUAL_ENV", venv.as_os_str()), @r###" + .stdout(std::process::Stdio::null()), @r###" success: true exit_code: 0 ----- stdout ----- ----- stderr ----- Resolved 13 packages in [TIME] - "###); - }); + "### + ); }; insta::allow_duplicates! { @@ -2906,7 +2137,7 @@ fn cache_errors_are_non_fatal() -> Result<()> { // Replace some cache files with invalid contents for file in &cache_files { - let file = cache_dir.join(file); + let file = context.cache_dir.join(file); if !file.is_file() { bail!("Missing cache file {}", file.display()); } @@ -2921,7 +2152,7 @@ fn cache_errors_are_non_fatal() -> Result<()> { // Make some files unreadable, so that the read instead of the deserialization will fail for file in cache_files { - let file = cache_dir.join(file); + let file = context.cache_dir.join(file); if !file.is_file() { bail!("Missing cache file {}", file.display()); } @@ -2943,39 +2174,33 @@ fn cache_errors_are_non_fatal() -> Result<()> { /// Resolve a distribution from an HTML-only registry. #[test] fn compile_html() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("jinja2<=3.1.2")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) + puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .arg("pip") .arg("compile") .arg("requirements.in") .arg("--cache-dir") - .arg(cache_dir.path()) + .arg(context.cache_dir.path()) .arg("--index-url") .arg("https://download.pytorch.org/whl") - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .env("VIRTUAL_ENV", context.venv.as_os_str()) + .current_dir(context.temp_dir.path()), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile requirements.in --cache-dir [CACHE_DIR] --index-url https://download.pytorch.org/whl jinja2==3.1.2 markupsafe==2.1.3 # via jinja2 ----- stderr ----- Resolved 2 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -2983,70 +2208,45 @@ fn compile_html() -> Result<()> { /// Resolve a distribution from a registry with and without a trailing slash. #[test] fn trailing_slash() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("jinja2")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) .arg("--index-url") - .arg("https://test.pypi.org/simple") - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("https://test.pypi.org/simple"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --index-url https://test.pypi.org/simple jinja2==3.1.2 markupsafe==2.1.3 # via jinja2 ----- stderr ----- Resolved 2 packages in [TIME] - "###); - }); + "### + ); - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) .arg("--index-url") - .arg("https://test.pypi.org/simple/") - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("https://test.pypi.org/simple/"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --index-url https://test.pypi.org/simple/ jinja2==3.1.2 markupsafe==2.1.3 # via jinja2 ----- stderr ----- Resolved 2 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3054,31 +2254,17 @@ fn trailing_slash() -> Result<()> { /// Resolve a project without a `pyproject.toml`, using the PEP 517 build backend (default). #[test] fn compile_legacy_sdist_pep_517() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flake8 @ https://files.pythonhosted.org/packages/66/53/3ad4a3b74d609b3b9008a10075c40e7c8909eae60af53623c3888f7a529a/flake8-6.0.0.tar.gz")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in flake8 @ https://files.pythonhosted.org/packages/66/53/3ad4a3b74d609b3b9008a10075c40e7c8909eae60af53623c3888f7a529a/flake8-6.0.0.tar.gz mccabe==0.7.0 # via flake8 @@ -3089,8 +2275,8 @@ fn compile_legacy_sdist_pep_517() -> Result<()> { ----- stderr ----- Resolved 4 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3098,32 +2284,18 @@ fn compile_legacy_sdist_pep_517() -> Result<()> { /// Resolve a project without a `pyproject.toml`, using `setuptools` directly. #[test] fn compile_legacy_sdist_setuptools() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flake8 @ https://files.pythonhosted.org/packages/66/53/3ad4a3b74d609b3b9008a10075c40e7c8909eae60af53623c3888f7a529a/flake8-6.0.0.tar.gz")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--legacy-setup-py") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--legacy-setup-py"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --legacy-setup-py --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --legacy-setup-py flake8 @ https://files.pythonhosted.org/packages/66/53/3ad4a3b74d609b3b9008a10075c40e7c8909eae60af53623c3888f7a529a/flake8-6.0.0.tar.gz mccabe==0.7.0 # via flake8 @@ -3134,8 +2306,8 @@ fn compile_legacy_sdist_setuptools() -> Result<()> { ----- stderr ----- Resolved 4 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3143,32 +2315,18 @@ fn compile_legacy_sdist_setuptools() -> Result<()> { /// Include hashes in the generated output. #[test] fn generate_hashes() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("flask==3.0.0")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--generate-hashes") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--generate-hashes"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --generate-hashes --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --generate-hashes blinker==1.7.0 \ --hash=sha256:c3f865d4d54db7abc53758a01601cf343fe55b84c1de4e3fa910e420b438d5b9 \ --hash=sha256:e6820ff6fa4e4d1d8e2747c2283749c3f547e4fee112b98555cdcdae32996182 @@ -3259,8 +2417,8 @@ fn generate_hashes() -> Result<()> { ----- stderr ----- Resolved 7 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3268,11 +2426,8 @@ fn generate_hashes() -> Result<()> { /// Compile using `--find-links` with a local directory. #[test] fn find_links_directory() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str(indoc! {r" tqdm numpy @@ -3285,26 +2440,15 @@ fn find_links_directory() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(filters, context.compile() .arg("requirements.in") .arg("--find-links") - .arg(project_root.join("scripts/wheels/")) - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg(project_root.join("scripts/wheels/")), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --find-links [PROJECT_ROOT]/scripts/wheels/ --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --find-links [PROJECT_ROOT]/scripts/wheels/ markupsafe==2.1.3 # via werkzeug numpy==1.26.2 @@ -3314,7 +2458,6 @@ fn find_links_directory() -> Result<()> { ----- stderr ----- Resolved 4 packages in [TIME] "###); - }); Ok(()) } @@ -3322,40 +2465,26 @@ fn find_links_directory() -> Result<()> { /// Compile using `--find-links` with a URL by resolving `tqdm` from the `PyTorch` wheels index. #[test] fn find_links_url() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("tqdm")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--no-index") .arg("--find-links") - .arg("https://download.pytorch.org/whl/torch_stable.html") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("https://download.pytorch.org/whl/torch_stable.html"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --no-index --find-links https://download.pytorch.org/whl/torch_stable.html --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --no-index --find-links https://download.pytorch.org/whl/torch_stable.html tqdm==4.64.1 ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3364,41 +2493,27 @@ fn find_links_url() -> Result<()> { /// with the URL itself provided in a `requirements.txt` file. #[test] fn find_links_requirements_txt() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("-f https://download.pytorch.org/whl/torch_stable.html\ntqdm")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--no-index") - .arg("--emit-find-links") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--emit-find-links"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --no-index --emit-find-links --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --no-index --emit-find-links --find-links https://download.pytorch.org/whl/torch_stable.html tqdm==4.64.1 ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3407,14 +2522,11 @@ fn find_links_requirements_txt() -> Result<()> { /// Nothing should change. #[test] fn upgrade_none() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - let requirements_txt = temp_dir.child("requirements.txt"); + let requirements_txt = context.temp_dir.child("requirements.txt"); requirements_txt.write_str(indoc! {r" black==23.10.1 click==8.1.2 @@ -3429,29 +2541,18 @@ fn upgrade_none() -> Result<()> { # via black "})?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--output-file") - .arg("requirements.txt") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("requirements.txt"), @r###" success: true exit_code: 0 ----- stdout ----- ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); // Read the output requirements, but skip the header. let resolution = fs::read_to_string(requirements_txt.path())? @@ -3479,14 +2580,11 @@ fn upgrade_none() -> Result<()> { /// Both packages should be upgraded. #[test] fn upgrade_all() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - let requirements_txt = temp_dir.child("requirements.txt"); + let requirements_txt = context.temp_dir.child("requirements.txt"); requirements_txt.write_str(indoc! {r" # This file was autogenerated by Puffin v0.0.1 via the following command: # puffin pip compile requirements.in --python-version 3.12 --cache-dir [CACHE_DIR] @@ -3503,30 +2601,19 @@ fn upgrade_all() -> Result<()> { # via black "})?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--output-file") .arg("requirements.txt") - .arg("--upgrade") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--upgrade"), @r###" success: true exit_code: 0 ----- stdout ----- ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); // Read the output requirements, but skip the header. let resolution = fs::read_to_string(requirements_txt.path())? @@ -3554,14 +2641,11 @@ fn upgrade_all() -> Result<()> { /// Only `click` should be upgraded. #[test] fn upgrade_package() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - let requirements_txt = temp_dir.child("requirements.txt"); + let requirements_txt = context.temp_dir.child("requirements.txt"); requirements_txt.write_str(indoc! {r" # This file was autogenerated by Puffin v0.0.1 via the following command: # puffin pip compile requirements.in --python-version 3.12 --cache-dir [CACHE_DIR] @@ -3578,31 +2662,20 @@ fn upgrade_package() -> Result<()> { # via black "})?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--output-file") .arg("requirements.txt") .arg("--upgrade-package") - .arg("click") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("click"), @r###" success: true exit_code: 0 ----- stdout ----- ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); // Read the output requirements, but skip the header. let resolution = fs::read_to_string(requirements_txt.path())? @@ -3630,11 +2703,8 @@ fn upgrade_package() -> Result<()> { /// Attempt to resolve a requirement at a path that doesn't exist. #[test] fn missing_path_requirement() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("django @ file:///tmp/django-3.2.8.tar.gz")?; let filters: Vec<_> = [(r"/[A-Z]:/", "/")] @@ -3642,19 +2712,8 @@ fn missing_path_requirement() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(filters, context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -3662,7 +2721,6 @@ fn missing_path_requirement() -> Result<()> { ----- stderr ----- error: Distribution not found at: file:///tmp/django-3.2.8.tar.gz "###); - }); Ok(()) } @@ -3670,11 +2728,8 @@ fn missing_path_requirement() -> Result<()> { /// Attempt to resolve an editable requirement at a path that doesn't exist. #[test] fn missing_editable_requirement() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("-e ../tmp/django-3.2.8.tar.gz")?; // File url, absolute Unix path or absolute Windows path @@ -3687,19 +2742,8 @@ fn missing_editable_requirement() -> Result<()> { .chain(INSTA_FILTERS.to_vec()) .collect::>(); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(filters, context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -3709,7 +2753,6 @@ fn missing_editable_requirement() -> Result<()> { Caused by: Failed to build editable: file://[TEMP_DIR]/django-3.2.8.tar.gz Caused by: Source distribution not found at: /[TEMP_DIR]/django-3.2.8.tar.gz "###); - }); Ok(()) } @@ -3717,26 +2760,12 @@ fn missing_editable_requirement() -> Result<()> { /// Attempt to resolve a URL requirement without a package name. #[test] fn missing_package_name() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -3746,8 +2775,8 @@ fn missing_package_name() -> Result<()> { Caused by: URL requirement must be preceded by a package name. Add the name of the package before the URL (e.g., `package_name @ https://...`). https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - "###); - }); + "### + ); Ok(()) } @@ -3755,32 +2784,18 @@ fn missing_package_name() -> Result<()> { /// Exclude annotations from the output. #[test] fn no_annotate() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--no-annotate") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--no-annotate"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --no-annotate --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --no-annotate black==23.10.1 click==8.1.7 mypy-extensions==1.0.0 @@ -3790,8 +2805,8 @@ fn no_annotate() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3799,27 +2814,13 @@ fn no_annotate() -> Result<()> { /// Exclude header from the output. #[test] fn no_header() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--no-header") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--no-header"), @r###" success: true exit_code: 0 ----- stdout ----- @@ -3837,8 +2838,8 @@ fn no_header() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3846,32 +2847,18 @@ fn no_header() -> Result<()> { /// Emit warnings when users pass redundant options from `pip-compile`. #[test] fn allow_unsafe() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("werkzeug==3.0.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--allow-unsafe") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--allow-unsafe"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --allow-unsafe --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --allow-unsafe markupsafe==2.1.3 # via werkzeug werkzeug==3.0.1 @@ -3879,8 +2866,8 @@ fn allow_unsafe() -> Result<()> { ----- stderr ----- warning: pip-compile's `--allow-unsafe` has no effect (Puffin can safely pin `pip` and other packages). Resolved 2 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3888,35 +2875,21 @@ fn allow_unsafe() -> Result<()> { /// Emit warnings when users pass redundant options from `pip-compile`. #[test] fn resolver_legacy() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("werkzeug==3.0.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") - .arg("--resolver=legacy") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("--resolver=legacy"), @r###" success: false exit_code: 2 ----- stdout ----- ----- stderr ----- error: pip-compile's `--resolver=legacy` is unsupported (Puffin always backtracks). - "###); - }); + "### + ); Ok(()) } @@ -3924,34 +2897,20 @@ fn resolver_legacy() -> Result<()> { /// Emit the `--index-url` and `--extra-index-url` locations. #[test] fn emit_index_urls() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--emit-index-url") .arg("--extra-index-url") - .arg("https://test.pypi.org/simple/") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("https://test.pypi.org/simple/"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --emit-index-url --extra-index-url https://test.pypi.org/simple/ --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --emit-index-url --extra-index-url https://test.pypi.org/simple/ --index-url https://pypi.org/simple --extra-index-url https://test.pypi.org/simple/ @@ -3969,8 +2928,8 @@ fn emit_index_urls() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -3978,34 +2937,20 @@ fn emit_index_urls() -> Result<()> { /// Emit the `--find-links` locations. #[test] fn emit_find_links() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("black==23.10.1")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--emit-find-links") .arg("--find-links") - .arg("./") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("./"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --emit-find-links --find-links ./ --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --emit-find-links --find-links ./ --find-links ./ black==23.10.1 @@ -4022,8 +2967,8 @@ fn emit_find_links() -> Result<()> { ----- stderr ----- Resolved 6 packages in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -4031,34 +2976,20 @@ fn emit_find_links() -> Result<()> { /// Respect the `--no-index` flag in a `requirements.txt` file. #[test] fn no_index_requirements_txt() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("--no-index\ntqdm")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + puffin_snapshot!(context.compile() + .arg("requirements.in"), @r###" success: false exit_code: 2 ----- stdout ----- ----- stderr ----- error: tqdm isn't available locally, but making network requests to registries was banned. - "###); - }); + "### + ); Ok(()) } @@ -4067,39 +2998,25 @@ fn no_index_requirements_txt() -> Result<()> { /// file. #[test] fn index_url_requirements_txt() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("--index-url https://google.com\ntqdm")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--index-url") - .arg("https://pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("https://pypi.org/simple"), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by Puffin v[VERSION] via the following command: - # puffin pip compile requirements.in --index-url https://pypi.org/simple --cache-dir [CACHE_DIR] + # puffin pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --index-url https://pypi.org/simple tqdm==4.66.1 ----- stderr ----- Resolved 1 package in [TIME] - "###); - }); + "### + ); Ok(()) } @@ -4107,39 +3024,25 @@ fn index_url_requirements_txt() -> Result<()> { /// Raise an error when multiple `requirements.txt` files include `--index-url` flags. #[test] fn conflicting_index_urls_requirements_txt() -> Result<()> { - let temp_dir = TempDir::new()?; - let cache_dir = TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); - - let requirements_in = temp_dir.child("requirements.in"); + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("--index-url https://google.com\ntqdm")?; - let constraints_in = temp_dir.child("constraints.in"); + let constraints_in = context.temp_dir.child("constraints.in"); constraints_in.write_str("--index-url https://wikipedia.org\nflask")?; - insta::with_settings!({ - filters => INSTA_FILTERS.to_vec() - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") + puffin_snapshot!(context.compile() .arg("requirements.in") .arg("--constraint") - .arg("constraints.in") - .arg("--cache-dir") - .arg(cache_dir.path()) - .arg("--exclude-newer") - .arg(EXCLUDE_NEWER) - .env("VIRTUAL_ENV", venv.as_os_str()) - .current_dir(&temp_dir), @r###" + .arg("constraints.in"), @r###" success: false exit_code: 2 ----- stdout ----- ----- stderr ----- error: Multiple index URLs specified: `https://google.com/` vs.` https://wikipedia.org/ - "###); - }); + "### + ); Ok(()) } diff --git a/crates/puffin/tests/pip_install.rs b/crates/puffin/tests/pip_install.rs index e45a536fb..2951bef1a 100644 --- a/crates/puffin/tests/pip_install.rs +++ b/crates/puffin/tests/pip_install.rs @@ -12,13 +12,10 @@ use indoc::indoc; use insta_cmd::_macro_support::insta; use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; -use common::{create_venv_py312, venv_to_interpreter, BIN_NAME, INSTA_FILTERS}; +use common::{create_venv, venv_to_interpreter, BIN_NAME, EXCLUDE_NEWER, INSTA_FILTERS}; mod common; -// Exclude any packages uploaded after this date. -static EXCLUDE_NEWER: &str = "2023-11-18T12:00:00Z"; - fn assert_command(venv: &Path, command: &str, temp_dir: &Path) -> Assert { Command::new(venv_to_interpreter(venv)) // https://github.com/python/cpython/issues/75953 @@ -66,7 +63,7 @@ fn missing_requirements_txt() -> Result<()> { fn no_solution() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .arg("pip") @@ -101,7 +98,7 @@ fn no_solution() -> Result<()> { fn install_package() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Install Flask. insta::with_settings!({ @@ -146,7 +143,7 @@ fn install_package() -> Result<()> { fn install_requirements_txt() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Install Flask. let requirements_txt = temp_dir.child("requirements.txt"); @@ -225,7 +222,7 @@ fn install_requirements_txt() -> Result<()> { fn respect_installed() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Install Flask. let requirements_txt = temp_dir.child("requirements.txt"); @@ -374,7 +371,7 @@ fn respect_installed() -> Result<()> { fn allow_incompatibilities() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Install Flask, which relies on `Werkzeug>=3.0.0`. let requirements_txt = temp_dir.child("requirements.txt"); @@ -461,7 +458,7 @@ fn allow_incompatibilities() -> Result<()> { fn install_editable() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let current_dir = std::env::current_dir()?; let workspace_dir = regex::escape( @@ -576,7 +573,7 @@ fn install_editable() -> Result<()> { fn install_editable_and_registry() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let current_dir = std::env::current_dir()?; let workspace_dir = regex::escape( @@ -716,7 +713,7 @@ fn install_editable_and_registry() -> Result<()> { fn reinstall_build_system() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Install devpi. let requirements_txt = temp_dir.child("requirements.txt"); @@ -769,7 +766,7 @@ fn reinstall_build_system() -> Result<()> { fn install_no_binary() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -814,7 +811,7 @@ fn install_no_binary() -> Result<()> { fn install_no_binary_subset() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -862,7 +859,7 @@ fn install_no_binary_subset() -> Result<()> { fn reinstall_no_binary() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // The first installation should use a pre-built wheel insta::with_settings!({ @@ -968,7 +965,7 @@ fn reinstall_no_binary() -> Result<()> { fn install_executable() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1014,7 +1011,7 @@ fn install_executable() -> Result<()> { fn install_executable_copy() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1062,7 +1059,7 @@ fn install_executable_copy() -> Result<()> { fn install_executable_hardlink() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1109,7 +1106,7 @@ fn install_executable_hardlink() -> Result<()> { fn no_deps() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Install Flask. insta::with_settings!({ diff --git a/crates/puffin/tests/pip_sync.rs b/crates/puffin/tests/pip_sync.rs index a2b1af8b6..380f4f511 100644 --- a/crates/puffin/tests/pip_sync.rs +++ b/crates/puffin/tests/pip_sync.rs @@ -12,7 +12,7 @@ use insta_cmd::_macro_support::insta; use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; use url::Url; -use common::{create_venv_py312, venv_to_interpreter, BIN_NAME, INSTA_FILTERS}; +use common::{create_venv, venv_to_interpreter, BIN_NAME, INSTA_FILTERS}; mod common; @@ -98,7 +98,7 @@ fn missing_venv() -> Result<()> { fn install() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -143,7 +143,7 @@ fn install() -> Result<()> { fn install_copy() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -190,7 +190,7 @@ fn install_copy() -> Result<()> { fn install_hardlink() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -237,7 +237,7 @@ fn install_hardlink() -> Result<()> { fn install_many() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -278,7 +278,7 @@ fn install_many() -> Result<()> { fn noop() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -328,7 +328,7 @@ fn noop() -> Result<()> { fn link() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv1 = create_venv_py312(&temp_dir, &cache_dir); + let venv1 = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -392,7 +392,7 @@ fn link() -> Result<()> { fn add_remove() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -458,7 +458,7 @@ fn add_remove() -> Result<()> { fn install_sequential() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -515,7 +515,7 @@ fn install_sequential() -> Result<()> { fn upgrade() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -573,7 +573,7 @@ fn upgrade() -> Result<()> { fn install_url() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -616,7 +616,7 @@ fn install_url() -> Result<()> { fn install_git_commit() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -659,7 +659,7 @@ fn install_git_commit() -> Result<()> { fn install_git_tag() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -702,7 +702,7 @@ fn install_git_tag() -> Result<()> { fn install_git_subdirectories() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -747,7 +747,7 @@ fn install_git_subdirectories() -> Result<()> { fn install_sdist() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -789,7 +789,7 @@ fn install_sdist() -> Result<()> { fn install_sdist_url() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -832,7 +832,7 @@ fn install_sdist_url() -> Result<()> { fn install_url_then_install_url() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -884,7 +884,7 @@ fn install_url_then_install_url() -> Result<()> { fn install_url_then_install_version() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -940,7 +940,7 @@ fn install_url_then_install_version() -> Result<()> { fn install_version_then_install_url() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -1053,7 +1053,7 @@ fn install_numpy_py38() -> Result<()> { fn install_no_binary() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -1093,7 +1093,7 @@ fn install_no_binary() -> Result<()> { fn warn_on_yanked_version() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_in = temp_dir.child("requirements.txt"); requirements_in.touch()?; @@ -1134,7 +1134,7 @@ fn warn_on_yanked_version() -> Result<()> { fn install_local_wheel() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Download a wheel. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl")?; @@ -1180,7 +1180,7 @@ fn install_local_wheel() -> Result<()> { check_command(&venv, "import tomli", &temp_dir); // Create a new virtual environment. - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Reinstall. The wheel should come from the cache, so there shouldn't be a "download". insta::with_settings!({ @@ -1208,7 +1208,7 @@ fn install_local_wheel() -> Result<()> { check_command(&venv, "import tomli", &temp_dir); // Create a new virtual environment. - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // "Modify" the wheel. // The `filetime` crate works on Windows unlike the std. @@ -1281,7 +1281,7 @@ fn install_local_wheel() -> Result<()> { fn mismatched_version() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Download a wheel. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl")?; @@ -1332,7 +1332,7 @@ fn mismatched_version() -> Result<()> { fn mismatched_name() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Download a wheel. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl")?; @@ -1383,7 +1383,7 @@ fn mismatched_name() -> Result<()> { fn install_local_source_distribution() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Download a source distribution. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/b0/b4/bc2baae3970c282fae6c2cb8e0f179923dceb7eaffb0e76170628f9af97b/wheel-0.42.0.tar.gz")?; @@ -1444,7 +1444,7 @@ fn install_local_source_distribution() -> Result<()> { fn install_ujson() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -1495,7 +1495,7 @@ fn install_ujson() -> Result<()> { fn install_build_system_no_backend() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -1535,7 +1535,7 @@ fn install_build_system_no_backend() -> Result<()> { fn install_url_source_dist_cached() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -1569,7 +1569,7 @@ fn install_url_source_dist_cached() -> Result<()> { // Re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1597,7 +1597,7 @@ fn install_url_source_dist_cached() -> Result<()> { // Clear the cache, then re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1653,7 +1653,7 @@ fn install_url_source_dist_cached() -> Result<()> { fn install_git_source_dist_cached() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -1687,7 +1687,7 @@ fn install_git_source_dist_cached() -> Result<()> { // Re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1715,7 +1715,7 @@ fn install_git_source_dist_cached() -> Result<()> { // Clear the cache, then re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1770,7 +1770,7 @@ fn install_git_source_dist_cached() -> Result<()> { fn install_registry_source_dist_cached() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -1804,7 +1804,7 @@ fn install_registry_source_dist_cached() -> Result<()> { // Re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1832,7 +1832,7 @@ fn install_registry_source_dist_cached() -> Result<()> { // Clear the cache, then re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -1887,7 +1887,7 @@ fn install_registry_source_dist_cached() -> Result<()> { fn install_path_source_dist_cached() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Download a source distribution. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/b0/b4/bc2baae3970c282fae6c2cb8e0f179923dceb7eaffb0e76170628f9af97b/wheel-0.42.0.tar.gz")?; @@ -1934,7 +1934,7 @@ fn install_path_source_dist_cached() -> Result<()> { // Re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => filters.clone() @@ -1962,7 +1962,7 @@ fn install_path_source_dist_cached() -> Result<()> { // Clear the cache, then re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => filters.clone() @@ -2017,7 +2017,7 @@ fn install_path_source_dist_cached() -> Result<()> { fn install_path_built_dist_cached() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); // Download a wheel. let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl")?; @@ -2064,7 +2064,7 @@ fn install_path_built_dist_cached() -> Result<()> { // Re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); insta::with_settings!({ filters => filters.clone() @@ -2092,7 +2092,7 @@ fn install_path_built_dist_cached() -> Result<()> { // Clear the cache, then re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => filters.clone() @@ -2147,7 +2147,7 @@ fn install_path_built_dist_cached() -> Result<()> { fn install_url_built_dist_cached() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -2181,7 +2181,7 @@ fn install_url_built_dist_cached() -> Result<()> { // Re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -2209,7 +2209,7 @@ fn install_url_built_dist_cached() -> Result<()> { // Clear the cache, then re-run the installation in a new virtual environment. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -2264,7 +2264,7 @@ fn install_url_built_dist_cached() -> Result<()> { fn duplicate_package_overlap() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -2300,7 +2300,7 @@ fn duplicate_package_overlap() -> Result<()> { fn duplicate_package_disjoint() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -2338,7 +2338,7 @@ fn duplicate_package_disjoint() -> Result<()> { fn reinstall() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -2411,7 +2411,7 @@ fn reinstall() -> Result<()> { fn reinstall_package() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -2484,7 +2484,7 @@ fn reinstall_package() -> Result<()> { fn reinstall_git() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -2553,7 +2553,7 @@ fn reinstall_git() -> Result<()> { fn refresh() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -2590,7 +2590,7 @@ fn refresh() -> Result<()> { // Re-run the installation into with `--refresh`. Ensure that we resolve and download the // latest versions of the packages. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -2629,7 +2629,7 @@ fn refresh() -> Result<()> { fn refresh_package() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -2666,7 +2666,7 @@ fn refresh_package() -> Result<()> { // Re-run the installation into with `--refresh`. Ensure that we resolve and download the // latest versions of the packages. let parent = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&parent, &cache_dir); + let venv = create_venv(&parent, &cache_dir, "3.12"); insta::with_settings!({ filters => INSTA_FILTERS.to_vec() @@ -2706,7 +2706,7 @@ fn refresh_package() -> Result<()> { fn sync_editable() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let current_dir = std::env::current_dir()?; let workspace_dir = regex::escape( @@ -2866,7 +2866,7 @@ fn sync_editable() -> Result<()> { fn sync_editable_and_registry() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let current_dir = std::env::current_dir()?; let workspace_dir = regex::escape( @@ -3058,7 +3058,7 @@ fn incompatible_wheel() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let wheel_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let wheel = wheel_dir.child("foo-1.2.3-not-compatible-wheel.whl"); wheel.touch()?; @@ -3104,7 +3104,7 @@ fn incompatible_wheel() -> Result<()> { fn sync_legacy_sdist_pep_517() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_in = temp_dir.child("requirements.in"); requirements_in.write_str("flake8 @ https://files.pythonhosted.org/packages/66/53/3ad4a3b74d609b3b9008a10075c40e7c8909eae60af53623c3888f7a529a/flake8-6.0.0.tar.gz")?; @@ -3140,7 +3140,7 @@ fn sync_legacy_sdist_pep_517() -> Result<()> { fn sync_legacy_sdist_setuptools() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_in = temp_dir.child("requirements.in"); requirements_in.write_str("flake8 @ https://files.pythonhosted.org/packages/66/53/3ad4a3b74d609b3b9008a10075c40e7c8909eae60af53623c3888f7a529a/flake8-6.0.0.tar.gz")?; @@ -3177,7 +3177,7 @@ fn sync_legacy_sdist_setuptools() -> Result<()> { fn find_links() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.write_str(indoc! {r" diff --git a/crates/puffin/tests/pip_uninstall.rs b/crates/puffin/tests/pip_uninstall.rs index c29c8809b..7ebafa3a1 100644 --- a/crates/puffin/tests/pip_uninstall.rs +++ b/crates/puffin/tests/pip_uninstall.rs @@ -10,7 +10,7 @@ use url::Url; use common::{BIN_NAME, INSTA_FILTERS}; use puffin_fs::NormalizedDisplay; -use crate::common::{create_venv_py312, venv_to_interpreter}; +use crate::common::{create_venv, venv_to_interpreter}; mod common; @@ -245,7 +245,7 @@ dependencies = ["flask==1.0.x"] fn uninstall() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -304,7 +304,7 @@ fn uninstall() -> Result<()> { fn missing_record() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let requirements_txt = temp_dir.child("requirements.txt"); requirements_txt.touch()?; @@ -385,7 +385,7 @@ fn missing_record() -> Result<()> { fn uninstall_editable_by_name() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let current_dir = std::env::current_dir()?; let workspace_dir = regex::escape( @@ -453,7 +453,7 @@ fn uninstall_editable_by_name() -> Result<()> { fn uninstall_editable_by_path() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let current_dir = std::env::current_dir()?; let workspace_dir = regex::escape( @@ -521,7 +521,7 @@ fn uninstall_editable_by_path() -> Result<()> { fn uninstall_duplicate_editable() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv_py312(&temp_dir, &cache_dir); + let venv = create_venv(&temp_dir, &cache_dir, "3.12"); let current_dir = std::env::current_dir()?; let workspace_dir = regex::escape(