diff --git a/crates/puffin/tests/common/mod.rs b/crates/puffin/tests/common/mod.rs index a20c257b2..366cc823c 100644 --- a/crates/puffin/tests/common/mod.rs +++ b/crates/puffin/tests/common/mod.rs @@ -97,3 +97,22 @@ pub fn create_venv(temp_dir: &TempDir, cache_dir: &TempDir, python: &str) -> Pat venv.assert(predicates::path::is_dir()); venv.to_path_buf() } + +/// Run [`assert_cmd_snapshot!`] with our default filters. +#[allow(unused_macros)] +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 + }, { + ::insta_cmd::assert_cmd_snapshot!($spawnable, @$snapshot); + }); + }}; +} + +/// +#[allow(unused_imports)] +pub(crate) use puffin_snapshot; diff --git a/crates/puffin/tests/pip_compile.rs b/crates/puffin/tests/pip_compile.rs index 9d8a59c0d..df1aee6d1 100644 --- a/crates/puffin/tests/pip_compile.rs +++ b/crates/puffin/tests/pip_compile.rs @@ -10,30 +10,16 @@ use assert_fs::TempDir; use indoc::indoc; use insta::assert_snapshot; use insta_cmd::_macro_support::insta; -use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; +use insta_cmd::get_cargo_bin; use itertools::Itertools; use url::Url; -use common::{TestContext, BIN_NAME, INSTA_FILTERS}; +use common::{puffin_snapshot, TestContext, BIN_NAME, INSTA_FILTERS}; use crate::common::EXCLUDE_NEWER; mod common; -/// 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<()> { diff --git a/crates/puffin/tests/pip_compile_scenarios.rs b/crates/puffin/tests/pip_compile_scenarios.rs index 97fc72de5..e8e537b18 100644 --- a/crates/puffin/tests/pip_compile_scenarios.rs +++ b/crates/puffin/tests/pip_compile_scenarios.rs @@ -10,13 +10,13 @@ use std::process::Command; use anyhow::Result; use assert_fs::fixture::{FileWriteStr, PathChild}; -use common::{create_venv, BIN_NAME, INSTA_FILTERS}; #[cfg(unix)] use fs_err::os::unix::fs::symlink as symlink_file; #[cfg(windows)] use fs_err::os::windows::fs::symlink_file; -use insta_cmd::_macro_support::insta; -use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; +use insta_cmd::get_cargo_bin; + +use common::{puffin_snapshot, TestContext, BIN_NAME, INSTA_FILTERS}; use puffin_interpreter::find_requested_python; mod common; @@ -24,11 +24,11 @@ mod common; /// Create a directory with the requested Python binaries available. pub(crate) fn create_bin_with_executables( temp_dir: &assert_fs::TempDir, - python: Vec<&str>, + python_versions: &[&str], ) -> Result { let bin = temp_dir.child("bin"); fs_err::create_dir(&bin)?; - for request in python { + for request in python_versions { let executable = find_requested_python(request)?; let name = executable .file_name() @@ -38,6 +38,26 @@ pub(crate) fn create_bin_with_executables( Ok(bin.canonicalize()?) } +/// Provision python binaries and return a `pip compile` command with options shared across all scenarios. +fn command(context: &TestContext, python_versions: &[&str]) -> Command { + let bin = create_bin_with_executables(&context.temp_dir, python_versions) + .expect("Failed to create bin dir"); + let mut command = Command::new(get_cargo_bin(BIN_NAME)); + command + .arg("pip") + .arg("compile") + .arg("requirements.in") + .arg("--extra-index-url") + .arg("https://test.pypi.org/simple") + .arg("--cache-dir") + .arg(context.cache_dir.path()) + .env("VIRTUAL_ENV", context.venv.as_os_str()) + .env("PUFFIN_NO_WRAP", "1") + .env("PUFFIN_PYTHON_PATH", bin) + .current_dir(&context.temp_dir); + command +} + /// requires-incompatible-python-version-compatible-override /// /// The user requires a package which requires a Python version greater than the @@ -57,48 +77,32 @@ pub(crate) fn create_bin_with_executables( /// ``` #[test] fn requires_incompatible_python_version_compatible_override() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); - let python_versions = vec![]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("3.9"); + let python_versions = &[]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-006fed96", "albatross")); filters.push((r"-006fed96", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("a-006fed96==1.0.0")?; - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--python-version=3.11") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @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.11 --extra-index-url https://test.pypi.org/simple --cache-dir [CACHE_DIR] - albatross==1.0.0 + puffin_snapshot!(filters, command(&context, python_versions) + .arg("--python-version=3.11") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by Puffin v[VERSION] via the following command: + # puffin pip compile requirements.in --extra-index-url https://test.pypi.org/simple --cache-dir [CACHE_DIR] --python-version=3.11 + albatross==1.0.0 - ----- stderr ----- - warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead. - Resolved 1 package in [TIME] - "###); - }); + ----- stderr ----- + warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead. + Resolved 1 package in [TIME] + "### + ); Ok(()) } @@ -121,47 +125,31 @@ fn requires_incompatible_python_version_compatible_override() -> Result<()> { /// ``` #[test] fn requires_compatible_python_version_incompatible_override() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.11"); - let python_versions = vec![]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("3.11"); + let python_versions = &[]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-8c1b0389", "albatross")); filters.push((r"-8c1b0389", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("a-8c1b0389==1.0.0")?; - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--python-version=3.9") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context, python_versions) + .arg("--python-version=3.9") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - warning: The requested Python version 3.9 is not available; 3.11.7 will be used to build dependencies instead. - × No solution found when resolving dependencies: - ╰─▶ Because the requested Python version (3.9) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. - And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + warning: The requested Python version 3.9 is not available; 3.11.7 will be used to build dependencies instead. + × No solution found when resolving dependencies: + ╰─▶ Because the requested Python version (3.9) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. + And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "### + ); Ok(()) } @@ -185,50 +173,34 @@ fn requires_compatible_python_version_incompatible_override() -> Result<()> { /// ``` #[test] fn requires_incompatible_python_version_compatible_override_no_wheels() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); - let python_versions = vec![]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("3.9"); + let python_versions = &[]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-b8ee1c03", "albatross")); filters.push((r"-b8ee1c03", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("a-b8ee1c03==1.0.0")?; // Since there are no wheels for the package and it is not compatible with the // local installation, we cannot build the source distribution to determine its // dependencies. - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--python-version=3.11") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context, python_versions) + .arg("--python-version=3.11") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead. - × No solution found when resolving dependencies: - ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. - And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead. + × No solution found when resolving dependencies: + ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. + And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "### + ); Ok(()) } @@ -255,49 +227,33 @@ fn requires_incompatible_python_version_compatible_override_no_wheels() -> Resul #[test] fn requires_incompatible_python_version_compatible_override_no_wheels_available_system( ) -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); - let python_versions = vec!["3.11"]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("3.9"); + let python_versions = &["3.11"]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-ae5b2665", "albatross")); filters.push((r"-ae5b2665", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("a-ae5b2665==1.0.0")?; // Since there is a compatible Python version available on the system, it should be // used to build the source distributions. - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--python-version=3.11") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @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.11 --extra-index-url https://test.pypi.org/simple --cache-dir [CACHE_DIR] - albatross==1.0.0 + puffin_snapshot!(filters, command(&context, python_versions) + .arg("--python-version=3.11") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by Puffin v[VERSION] via the following command: + # puffin pip compile requirements.in --extra-index-url https://test.pypi.org/simple --cache-dir [CACHE_DIR] --python-version=3.11 + albatross==1.0.0 - ----- stderr ----- - Resolved 1 package in [TIME] - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + "### + ); Ok(()) } @@ -321,50 +277,34 @@ fn requires_incompatible_python_version_compatible_override_no_wheels_available_ /// ``` #[test] fn requires_incompatible_python_version_compatible_override_no_compatible_wheels() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); - let python_versions = vec![]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("3.9"); + let python_versions = &[]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-c0ea406a", "albatross")); filters.push((r"-c0ea406a", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("a-c0ea406a==1.0.0")?; // Since there are no compatible wheels for the package and it is not compatible // with the local installation, we cannot build the source distribution to // determine its dependencies. - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--python-version=3.11") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context, python_versions) + .arg("--python-version=3.11") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead. - × No solution found when resolving dependencies: - ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. - And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead. + × No solution found when resolving dependencies: + ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. + And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "### + ); Ok(()) } @@ -392,59 +332,43 @@ fn requires_incompatible_python_version_compatible_override_no_compatible_wheels /// ``` #[test] fn requires_incompatible_python_version_compatible_override_other_wheel() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); - let python_versions = vec![]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("3.9"); + let python_versions = &[]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-08a4e843", "albatross")); filters.push((r"-08a4e843", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("a-08a4e843")?; // Since there are no wheels for the version of the package compatible with the // target and it is not compatible with the local installation, we cannot build the // source distribution to determine its dependencies. The other version has wheels // available, but is not compatible with the target version and cannot be used. - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--python-version=3.11") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context, python_versions) + .arg("--python-version=3.11") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead. - × No solution found when resolving dependencies: - ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. - And because there are no versions of albatross that satisfy any of: - albatross<1.0.0 - albatross>1.0.0,<2.0.0 - albatross>2.0.0 - we can conclude that albatross<2.0.0 cannot be used. (1) + ----- stderr ----- + warning: The requested Python version 3.11 is not available; 3.9.18 will be used to build dependencies instead. + × No solution found when resolving dependencies: + ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. + And because there are no versions of albatross that satisfy any of: + albatross<1.0.0 + albatross>1.0.0,<2.0.0 + albatross>2.0.0 + we can conclude that albatross<2.0.0 cannot be used. (1) - Because the requested Python version (3.11) does not satisfy Python>=3.12 and albatross==2.0.0 depends on Python>=3.12, we can conclude that albatross==2.0.0 cannot be used. - And because we know from (1) that albatross<2.0.0 cannot be used, we can conclude that all versions of albatross cannot be used. - And because you require albatross, we can conclude that the requirements are unsatisfiable. - "###); - }); + Because the requested Python version (3.11) does not satisfy Python>=3.12 and albatross==2.0.0 depends on Python>=3.12, we can conclude that albatross==2.0.0 cannot be used. + And because we know from (1) that albatross<2.0.0 cannot be used, we can conclude that all versions of albatross cannot be used. + And because you require albatross, we can conclude that the requirements are unsatisfiable. + "### + ); Ok(()) } @@ -467,48 +391,32 @@ fn requires_incompatible_python_version_compatible_override_other_wheel() -> Res /// ``` #[test] fn requires_python_patch_version_override_no_patch() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8.18"); - let python_versions = vec![]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("3.8.18"); + let python_versions = &[]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-2e1edfd6", "albatross")); filters.push((r"-2e1edfd6", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("a-2e1edfd6==1.0.0")?; // Since the resolver is asked to solve with 3.8, the minimum compatible Python // requirement is treated as 3.8.0. - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--python-version=3.8") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context, python_versions) + .arg("--python-version=3.8") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because the requested Python version (3.8) does not satisfy Python>=3.8.4 and albatross==1.0.0 depends on Python>=3.8.4, we can conclude that albatross==1.0.0 cannot be used. - And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because the requested Python version (3.8) does not satisfy Python>=3.8.4 and albatross==1.0.0 depends on Python>=3.8.4, we can conclude that albatross==1.0.0 cannot be used. + And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "### + ); Ok(()) } @@ -531,48 +439,32 @@ fn requires_python_patch_version_override_no_patch() -> Result<()> { /// ``` #[test] fn requires_python_patch_version_override_patch_compatible() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8.18"); - let python_versions = vec![]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("3.8.18"); + let python_versions = &[]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-844899bd", "albatross")); filters.push((r"-844899bd", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); requirements_in.write_str("a-844899bd==1.0.0")?; - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - .arg("--python-version=3.8.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @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.8.0 --extra-index-url https://test.pypi.org/simple --cache-dir [CACHE_DIR] - albatross==1.0.0 + puffin_snapshot!(filters, command(&context, python_versions) + .arg("--python-version=3.8.0") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by Puffin v[VERSION] via the following command: + # puffin pip compile requirements.in --extra-index-url https://test.pypi.org/simple --cache-dir [CACHE_DIR] --python-version=3.8.0 + albatross==1.0.0 - ----- stderr ----- - warning: The requested Python version 3.8.0 is not available; 3.8.18 will be used to build dependencies instead. - Resolved 1 package in [TIME] - "###); - }); + ----- stderr ----- + warning: The requested Python version 3.8.0 is not available; 3.8.18 will be used to build dependencies instead. + Resolved 1 package in [TIME] + "### + ); Ok(()) } diff --git a/crates/puffin/tests/pip_install_scenarios.rs b/crates/puffin/tests/pip_install_scenarios.rs index f62c65e51..5b93395a9 100644 --- a/crates/puffin/tests/pip_install_scenarios.rs +++ b/crates/puffin/tests/pip_install_scenarios.rs @@ -8,13 +8,13 @@ use std::path::Path; use std::process::Command; -use anyhow::Result; use assert_cmd::assert::Assert; use assert_cmd::prelude::*; -use insta_cmd::_macro_support::insta; -use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; +use insta_cmd::get_cargo_bin; -use common::{create_venv, venv_to_interpreter, BIN_NAME, INSTA_FILTERS}; +use common::{venv_to_interpreter, BIN_NAME, INSTA_FILTERS}; + +use crate::common::{puffin_snapshot, TestContext}; mod common; @@ -40,6 +40,22 @@ fn assert_not_installed(venv: &Path, package: &'static str, temp_dir: &Path) { assert_command(venv, format!("import {package}").as_str(), temp_dir).failure(); } +/// Create a `pip install` command with options shared across all scenarios. +fn command(context: &TestContext) -> Command { + let mut command = Command::new(get_cargo_bin(BIN_NAME)); + command + .arg("pip") + .arg("install") + .arg("--extra-index-url") + .arg("https://test.pypi.org/simple") + .arg("--cache-dir") + .arg(context.cache_dir.path()) + .env("VIRTUAL_ENV", context.venv.as_os_str()) + .env("PUFFIN_NO_WRAP", "1") + .current_dir(&context.temp_dir); + command +} + /// requires-package-does-not-exist /// /// The user requires any version of package `a` which does not exist. @@ -53,41 +69,25 @@ fn assert_not_installed(venv: &Path, package: &'static str, temp_dir: &Path) { /// └── unsatisfied: no versions for package /// ``` #[test] -fn requires_package_does_not_exist() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn requires_package_does_not_exist() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"-3cb60d4c", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-3cb60d4c") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 2 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-3cb60d4c") + , @r###" + success: false + exit_code: 2 + ----- stdout ----- - ----- stderr ----- - error: Package `a` was not found in the registry. - "###); - }); + ----- stderr ----- + error: Package `a` was not found in the registry. + "###); - assert_not_installed(&venv, "a_3cb60d4c", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_3cb60d4c", &context.temp_dir); } /// requires-exact-version-does-not-exist @@ -105,43 +105,27 @@ fn requires_package_does_not_exist() -> Result<()> { /// └── a-1.0.0 /// ``` #[test] -fn requires_exact_version_does_not_exist() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn requires_exact_version_does_not_exist() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-e7132fc5", "albatross")); filters.push((r"-e7132fc5", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-e7132fc5==2.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-e7132fc5==2.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because there is no version of albatross==2.0.0 and you require albatross==2.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because there is no version of albatross==2.0.0 and you require albatross==2.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_e7132fc5", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_e7132fc5", &context.temp_dir); } /// requires-greater-version-does-not-exist @@ -161,43 +145,27 @@ fn requires_exact_version_does_not_exist() -> Result<()> { /// └── a-1.0.0 /// ``` #[test] -fn requires_greater_version_does_not_exist() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn requires_greater_version_does_not_exist() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-0e488e8f", "albatross")); filters.push((r"-0e488e8f", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-0e488e8f>1.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-0e488e8f>1.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only albatross<=1.0.0 is available and you require albatross>1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only albatross<=1.0.0 is available and you require albatross>1.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_0e488e8f", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_0e488e8f", &context.temp_dir); } /// requires-less-version-does-not-exist @@ -218,43 +186,27 @@ fn requires_greater_version_does_not_exist() -> Result<()> { /// └── a-4.0.0 /// ``` #[test] -fn requires_less_version_does_not_exist() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn requires_less_version_does_not_exist() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-1a4076bc", "albatross")); filters.push((r"-1a4076bc", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-1a4076bc<2.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-1a4076bc<2.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only albatross>=2.0.0 is available and you require albatross<2.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only albatross>=2.0.0 is available and you require albatross<2.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_1a4076bc", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_1a4076bc", &context.temp_dir); } /// transitive-requires-package-does-not-exist @@ -274,42 +226,26 @@ fn requires_less_version_does_not_exist() -> Result<()> { /// └── unsatisfied: no versions for package /// ``` #[test] -fn transitive_requires_package_does_not_exist() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_requires_package_does_not_exist() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-22a72022", "albatross")); filters.push((r"-22a72022", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-22a72022") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 2 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-22a72022") + , @r###" + success: false + exit_code: 2 + ----- stdout ----- - ----- stderr ----- - error: Package `b` was not found in the registry. - "###); - }); + ----- stderr ----- + error: Package `b` was not found in the registry. + "###); - assert_not_installed(&venv, "a_22a72022", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_22a72022", &context.temp_dir); } /// excluded-only-version @@ -328,47 +264,31 @@ fn transitive_requires_package_does_not_exist() -> Result<()> { /// └── a-1.0.0 /// ``` #[test] -fn excluded_only_version() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn excluded_only_version() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-2bc4455f", "albatross")); filters.push((r"-2bc4455f", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-2bc4455f!=1.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-2bc4455f!=1.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only albatross==1.0.0 is available and you require one of: - albatross<1.0.0 - albatross>1.0.0 - we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only albatross==1.0.0 is available and you require one of: + albatross<1.0.0 + albatross>1.0.0 + we can conclude that the requirements are unsatisfiable. + "###); // Only `a==1.0.0` is available but the user excluded it. - assert_not_installed(&venv, "a_2bc4455f", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_2bc4455f", &context.temp_dir); } /// excluded-only-compatible-version @@ -402,10 +322,8 @@ fn excluded_only_version() -> Result<()> { /// └── b-3.0.0 /// ``` #[test] -fn excluded_only_compatible_version() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn excluded_only_compatible_version() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -413,54 +331,40 @@ fn excluded_only_compatible_version() -> Result<()> { filters.push((r"b-5b90a629", "bluebird")); filters.push((r"-5b90a629", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-5b90a629!=2.0.0") - .arg("b-5b90a629<3.0.0,>=2.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-5b90a629!=2.0.0") + .arg("b-5b90a629<3.0.0,>=2.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because there are no versions of albatross that satisfy any of: - albatross<1.0.0 - albatross>1.0.0,<2.0.0 - albatross>2.0.0,<3.0.0 - albatross>3.0.0 - and albatross==1.0.0 depends on bluebird==1.0.0, we can conclude that albatross<2.0.0 depends on bluebird==1.0.0. - And because albatross==3.0.0 depends on bluebird==3.0.0, we can conclude that any of: - albatross<2.0.0 - albatross>2.0.0 - depends on one of: - bluebird<=1.0.0 - bluebird>=3.0.0 + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because there are no versions of albatross that satisfy any of: + albatross<1.0.0 + albatross>1.0.0,<2.0.0 + albatross>2.0.0,<3.0.0 + albatross>3.0.0 + and albatross==1.0.0 depends on bluebird==1.0.0, we can conclude that albatross<2.0.0 depends on bluebird==1.0.0. + And because albatross==3.0.0 depends on bluebird==3.0.0, we can conclude that any of: + albatross<2.0.0 + albatross>2.0.0 + depends on one of: + bluebird<=1.0.0 + bluebird>=3.0.0 - And because you require bluebird>=2.0.0,<3.0.0 and you require one of: - albatross<2.0.0 - albatross>2.0.0 - we can conclude that the requirements are unsatisfiable. - "###); - }); + And because you require bluebird>=2.0.0,<3.0.0 and you require one of: + albatross<2.0.0 + albatross>2.0.0 + we can conclude that the requirements are unsatisfiable. + "###); // Only `a==1.2.0` is available since `a==1.0.0` and `a==3.0.0` require // incompatible versions of `b`. The user has excluded that version of `a` so // resolution fails. - assert_not_installed(&venv, "a_5b90a629", &temp_dir); - assert_not_installed(&venv, "b_5b90a629", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_5b90a629", &context.temp_dir); + assert_not_installed(&context.venv, "b_5b90a629", &context.temp_dir); } /// dependency-excludes-range-of-compatible-versions @@ -517,10 +421,8 @@ fn excluded_only_compatible_version() -> Result<()> { /// └── satisfied by a-3.0.0 /// ``` #[test] -fn dependency_excludes_range_of_compatible_versions() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn dependency_excludes_range_of_compatible_versions() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -529,58 +431,44 @@ fn dependency_excludes_range_of_compatible_versions() -> Result<()> { filters.push((r"c-e59e1cd1", "crow")); filters.push((r"-e59e1cd1", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-e59e1cd1") - .arg("b-e59e1cd1<3.0.0,>=2.0.0") - .arg("c-e59e1cd1") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-e59e1cd1") + .arg("b-e59e1cd1<3.0.0,>=2.0.0") + .arg("c-e59e1cd1") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because there are no versions of crow that satisfy any of: - crow<1.0.0 - crow>1.0.0,<2.0.0 - crow>2.0.0 - and crow==1.0.0 depends on albatross<2.0.0, we can conclude that crow<2.0.0 depends on albatross<2.0.0. (1) + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because there are no versions of crow that satisfy any of: + crow<1.0.0 + crow>1.0.0,<2.0.0 + crow>2.0.0 + and crow==1.0.0 depends on albatross<2.0.0, we can conclude that crow<2.0.0 depends on albatross<2.0.0. (1) - Because there are no versions of albatross that satisfy any of: - albatross<1.0.0 - albatross>1.0.0,<2.0.0 - and albatross==1.0.0 depends on bluebird==1.0.0, we can conclude that albatross<2.0.0 depends on bluebird==1.0.0. - And because we know from (1) that crow<2.0.0 depends on albatross<2.0.0, we can conclude that crow<2.0.0 depends on bluebird==1.0.0. - And because crow==2.0.0 depends on albatross>=3.0.0, we can conclude that all versions of crow, bluebird!=1.0.0, albatross<3.0.0 are incompatible. (2) + Because there are no versions of albatross that satisfy any of: + albatross<1.0.0 + albatross>1.0.0,<2.0.0 + and albatross==1.0.0 depends on bluebird==1.0.0, we can conclude that albatross<2.0.0 depends on bluebird==1.0.0. + And because we know from (1) that crow<2.0.0 depends on albatross<2.0.0, we can conclude that crow<2.0.0 depends on bluebird==1.0.0. + And because crow==2.0.0 depends on albatross>=3.0.0, we can conclude that all versions of crow, bluebird!=1.0.0, albatross<3.0.0 are incompatible. (2) - Because only albatross<=3.0.0 is available and albatross==3.0.0 depends on bluebird==3.0.0, we can conclude that albatross>=3.0.0 depends on bluebird==3.0.0. - And because we know from (2) that all versions of crow, bluebird!=1.0.0, albatross<3.0.0 are incompatible, we can conclude that all versions of crow depend on one of: - bluebird==1.0.0 - bluebird==3.0.0 + Because only albatross<=3.0.0 is available and albatross==3.0.0 depends on bluebird==3.0.0, we can conclude that albatross>=3.0.0 depends on bluebird==3.0.0. + And because we know from (2) that all versions of crow, bluebird!=1.0.0, albatross<3.0.0 are incompatible, we can conclude that all versions of crow depend on one of: + bluebird==1.0.0 + bluebird==3.0.0 - And because you require crow and you require bluebird>=2.0.0,<3.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + And because you require crow and you require bluebird>=2.0.0,<3.0.0, we can conclude that the requirements are unsatisfiable. + "###); // Only the `2.x` versions of `a` are available since `a==1.0.0` and `a==3.0.0` // require incompatible versions of `b`, but all available versions of `c` exclude // that range of `a` so resolution fails. - assert_not_installed(&venv, "a_e59e1cd1", &temp_dir); - assert_not_installed(&venv, "b_e59e1cd1", &temp_dir); - assert_not_installed(&venv, "c_e59e1cd1", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_e59e1cd1", &context.temp_dir); + assert_not_installed(&context.venv, "b_e59e1cd1", &context.temp_dir); + assert_not_installed(&context.venv, "c_e59e1cd1", &context.temp_dir); } /// dependency-excludes-non-contiguous-range-of-compatible-versions @@ -648,10 +536,8 @@ fn dependency_excludes_range_of_compatible_versions() -> Result<()> { /// └── satisfied by a-3.0.0 /// ``` #[test] -fn dependency_excludes_non_contiguous_range_of_compatible_versions() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn dependency_excludes_non_contiguous_range_of_compatible_versions() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -660,58 +546,44 @@ fn dependency_excludes_non_contiguous_range_of_compatible_versions() -> Result<( filters.push((r"c-ed41451f", "crow")); filters.push((r"-ed41451f", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-ed41451f") - .arg("b-ed41451f<3.0.0,>=2.0.0") - .arg("c-ed41451f") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-ed41451f") + .arg("b-ed41451f<3.0.0,>=2.0.0") + .arg("c-ed41451f") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because there are no versions of crow that satisfy any of: - crow<1.0.0 - crow>1.0.0,<2.0.0 - crow>2.0.0 - and crow==1.0.0 depends on albatross<2.0.0, we can conclude that crow<2.0.0 depends on albatross<2.0.0. (1) + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because there are no versions of crow that satisfy any of: + crow<1.0.0 + crow>1.0.0,<2.0.0 + crow>2.0.0 + and crow==1.0.0 depends on albatross<2.0.0, we can conclude that crow<2.0.0 depends on albatross<2.0.0. (1) - Because there are no versions of albatross that satisfy any of: - albatross<1.0.0 - albatross>1.0.0,<2.0.0 - and albatross==1.0.0 depends on bluebird==1.0.0, we can conclude that albatross<2.0.0 depends on bluebird==1.0.0. - And because we know from (1) that crow<2.0.0 depends on albatross<2.0.0, we can conclude that crow<2.0.0 depends on bluebird==1.0.0. - And because crow==2.0.0 depends on albatross>=3.0.0, we can conclude that all versions of crow, bluebird!=1.0.0, albatross<3.0.0 are incompatible. (2) + Because there are no versions of albatross that satisfy any of: + albatross<1.0.0 + albatross>1.0.0,<2.0.0 + and albatross==1.0.0 depends on bluebird==1.0.0, we can conclude that albatross<2.0.0 depends on bluebird==1.0.0. + And because we know from (1) that crow<2.0.0 depends on albatross<2.0.0, we can conclude that crow<2.0.0 depends on bluebird==1.0.0. + And because crow==2.0.0 depends on albatross>=3.0.0, we can conclude that all versions of crow, bluebird!=1.0.0, albatross<3.0.0 are incompatible. (2) - Because only albatross<=3.0.0 is available and albatross==3.0.0 depends on bluebird==3.0.0, we can conclude that albatross>=3.0.0 depends on bluebird==3.0.0. - And because we know from (2) that all versions of crow, bluebird!=1.0.0, albatross<3.0.0 are incompatible, we can conclude that all versions of crow depend on one of: - bluebird==1.0.0 - bluebird==3.0.0 + Because only albatross<=3.0.0 is available and albatross==3.0.0 depends on bluebird==3.0.0, we can conclude that albatross>=3.0.0 depends on bluebird==3.0.0. + And because we know from (2) that all versions of crow, bluebird!=1.0.0, albatross<3.0.0 are incompatible, we can conclude that all versions of crow depend on one of: + bluebird==1.0.0 + bluebird==3.0.0 - And because you require crow and you require bluebird>=2.0.0,<3.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + And because you require crow and you require bluebird>=2.0.0,<3.0.0, we can conclude that the requirements are unsatisfiable. + "###); // Only the `2.x` versions of `a` are available since `a==1.0.0` and `a==3.0.0` // require incompatible versions of `b`, but all available versions of `c` exclude // that range of `a` so resolution fails. - assert_not_installed(&venv, "a_ed41451f", &temp_dir); - assert_not_installed(&venv, "b_ed41451f", &temp_dir); - assert_not_installed(&venv, "c_ed41451f", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_ed41451f", &context.temp_dir); + assert_not_installed(&context.venv, "b_ed41451f", &context.temp_dir); + assert_not_installed(&context.venv, "c_ed41451f", &context.temp_dir); } /// extra-required @@ -735,10 +607,8 @@ fn dependency_excludes_non_contiguous_range_of_compatible_versions() -> Result<( /// └── b-1.0.0 /// ``` #[test] -fn extra_required() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn extra_required() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -746,37 +616,23 @@ fn extra_required() -> Result<()> { filters.push((r"b-c9be513b", "bluebird")); filters.push((r"-c9be513b", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-c9be513b[extra]") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-c9be513b[extra]") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 2 packages in [TIME] - Downloaded 2 packages in [TIME] - Installed 2 packages in [TIME] - + albatross==1.0.0 - + bluebird==1.0.0 - "###); - }); + ----- stderr ----- + Resolved 2 packages in [TIME] + Downloaded 2 packages in [TIME] + Installed 2 packages in [TIME] + + albatross==1.0.0 + + bluebird==1.0.0 + "###); - assert_installed(&venv, "a_c9be513b", "1.0.0", &temp_dir); - assert_installed(&venv, "b_c9be513b", "1.0.0", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_c9be513b", "1.0.0", &context.temp_dir); + assert_installed(&context.venv, "b_c9be513b", "1.0.0", &context.temp_dir); } /// missing-extra @@ -795,46 +651,30 @@ fn extra_required() -> Result<()> { /// └── a-1.0.0 /// ``` #[test] -fn missing_extra() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn missing_extra() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-79fd9a92", "albatross")); filters.push((r"-79fd9a92", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-79fd9a92[extra]") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-79fd9a92[extra]") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0 + "###); // Missing extras are ignored during resolution. - assert_installed(&venv, "a_79fd9a92", "1.0.0", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_79fd9a92", "1.0.0", &context.temp_dir); } /// multiple-extras-required @@ -864,10 +704,8 @@ fn missing_extra() -> Result<()> { /// └── c-1.0.0 /// ``` #[test] -fn multiple_extras_required() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn multiple_extras_required() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -876,39 +714,25 @@ fn multiple_extras_required() -> Result<()> { filters.push((r"c-14317535", "crow")); filters.push((r"-14317535", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-14317535[extra_b,extra_c]") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-14317535[extra_b,extra_c]") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 3 packages in [TIME] - Downloaded 3 packages in [TIME] - Installed 3 packages in [TIME] - + albatross==1.0.0 - + bluebird==1.0.0 - + crow==1.0.0 - "###); - }); + ----- stderr ----- + Resolved 3 packages in [TIME] + Downloaded 3 packages in [TIME] + Installed 3 packages in [TIME] + + albatross==1.0.0 + + bluebird==1.0.0 + + crow==1.0.0 + "###); - assert_installed(&venv, "a_14317535", "1.0.0", &temp_dir); - assert_installed(&venv, "b_14317535", "1.0.0", &temp_dir); - assert_installed(&venv, "c_14317535", "1.0.0", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_14317535", "1.0.0", &context.temp_dir); + assert_installed(&context.venv, "b_14317535", "1.0.0", &context.temp_dir); + assert_installed(&context.venv, "c_14317535", "1.0.0", &context.temp_dir); } /// extra-incompatible-with-extra @@ -938,10 +762,8 @@ fn multiple_extras_required() -> Result<()> { /// └── b-2.0.0 /// ``` #[test] -fn extra_incompatible_with_extra() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn extra_incompatible_with_extra() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -949,37 +771,23 @@ fn extra_incompatible_with_extra() -> Result<()> { filters.push((r"b-afa38951", "bluebird")); filters.push((r"-afa38951", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-afa38951[extra_b,extra_c]") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-afa38951[extra_b,extra_c]") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only albatross[extra-b]==1.0.0 is available and albatross[extra-b]==1.0.0 depends on bluebird==1.0.0, we can conclude that all versions of albatross[extra-b] depend on bluebird==1.0.0. - And because albatross[extra-c]==1.0.0 depends on bluebird==2.0.0 and only albatross[extra-c]==1.0.0 is available, we can conclude that all versions of albatross[extra-c] and all versions of albatross[extra-b] are incompatible. - And because you require albatross[extra-b] and you require albatross[extra-c], we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only albatross[extra-b]==1.0.0 is available and albatross[extra-b]==1.0.0 depends on bluebird==1.0.0, we can conclude that all versions of albatross[extra-b] depend on bluebird==1.0.0. + And because albatross[extra-c]==1.0.0 depends on bluebird==2.0.0 and only albatross[extra-c]==1.0.0 is available, we can conclude that all versions of albatross[extra-c] and all versions of albatross[extra-b] are incompatible. + And because you require albatross[extra-b] and you require albatross[extra-c], we can conclude that the requirements are unsatisfiable. + "###); // Because both `extra_b` and `extra_c` are requested and they require incompatible // versions of `b`, `a` cannot be installed. - assert_not_installed(&venv, "a_afa38951", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_afa38951", &context.temp_dir); } /// extra-incompatible-with-extra-not-requested @@ -1008,10 +816,8 @@ fn extra_incompatible_with_extra() -> Result<()> { /// └── b-2.0.0 /// ``` #[test] -fn extra_incompatible_with_extra_not_requested() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn extra_incompatible_with_extra_not_requested() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -1019,39 +825,25 @@ fn extra_incompatible_with_extra_not_requested() -> Result<()> { filters.push((r"b-5c305dd9", "bluebird")); filters.push((r"-5c305dd9", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-5c305dd9[extra_c]") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-5c305dd9[extra_c]") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 2 packages in [TIME] - Downloaded 2 packages in [TIME] - Installed 2 packages in [TIME] - + albatross==1.0.0 - + bluebird==2.0.0 - "###); - }); + ----- stderr ----- + Resolved 2 packages in [TIME] + Downloaded 2 packages in [TIME] + Installed 2 packages in [TIME] + + albatross==1.0.0 + + bluebird==2.0.0 + "###); // Because the user does not request both extras, it is okay that one is // incompatible with the other. - assert_installed(&venv, "a_5c305dd9", "1.0.0", &temp_dir); - assert_installed(&venv, "b_5c305dd9", "2.0.0", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_5c305dd9", "1.0.0", &context.temp_dir); + assert_installed(&context.venv, "b_5c305dd9", "2.0.0", &context.temp_dir); } /// extra-incompatible-with-root @@ -1079,10 +871,8 @@ fn extra_incompatible_with_extra_not_requested() -> Result<()> { /// └── b-2.0.0 /// ``` #[test] -fn extra_incompatible_with_root() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn extra_incompatible_with_root() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -1090,38 +880,24 @@ fn extra_incompatible_with_root() -> Result<()> { filters.push((r"b-743dac5a", "bluebird")); filters.push((r"-743dac5a", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-743dac5a[extra]") - .arg("b-743dac5a==2.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-743dac5a[extra]") + .arg("b-743dac5a==2.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only albatross[extra]==1.0.0 is available and albatross[extra]==1.0.0 depends on bluebird==1.0.0, we can conclude that all versions of albatross[extra] depend on bluebird==1.0.0. - And because you require bluebird==2.0.0 and you require albatross[extra], we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only albatross[extra]==1.0.0 is available and albatross[extra]==1.0.0 depends on bluebird==1.0.0, we can conclude that all versions of albatross[extra] depend on bluebird==1.0.0. + And because you require bluebird==2.0.0 and you require albatross[extra], we can conclude that the requirements are unsatisfiable. + "###); // Because the user requested `b==2.0.0` but the requested extra requires // `b==1.0.0`, the dependencies cannot be satisfied. - assert_not_installed(&venv, "a_743dac5a", &temp_dir); - assert_not_installed(&venv, "b_743dac5a", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_743dac5a", &context.temp_dir); + assert_not_installed(&context.venv, "b_743dac5a", &context.temp_dir); } /// extra-does-not-exist-backtrack @@ -1150,10 +926,8 @@ fn extra_incompatible_with_root() -> Result<()> { /// └── b-1.0.0 /// ``` #[test] -fn extra_does_not_exist_backtrack() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn extra_does_not_exist_backtrack() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -1161,37 +935,23 @@ fn extra_does_not_exist_backtrack() -> Result<()> { filters.push((r"b-a35e4442", "bluebird")); filters.push((r"-a35e4442", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-a35e4442[extra]") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-a35e4442[extra]") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==3.0.0 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==3.0.0 + "###); // The resolver should not backtrack to `a==1.0.0` because missing extras are // allowed during resolution. `b` should not be installed. - assert_installed(&venv, "a_a35e4442", "3.0.0", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_a35e4442", "3.0.0", &context.temp_dir); } /// direct-incompatible-versions @@ -1212,45 +972,29 @@ fn extra_does_not_exist_backtrack() -> Result<()> { /// └── a-2.0.0 /// ``` #[test] -fn direct_incompatible_versions() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn direct_incompatible_versions() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-f75c56e2", "albatross")); filters.push((r"-f75c56e2", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-f75c56e2==1.0.0") - .arg("a-f75c56e2==2.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-f75c56e2==1.0.0") + .arg("a-f75c56e2==2.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ your requirements cannot be used because there are conflicting versions for `albatross`: `albatross==1.0.0` does not intersect with `albatross==2.0.0` - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ your requirements cannot be used because there are conflicting versions for `albatross`: `albatross==1.0.0` does not intersect with `albatross==2.0.0` + "###); - assert_not_installed(&venv, "a_f75c56e2", &temp_dir); - assert_not_installed(&venv, "a_f75c56e2", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_f75c56e2", &context.temp_dir); + assert_not_installed(&context.venv, "a_f75c56e2", &context.temp_dir); } /// transitive-incompatible-with-root-version @@ -1276,10 +1020,8 @@ fn direct_incompatible_versions() -> Result<()> { /// └── b-2.0.0 /// ``` #[test] -fn transitive_incompatible_with_root_version() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_incompatible_with_root_version() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -1287,36 +1029,22 @@ fn transitive_incompatible_with_root_version() -> Result<()> { filters.push((r"b-812a0fda", "bluebird")); filters.push((r"-812a0fda", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-812a0fda") - .arg("b-812a0fda==1.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-812a0fda") + .arg("b-812a0fda==1.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because albatross==1.0.0 depends on bluebird==2.0.0 and only albatross==1.0.0 is available, we can conclude that all versions of albatross depend on bluebird==2.0.0. - And because you require bluebird==1.0.0 and you require albatross, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because albatross==1.0.0 depends on bluebird==2.0.0 and only albatross==1.0.0 is available, we can conclude that all versions of albatross depend on bluebird==2.0.0. + And because you require bluebird==1.0.0 and you require albatross, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_812a0fda", &temp_dir); - assert_not_installed(&venv, "b_812a0fda", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_812a0fda", &context.temp_dir); + assert_not_installed(&context.venv, "b_812a0fda", &context.temp_dir); } /// transitive-incompatible-with-transitive @@ -1346,10 +1074,8 @@ fn transitive_incompatible_with_root_version() -> Result<()> { /// └── c-2.0.0 /// ``` #[test] -fn transitive_incompatible_with_transitive() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_incompatible_with_transitive() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -1358,37 +1084,23 @@ fn transitive_incompatible_with_transitive() -> Result<()> { filters.push((r"c-74531fe0", "crow")); filters.push((r"-74531fe0", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-74531fe0") - .arg("b-74531fe0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-74531fe0") + .arg("b-74531fe0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only albatross==1.0.0 is available and albatross==1.0.0 depends on crow==1.0.0, we can conclude that all versions of albatross depend on crow==1.0.0. - And because bluebird==1.0.0 depends on crow==2.0.0 and only bluebird==1.0.0 is available, we can conclude that all versions of albatross and all versions of bluebird are incompatible. - And because you require albatross and you require bluebird, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only albatross==1.0.0 is available and albatross==1.0.0 depends on crow==1.0.0, we can conclude that all versions of albatross depend on crow==1.0.0. + And because bluebird==1.0.0 depends on crow==2.0.0 and only bluebird==1.0.0 is available, we can conclude that all versions of albatross and all versions of bluebird are incompatible. + And because you require albatross and you require bluebird, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_74531fe0", &temp_dir); - assert_not_installed(&venv, "b_74531fe0", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_74531fe0", &context.temp_dir); + assert_not_installed(&context.venv, "b_74531fe0", &context.temp_dir); } /// package-only-prereleases @@ -1407,47 +1119,31 @@ fn transitive_incompatible_with_transitive() -> Result<()> { /// └── a-1.0.0a1 /// ``` #[test] -fn package_only_prereleases() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn package_only_prereleases() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-e2dbc237", "albatross")); filters.push((r"-e2dbc237", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-e2dbc237") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-e2dbc237") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0a1 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0a1 + "###); // Since there are only prerelease versions of `a` available, it should be // installed even though the user did not include a prerelease specifier. - assert_installed(&venv, "a_e2dbc237", "1.0.0a1", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_e2dbc237", "1.0.0a1", &context.temp_dir); } /// package-only-prereleases-in-range @@ -1467,47 +1163,31 @@ fn package_only_prereleases() -> Result<()> { /// └── a-1.0.0a1 /// ``` #[test] -fn package_only_prereleases_in_range() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn package_only_prereleases_in_range() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-4e199000", "albatross")); filters.push((r"-4e199000", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-4e199000>0.1.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-4e199000>0.1.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only albatross<=0.1.0 is available and you require albatross>0.1.0, we can conclude that the requirements are unsatisfiable. + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only albatross<=0.1.0 is available and you require albatross>0.1.0, we can conclude that the requirements are unsatisfiable. - hint: Pre-releases are available for albatross in the requested range (e.g., 1.0.0a1), but pre-releases weren't enabled (try: `--prerelease=allow`) - "###); - }); + hint: Pre-releases are available for albatross in the requested range (e.g., 1.0.0a1), but pre-releases weren't enabled (try: `--prerelease=allow`) + "###); // Since there are stable versions of `a` available, prerelease versions should not // be selected without explicit opt-in. - assert_not_installed(&venv, "a_4e199000", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_4e199000", &context.temp_dir); } /// requires-package-only-prereleases-in-range-global-opt-in @@ -1528,46 +1208,30 @@ fn package_only_prereleases_in_range() -> Result<()> { /// └── a-1.0.0a1 /// ``` #[test] -fn requires_package_only_prereleases_in_range_global_opt_in() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn requires_package_only_prereleases_in_range_global_opt_in() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-af391f9c", "albatross")); filters.push((r"-af391f9c", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-af391f9c>0.1.0") - .arg("--prerelease=allow") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("--prerelease=allow") + .arg("a-af391f9c>0.1.0") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0a1 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0a1 + "###); - assert_installed(&venv, "a_af391f9c", "1.0.0a1", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_af391f9c", "1.0.0a1", &context.temp_dir); } /// requires-package-prerelease-and-final-any @@ -1587,47 +1251,31 @@ fn requires_package_only_prereleases_in_range_global_opt_in() -> Result<()> { /// └── a-1.0.0a1 /// ``` #[test] -fn requires_package_prerelease_and_final_any() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn requires_package_prerelease_and_final_any() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-81dbab9d", "albatross")); filters.push((r"-81dbab9d", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-81dbab9d") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-81dbab9d") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==0.1.0 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==0.1.0 + "###); // Since the user did not provide a prerelease specifier, the older stable version // should be selected. - assert_installed(&venv, "a_81dbab9d", "0.1.0", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_81dbab9d", "0.1.0", &context.temp_dir); } /// package-prerelease-specified-only-final-available @@ -1650,46 +1298,30 @@ fn requires_package_prerelease_and_final_any() -> Result<()> { /// └── a-0.3.0 /// ``` #[test] -fn package_prerelease_specified_only_final_available() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn package_prerelease_specified_only_final_available() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-2ee8f3f9", "albatross")); filters.push((r"-2ee8f3f9", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-2ee8f3f9>=0.1.0a1") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-2ee8f3f9>=0.1.0a1") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==0.3.0 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==0.3.0 + "###); // The latest stable version should be selected. - assert_installed(&venv, "a_2ee8f3f9", "0.3.0", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_2ee8f3f9", "0.3.0", &context.temp_dir); } /// package-prerelease-specified-only-prerelease-available @@ -1712,46 +1344,30 @@ fn package_prerelease_specified_only_final_available() -> Result<()> { /// └── a-0.3.0a1 /// ``` #[test] -fn package_prerelease_specified_only_prerelease_available() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn package_prerelease_specified_only_prerelease_available() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-dd6b1e32", "albatross")); filters.push((r"-dd6b1e32", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-dd6b1e32>=0.1.0a1") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-dd6b1e32>=0.1.0a1") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==0.3.0a1 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==0.3.0a1 + "###); // The latest prerelease version should be selected. - assert_installed(&venv, "a_dd6b1e32", "0.3.0a1", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_dd6b1e32", "0.3.0a1", &context.temp_dir); } /// package-prerelease-specified-mixed-available @@ -1776,47 +1392,31 @@ fn package_prerelease_specified_only_prerelease_available() -> Result<()> { /// └── a-1.0.0a1 /// ``` #[test] -fn package_prerelease_specified_mixed_available() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn package_prerelease_specified_mixed_available() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-794fce4d", "albatross")); filters.push((r"-794fce4d", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-794fce4d>=0.1.0a1") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-794fce4d>=0.1.0a1") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0a1 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0a1 + "###); // Since the user provided a prerelease specifier, the latest prerelease version // should be selected. - assert_installed(&venv, "a_794fce4d", "1.0.0a1", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_794fce4d", "1.0.0a1", &context.temp_dir); } /// package-multiple-prereleases-kinds @@ -1839,46 +1439,30 @@ fn package_prerelease_specified_mixed_available() -> Result<()> { /// └── a-1.0.0rc1 /// ``` #[test] -fn package_multiple_prereleases_kinds() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn package_multiple_prereleases_kinds() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-256d4e16", "albatross")); filters.push((r"-256d4e16", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-256d4e16>=1.0.0a1") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-256d4e16>=1.0.0a1") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0rc1 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0rc1 + "###); // Release candidates should be the highest precedence prerelease kind. - assert_installed(&venv, "a_256d4e16", "1.0.0rc1", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_256d4e16", "1.0.0rc1", &context.temp_dir); } /// package-multiple-prereleases-numbers @@ -1900,46 +1484,30 @@ fn package_multiple_prereleases_kinds() -> Result<()> { /// └── a-1.0.0a3 /// ``` #[test] -fn package_multiple_prereleases_numbers() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn package_multiple_prereleases_numbers() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-ac82d3fb", "albatross")); filters.push((r"-ac82d3fb", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-ac82d3fb>=1.0.0a1") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-ac82d3fb>=1.0.0a1") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0a3 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0a3 + "###); // The latest alpha version should be selected. - assert_installed(&venv, "a_ac82d3fb", "1.0.0a3", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_ac82d3fb", "1.0.0a3", &context.temp_dir); } /// transitive-package-only-prereleases @@ -1962,10 +1530,8 @@ fn package_multiple_prereleases_numbers() -> Result<()> { /// └── b-1.0.0a1 /// ``` #[test] -fn transitive_package_only_prereleases() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_package_only_prereleases() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -1973,39 +1539,25 @@ fn transitive_package_only_prereleases() -> Result<()> { filters.push((r"b-9da8532e", "bluebird")); filters.push((r"-9da8532e", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-9da8532e") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-9da8532e") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 2 packages in [TIME] - Downloaded 2 packages in [TIME] - Installed 2 packages in [TIME] - + albatross==0.1.0 - + bluebird==1.0.0a1 - "###); - }); + ----- stderr ----- + Resolved 2 packages in [TIME] + Downloaded 2 packages in [TIME] + Installed 2 packages in [TIME] + + albatross==0.1.0 + + bluebird==1.0.0a1 + "###); // Since there are only prerelease versions of `b` available, it should be selected // even though the user did not opt-in to prereleases. - assert_installed(&venv, "a_9da8532e", "0.1.0", &temp_dir); - assert_installed(&venv, "b_9da8532e", "1.0.0a1", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_9da8532e", "0.1.0", &context.temp_dir); + assert_installed(&context.venv, "b_9da8532e", "1.0.0a1", &context.temp_dir); } /// transitive-package-only-prereleases-in-range @@ -2029,10 +1581,8 @@ fn transitive_package_only_prereleases() -> Result<()> { /// └── b-1.0.0a1 /// ``` #[test] -fn transitive_package_only_prereleases_in_range() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_package_only_prereleases_in_range() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -2040,39 +1590,25 @@ fn transitive_package_only_prereleases_in_range() -> Result<()> { filters.push((r"b-c41a54fc", "bluebird")); filters.push((r"-c41a54fc", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-c41a54fc") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-c41a54fc") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only bluebird<=0.1 is available and albatross==0.1.0 depends on bluebird>0.1, we can conclude that albatross==0.1.0 cannot be used. - And because only albatross==0.1.0 is available and you require albatross, we can conclude that the requirements are unsatisfiable. + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only bluebird<=0.1 is available and albatross==0.1.0 depends on bluebird>0.1, we can conclude that albatross==0.1.0 cannot be used. + And because only albatross==0.1.0 is available and you require albatross, we can conclude that the requirements are unsatisfiable. - hint: Pre-releases are available for bluebird in the requested range (e.g., 1.0.0a1), but pre-releases weren't enabled (try: `--prerelease=allow`) - "###); - }); + hint: Pre-releases are available for bluebird in the requested range (e.g., 1.0.0a1), but pre-releases weren't enabled (try: `--prerelease=allow`) + "###); // Since there are stable versions of `b` available, the prerelease version should // not be selected without explicit opt-in. The available version is excluded by // the range requested by the user. - assert_not_installed(&venv, "a_c41a54fc", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_c41a54fc", &context.temp_dir); } /// transitive-package-only-prereleases-in-range-opt-in @@ -2099,10 +1635,8 @@ fn transitive_package_only_prereleases_in_range() -> Result<()> { /// └── b-1.0.0a1 /// ``` #[test] -fn transitive_package_only_prereleases_in_range_opt_in() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_package_only_prereleases_in_range_opt_in() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -2110,40 +1644,26 @@ fn transitive_package_only_prereleases_in_range_opt_in() -> Result<()> { filters.push((r"b-96f98f65", "bluebird")); filters.push((r"-96f98f65", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-96f98f65") - .arg("b-96f98f65>0.0.0a1") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-96f98f65") + .arg("b-96f98f65>0.0.0a1") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 2 packages in [TIME] - Downloaded 2 packages in [TIME] - Installed 2 packages in [TIME] - + albatross==0.1.0 - + bluebird==1.0.0a1 - "###); - }); + ----- stderr ----- + Resolved 2 packages in [TIME] + Downloaded 2 packages in [TIME] + Installed 2 packages in [TIME] + + albatross==0.1.0 + + bluebird==1.0.0a1 + "###); // Since the user included a dependency on `b` with a prerelease specifier, a // prerelease version can be selected. - assert_installed(&venv, "a_96f98f65", "0.1.0", &temp_dir); - assert_installed(&venv, "b_96f98f65", "1.0.0a1", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_96f98f65", "0.1.0", &context.temp_dir); + assert_installed(&context.venv, "b_96f98f65", "1.0.0a1", &context.temp_dir); } /// transitive-prerelease-and-stable-dependency @@ -2173,10 +1693,8 @@ fn transitive_package_only_prereleases_in_range_opt_in() -> Result<()> { /// └── c-2.0.0b1 /// ``` #[test] -fn transitive_prerelease_and_stable_dependency() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_prerelease_and_stable_dependency() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -2185,39 +1703,25 @@ fn transitive_prerelease_and_stable_dependency() -> Result<()> { filters.push((r"c-3d5eb91f", "crow")); filters.push((r"-3d5eb91f", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-3d5eb91f") - .arg("b-3d5eb91f") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-3d5eb91f") + .arg("b-3d5eb91f") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because there is no version of crow==2.0.0b1 and albatross==1.0.0 depends on crow==2.0.0b1, we can conclude that albatross==1.0.0 cannot be used. - And because only albatross==1.0.0 is available and you require albatross, we can conclude that the requirements are unsatisfiable. + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because there is no version of crow==2.0.0b1 and albatross==1.0.0 depends on crow==2.0.0b1, we can conclude that albatross==1.0.0 cannot be used. + And because only albatross==1.0.0 is available and you require albatross, we can conclude that the requirements are unsatisfiable. - hint: crow was requested with a pre-release marker (e.g., crow==2.0.0b1), but pre-releases weren't enabled (try: `--prerelease=allow`) - "###); - }); + hint: crow was requested with a pre-release marker (e.g., crow==2.0.0b1), but pre-releases weren't enabled (try: `--prerelease=allow`) + "###); // Since the user did not explicitly opt-in to a prerelease, it cannot be selected. - assert_not_installed(&venv, "a_3d5eb91f", &temp_dir); - assert_not_installed(&venv, "b_3d5eb91f", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_3d5eb91f", &context.temp_dir); + assert_not_installed(&context.venv, "b_3d5eb91f", &context.temp_dir); } /// transitive-prerelease-and-stable-dependency-opt-in @@ -2251,10 +1755,8 @@ fn transitive_prerelease_and_stable_dependency() -> Result<()> { /// └── c-2.0.0b1 /// ``` #[test] -fn transitive_prerelease_and_stable_dependency_opt_in() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_prerelease_and_stable_dependency_opt_in() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -2263,42 +1765,28 @@ fn transitive_prerelease_and_stable_dependency_opt_in() -> Result<()> { filters.push((r"c-6192ec57", "crow")); filters.push((r"-6192ec57", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-6192ec57") - .arg("b-6192ec57") - .arg("c-6192ec57>=0.0.0a1") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-6192ec57") + .arg("b-6192ec57") + .arg("c-6192ec57>=0.0.0a1") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 3 packages in [TIME] - Downloaded 3 packages in [TIME] - Installed 3 packages in [TIME] - + albatross==1.0.0 - + bluebird==1.0.0 - + crow==2.0.0b1 - "###); - }); + ----- stderr ----- + Resolved 3 packages in [TIME] + Downloaded 3 packages in [TIME] + Installed 3 packages in [TIME] + + albatross==1.0.0 + + bluebird==1.0.0 + + crow==2.0.0b1 + "###); // Since the user explicitly opted-in to a prerelease for `c`, it can be installed. - assert_installed(&venv, "a_6192ec57", "1.0.0", &temp_dir); - assert_installed(&venv, "b_6192ec57", "1.0.0", &temp_dir); - assert_installed(&venv, "c_6192ec57", "2.0.0b1", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_6192ec57", "1.0.0", &context.temp_dir); + assert_installed(&context.venv, "b_6192ec57", "1.0.0", &context.temp_dir); + assert_installed(&context.venv, "c_6192ec57", "2.0.0b1", &context.temp_dir); } /// transitive-prerelease-and-stable-dependency-many-versions @@ -2353,10 +1841,8 @@ fn transitive_prerelease_and_stable_dependency_opt_in() -> Result<()> { /// └── c-2.0.0b9 /// ``` #[test] -fn transitive_prerelease_and_stable_dependency_many_versions() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_prerelease_and_stable_dependency_many_versions() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -2365,41 +1851,27 @@ fn transitive_prerelease_and_stable_dependency_many_versions() -> Result<()> { filters.push((r"c-bcd0f988", "crow")); filters.push((r"-bcd0f988", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-bcd0f988") - .arg("b-bcd0f988") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-bcd0f988") + .arg("b-bcd0f988") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because only bluebird==1.0.0 is available and bluebird==1.0.0 depends on crow, we can conclude that all versions of bluebird depend on crow. - And because only crow<2.0.0b1 is available, we can conclude that all versions of bluebird depend on crow<2.0.0b1. - And because albatross==1.0.0 depends on crow>=2.0.0b1 and only albatross==1.0.0 is available, we can conclude that all versions of bluebird and all versions of albatross are incompatible. - And because you require bluebird and you require albatross, we can conclude that the requirements are unsatisfiable. + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because only bluebird==1.0.0 is available and bluebird==1.0.0 depends on crow, we can conclude that all versions of bluebird depend on crow. + And because only crow<2.0.0b1 is available, we can conclude that all versions of bluebird depend on crow<2.0.0b1. + And because albatross==1.0.0 depends on crow>=2.0.0b1 and only albatross==1.0.0 is available, we can conclude that all versions of bluebird and all versions of albatross are incompatible. + And because you require bluebird and you require albatross, we can conclude that the requirements are unsatisfiable. - hint: crow was requested with a pre-release marker (e.g., crow>=2.0.0b1), but pre-releases weren't enabled (try: `--prerelease=allow`) - "###); - }); + hint: crow was requested with a pre-release marker (e.g., crow>=2.0.0b1), but pre-releases weren't enabled (try: `--prerelease=allow`) + "###); // Since the user did not explicitly opt-in to a prerelease, it cannot be selected. - assert_not_installed(&venv, "a_bcd0f988", &temp_dir); - assert_not_installed(&venv, "b_bcd0f988", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_bcd0f988", &context.temp_dir); + assert_not_installed(&context.venv, "b_bcd0f988", &context.temp_dir); } /// transitive-prerelease-and-stable-dependency-many-versions-holes @@ -2447,10 +1919,8 @@ fn transitive_prerelease_and_stable_dependency_many_versions() -> Result<()> { /// └── c-2.0.0b9 /// ``` #[test] -fn transitive_prerelease_and_stable_dependency_many_versions_holes() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn transitive_prerelease_and_stable_dependency_many_versions_holes() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -2459,51 +1929,37 @@ fn transitive_prerelease_and_stable_dependency_many_versions_holes() -> Result<( filters.push((r"c-5cee052e", "crow")); filters.push((r"-5cee052e", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-5cee052e") - .arg("b-5cee052e") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-5cee052e") + .arg("b-5cee052e") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because there are no versions of crow that satisfy any of: - crow>1.0.0,<2.0.0a5 - crow>2.0.0a7,<2.0.0b1 - crow>2.0.0b1,<2.0.0b5 - and albatross==1.0.0 depends on one of: - crow>1.0.0,<2.0.0a5 - crow>2.0.0a7,<2.0.0b1 - crow>2.0.0b1,<2.0.0b5 - we can conclude that albatross==1.0.0 cannot be used. - And because only albatross==1.0.0 is available and you require albatross, we can conclude that the requirements are unsatisfiable. + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because there are no versions of crow that satisfy any of: + crow>1.0.0,<2.0.0a5 + crow>2.0.0a7,<2.0.0b1 + crow>2.0.0b1,<2.0.0b5 + and albatross==1.0.0 depends on one of: + crow>1.0.0,<2.0.0a5 + crow>2.0.0a7,<2.0.0b1 + crow>2.0.0b1,<2.0.0b5 + we can conclude that albatross==1.0.0 cannot be used. + And because only albatross==1.0.0 is available and you require albatross, we can conclude that the requirements are unsatisfiable. - hint: crow was requested with a pre-release marker (e.g., any of: - crow>1.0.0,<2.0.0a5 - crow>2.0.0a7,<2.0.0b1 - crow>2.0.0b1,<2.0.0b5 - ), but pre-releases weren't enabled (try: `--prerelease=allow`) - "###); - }); + hint: crow was requested with a pre-release marker (e.g., any of: + crow>1.0.0,<2.0.0a5 + crow>2.0.0a7,<2.0.0b1 + crow>2.0.0b1,<2.0.0b5 + ), but pre-releases weren't enabled (try: `--prerelease=allow`) + "###); // Since the user did not explicitly opt-in to a prerelease, it cannot be selected. - assert_not_installed(&venv, "a_5cee052e", &temp_dir); - assert_not_installed(&venv, "b_5cee052e", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_5cee052e", &context.temp_dir); + assert_not_installed(&context.venv, "b_5cee052e", &context.temp_dir); } /// requires-python-version-does-not-exist @@ -2522,44 +1978,28 @@ fn transitive_prerelease_and_stable_dependency_many_versions_holes() -> Result<( /// └── requires python>=4.0 (incompatible with environment) /// ``` #[test] -fn requires_python_version_does_not_exist() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn requires_python_version_does_not_exist() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-d004e577", "albatross")); filters.push((r"-d004e577", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-d004e577==1.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-d004e577==1.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because the current Python version (3.8.18) does not satisfy Python>=4.0 and albatross==1.0.0 depends on Python>=4.0, we can conclude that albatross==1.0.0 cannot be used. - And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because the current Python version (3.8.18) does not satisfy Python>=4.0 and albatross==1.0.0 depends on Python>=4.0, we can conclude that albatross==1.0.0 cannot be used. + And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_d004e577", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_d004e577", &context.temp_dir); } /// requires-python-version-less-than-current @@ -2579,44 +2019,28 @@ fn requires_python_version_does_not_exist() -> Result<()> { /// └── requires python<=3.8 (incompatible with environment) /// ``` #[test] -fn requires_python_version_less_than_current() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); +fn requires_python_version_less_than_current() { + let context = TestContext::new("3.9"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-5e520203", "albatross")); filters.push((r"-5e520203", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-5e520203==1.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-5e520203==1.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because the current Python version (3.9.18) does not satisfy Python<=3.8 and albatross==1.0.0 depends on Python<=3.8, we can conclude that albatross==1.0.0 cannot be used. - And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because the current Python version (3.9.18) does not satisfy Python<=3.8 and albatross==1.0.0 depends on Python<=3.8, we can conclude that albatross==1.0.0 cannot be used. + And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_5e520203", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_5e520203", &context.temp_dir); } /// requires-python-version-greater-than-current @@ -2636,44 +2060,28 @@ fn requires_python_version_less_than_current() -> Result<()> { /// └── requires python>=3.10 (incompatible with environment) /// ``` #[test] -fn requires_python_version_greater_than_current() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); +fn requires_python_version_greater_than_current() { + let context = TestContext::new("3.9"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-62394505", "albatross")); filters.push((r"-62394505", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-62394505==1.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-62394505==1.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. - And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10 and albatross==1.0.0 depends on Python>=3.10, we can conclude that albatross==1.0.0 cannot be used. + And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_62394505", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_62394505", &context.temp_dir); } /// requires-python-version-greater-than-current-patch @@ -2693,44 +2101,28 @@ fn requires_python_version_greater_than_current() -> Result<()> { /// └── requires python>=3.8.14 (incompatible with environment) /// ``` #[test] -fn requires_python_version_greater_than_current_patch() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8.12"); +fn requires_python_version_greater_than_current_patch() { + let context = TestContext::new("3.8.12"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-7b98f5af", "albatross")); filters.push((r"-7b98f5af", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-7b98f5af==1.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-7b98f5af==1.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because the current Python version (3.8.12) does not satisfy Python>=3.8.14 and albatross==1.0.0 depends on Python>=3.8.14, we can conclude that albatross==1.0.0 cannot be used. - And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because the current Python version (3.8.12) does not satisfy Python>=3.8.14 and albatross==1.0.0 depends on Python>=3.8.14, we can conclude that albatross==1.0.0 cannot be used. + And because you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_7b98f5af", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_7b98f5af", &context.temp_dir); } /// requires-python-version-greater-than-current-many @@ -2772,43 +2164,27 @@ fn requires_python_version_greater_than_current_patch() -> Result<()> { /// └── requires python>=3.11 (incompatible with environment) /// ``` #[test] -fn requires_python_version_greater_than_current_many() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); +fn requires_python_version_greater_than_current_many() { + let context = TestContext::new("3.9"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-fd1f719c", "albatross")); filters.push((r"-fd1f719c", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-fd1f719c==1.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-fd1f719c==1.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because there is no version of albatross==1.0.0 and you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because there is no version of albatross==1.0.0 and you require albatross==1.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_fd1f719c", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_fd1f719c", &context.temp_dir); } /// requires-python-version-greater-than-current-backtrack @@ -2836,45 +2212,29 @@ fn requires_python_version_greater_than_current_many() -> Result<()> { /// └── requires python>=3.12 (incompatible with environment) /// ``` #[test] -fn requires_python_version_greater_than_current_backtrack() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); +fn requires_python_version_greater_than_current_backtrack() { + let context = TestContext::new("3.9"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-b2677f9a", "albatross")); filters.push((r"-b2677f9a", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-b2677f9a") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-b2677f9a") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0 - "###); - }); + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0 + "###); - assert_installed(&venv, "a_b2677f9a", "1.0.0", &temp_dir); - - Ok(()) + assert_installed(&context.venv, "a_b2677f9a", "1.0.0", &context.temp_dir); } /// requires-python-version-greater-than-current-excluded @@ -2901,60 +2261,44 @@ fn requires_python_version_greater_than_current_backtrack() -> Result<()> { /// └── requires python>=3.12 (incompatible with environment) /// ``` #[test] -fn requires_python_version_greater_than_current_excluded() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.9"); +fn requires_python_version_greater_than_current_excluded() { + let context = TestContext::new("3.9"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-34ee1c3e", "albatross")); filters.push((r"-34ee1c3e", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-34ee1c3e>=2.0.0") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: false - exit_code: 1 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-34ee1c3e>=2.0.0") + , @r###" + success: false + exit_code: 1 + ----- stdout ----- - ----- stderr ----- - × No solution found when resolving dependencies: - ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10,<3.11 and the current Python version (3.9.18) does not satisfy Python>=3.12, we can conclude that any of: - Python>=3.10,<3.11 - Python>=3.12 - are incompatible. - And because the current Python version (3.9.18) does not satisfy Python>=3.11,<3.12, we can conclude that Python>=3.10 are incompatible. - And because albatross==2.0.0 depends on Python>=3.10 and there are no versions of albatross that satisfy any of: - albatross>2.0.0,<3.0.0 - albatross>3.0.0,<4.0.0 - albatross>4.0.0 - we can conclude that albatross>=2.0.0,<3.0.0 cannot be used. (1) + ----- stderr ----- + × No solution found when resolving dependencies: + ╰─▶ Because the current Python version (3.9.18) does not satisfy Python>=3.10,<3.11 and the current Python version (3.9.18) does not satisfy Python>=3.12, we can conclude that any of: + Python>=3.10,<3.11 + Python>=3.12 + are incompatible. + And because the current Python version (3.9.18) does not satisfy Python>=3.11,<3.12, we can conclude that Python>=3.10 are incompatible. + And because albatross==2.0.0 depends on Python>=3.10 and there are no versions of albatross that satisfy any of: + albatross>2.0.0,<3.0.0 + albatross>3.0.0,<4.0.0 + albatross>4.0.0 + we can conclude that albatross>=2.0.0,<3.0.0 cannot be used. (1) - Because the current Python version (3.9.18) does not satisfy Python>=3.11,<3.12 and the current Python version (3.9.18) does not satisfy Python>=3.12, we can conclude that Python>=3.11 are incompatible. - And because albatross==3.0.0 depends on Python>=3.11, we can conclude that albatross==3.0.0 cannot be used. - And because we know from (1) that albatross>=2.0.0,<3.0.0 cannot be used, we can conclude that albatross>=2.0.0,<4.0.0 cannot be used. (2) + Because the current Python version (3.9.18) does not satisfy Python>=3.11,<3.12 and the current Python version (3.9.18) does not satisfy Python>=3.12, we can conclude that Python>=3.11 are incompatible. + And because albatross==3.0.0 depends on Python>=3.11, we can conclude that albatross==3.0.0 cannot be used. + And because we know from (1) that albatross>=2.0.0,<3.0.0 cannot be used, we can conclude that albatross>=2.0.0,<4.0.0 cannot be used. (2) - Because the current Python version (3.9.18) does not satisfy Python>=3.12 and albatross==4.0.0 depends on Python>=3.12, we can conclude that albatross==4.0.0 cannot be used. - And because we know from (2) that albatross>=2.0.0,<4.0.0 cannot be used, we can conclude that albatross>=2.0.0 cannot be used. - And because you require albatross>=2.0.0, we can conclude that the requirements are unsatisfiable. - "###); - }); + Because the current Python version (3.9.18) does not satisfy Python>=3.12 and albatross==4.0.0 depends on Python>=3.12, we can conclude that albatross==4.0.0 cannot be used. + And because we know from (2) that albatross>=2.0.0,<4.0.0 cannot be used, we can conclude that albatross>=2.0.0 cannot be used. + And because you require albatross>=2.0.0, we can conclude that the requirements are unsatisfiable. + "###); - assert_not_installed(&venv, "a_34ee1c3e", &temp_dir); - - Ok(()) + assert_not_installed(&context.venv, "a_34ee1c3e", &context.temp_dir); } /// specific-tag-and-default @@ -2972,43 +2316,27 @@ fn requires_python_version_greater_than_current_excluded() -> Result<()> { /// └── a-1.0.0 /// ``` #[test] -fn specific_tag_and_default() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn specific_tag_and_default() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-ce63fb65", "albatross")); filters.push((r"-ce63fb65", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-ce63fb65") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-ce63fb65") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0 - "###); - }); - - Ok(()) + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0 + "###); } /// only-wheels @@ -3026,43 +2354,27 @@ fn specific_tag_and_default() -> Result<()> { /// └── a-1.0.0 /// ``` #[test] -fn only_wheels() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn only_wheels() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-08df4319", "albatross")); filters.push((r"-08df4319", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-08df4319") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-08df4319") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0 - "###); - }); - - Ok(()) + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0 + "###); } /// no-wheels @@ -3080,43 +2392,27 @@ fn only_wheels() -> Result<()> { /// └── a-1.0.0 /// ``` #[test] -fn no_wheels() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn no_wheels() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-0a9090ba", "albatross")); filters.push((r"-0a9090ba", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-0a9090ba") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-0a9090ba") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0 - "###); - }); - - Ok(()) + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0 + "###); } /// no-wheels-with-matching-platform @@ -3134,41 +2430,25 @@ fn no_wheels() -> Result<()> { /// └── a-1.0.0 /// ``` #[test] -fn no_wheels_with_matching_platform() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "3.8"); +fn no_wheels_with_matching_platform() { + let context = TestContext::new("3.8"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"a-b595b358", "albatross")); filters.push((r"-b595b358", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - .arg("a-b595b358") - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - success: true - exit_code: 0 - ----- stdout ----- + puffin_snapshot!(filters, command(&context) + .arg("a-b595b358") + , @r###" + success: true + exit_code: 0 + ----- stdout ----- - ----- stderr ----- - Resolved 1 package in [TIME] - Downloaded 1 package in [TIME] - Installed 1 package in [TIME] - + albatross==1.0.0 - "###); - }); - - Ok(()) + ----- stderr ----- + Resolved 1 package in [TIME] + Downloaded 1 package in [TIME] + Installed 1 package in [TIME] + + albatross==1.0.0 + "###); } diff --git a/scripts/scenarios/templates/compile.mustache b/scripts/scenarios/templates/compile.mustache index d0d37d71c..e4ac876d5 100644 --- a/scripts/scenarios/templates/compile.mustache +++ b/scripts/scenarios/templates/compile.mustache @@ -10,13 +10,13 @@ use std::process::Command; use anyhow::Result; use assert_fs::fixture::{FileWriteStr, PathChild}; -use common::{create_venv, BIN_NAME, INSTA_FILTERS}; #[cfg(unix)] use fs_err::os::unix::fs::symlink as symlink_file; #[cfg(windows)] use fs_err::os::windows::fs::symlink_file; -use insta_cmd::_macro_support::insta; -use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; +use insta_cmd::get_cargo_bin; + +use common::{puffin_snapshot, TestContext, BIN_NAME, INSTA_FILTERS}; use puffin_interpreter::find_requested_python; mod common; @@ -24,19 +24,40 @@ mod common; /// Create a directory with the requested Python binaries available. pub(crate) fn create_bin_with_executables( temp_dir: &assert_fs::TempDir, - python: Vec<&str>, + python_versions: &[&str], ) -> Result { let bin = temp_dir.child("bin"); fs_err::create_dir(&bin)?; - for request in python { + for request in python_versions { let executable = find_requested_python(request)?; let name = executable .file_name() .expect("Discovered executable must have a filename"); - symlink(&executable, bin.child(name))?; + symlink_file(&executable, bin.child(name))?; } Ok(bin.canonicalize()?) } + +/// Provision python binaries and return a `pip compile` command with options shared across all scenarios. +fn command(context: &TestContext, python_versions: &[&str]) -> Command { + let bin = create_bin_with_executables(&context.temp_dir, python_versions) + .expect("Failed to create bin dir"); + let mut command = Command::new(get_cargo_bin(BIN_NAME)); + command + .arg("pip") + .arg("compile") + .arg("requirements.in") + .arg("--extra-index-url") + .arg("https://test.pypi.org/simple") + .arg("--cache-dir") + .arg(context.cache_dir.path()) + .env("VIRTUAL_ENV", context.venv.as_os_str()) + .env("PUFFIN_NO_WRAP", "1") + .env("PUFFIN_PYTHON_PATH", bin) + .current_dir(&context.temp_dir); + command +} + {{#scenarios}} /// {{name}} @@ -53,11 +74,8 @@ pub(crate) fn create_bin_with_executables( /// ``` #[test] fn {{module_name}}() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "{{environment.python}}"); - let python_versions = vec![{{#environment.additional_python}}"{{.}}", {{/environment.additional_python}}]; - let bin = create_bin_with_executables(&temp_dir, python_versions)?; + let context = TestContext::new("{{environment.python}}"); + let python_versions = &[{{#environment.additional_python}}"{{.}}", {{/environment.additional_python}}]; // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -66,7 +84,7 @@ fn {{module_name}}() -> Result<()> { {{/packages}} filters.push((r"-{{version}}", "")); - let requirements_in = temp_dir.child("requirements.in"); + let requirements_in = context.temp_dir.child("requirements.in"); {{#root.requires}} requirements_in.write_str("{{requirement}}")?; {{/root.requires}} @@ -74,29 +92,15 @@ fn {{module_name}}() -> Result<()> { {{#expected.explanation_lines}} // {{.}} {{/expected.explanation_lines}} - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("compile") - .arg("requirements.in") - {{#environment.prereleases}} - .arg("--prerelease=allow") - {{/environment.prereleases}} - {{#resolver_options.python}} - .arg("--python-version={{.}}") - {{/resolver_options.python}} - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .env("PUFFIN_PYTHON_PATH", bin) - .current_dir(&temp_dir), @r###" - "###); - }); + puffin_snapshot!(filters, command(&context, python_versions) + {{#environment.prereleases}} + .arg("--prerelease=allow") + {{/environment.prereleases}} + {{#resolver_options.python}} + .arg("--python-version={{.}}") + {{/resolver_options.python}}, @r###" + "### + ); Ok(()) } diff --git a/scripts/scenarios/templates/install.mustache b/scripts/scenarios/templates/install.mustache index 6217d8eec..9bd308676 100644 --- a/scripts/scenarios/templates/install.mustache +++ b/scripts/scenarios/templates/install.mustache @@ -8,13 +8,13 @@ use std::path::Path; use std::process::Command; -use anyhow::Result; use assert_cmd::assert::Assert; use assert_cmd::prelude::*; -use insta_cmd::_macro_support::insta; -use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; +use insta_cmd::get_cargo_bin; -use common::{create_venv, BIN_NAME, INSTA_FILTERS, venv_to_interpreter}; +use common::{venv_to_interpreter, BIN_NAME, INSTA_FILTERS}; + +use crate::common::{puffin_snapshot, TestContext}; mod common; @@ -39,6 +39,23 @@ fn assert_installed(venv: &Path, package: &'static str, version: &'static str, t fn assert_not_installed(venv: &Path, package: &'static str, temp_dir: &Path) { assert_command(venv, format!("import {package}").as_str(), temp_dir).failure(); } + +/// Create a `pip install` command with options shared across all scenarios. +fn command(context: &TestContext) -> Command { + let mut command = Command::new(get_cargo_bin(BIN_NAME)); + command + .arg("pip") + .arg("install") + .arg("--extra-index-url") + .arg("https://test.pypi.org/simple") + .arg("--cache-dir") + .arg(context.cache_dir.path()) + .env("VIRTUAL_ENV", context.venv.as_os_str()) + .env("PUFFIN_NO_WRAP", "1") + .current_dir(&context.temp_dir); + command +} + {{#scenarios}} /// {{name}} @@ -54,10 +71,8 @@ fn assert_not_installed(venv: &Path, package: &'static str, temp_dir: &Path) { {{/tree}} /// ``` #[test] -fn {{module_name}}() -> Result<()> { - let temp_dir = assert_fs::TempDir::new()?; - let cache_dir = assert_fs::TempDir::new()?; - let venv = create_venv(&temp_dir, &cache_dir, "{{environment.python}}"); +fn {{module_name}}() { + let context = TestContext::new("{{environment.python}}"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); @@ -66,27 +81,14 @@ fn {{module_name}}() -> Result<()> { {{/packages}} filters.push((r"-{{version}}", "")); - insta::with_settings!({ - filters => filters - }, { - assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) - .arg("pip") - .arg("install") - {{#root.requires}} - .arg("{{requirement}}") - {{/root.requires}} - {{#environment.prereleases}} - .arg("--prerelease=allow") - {{/environment.prereleases}} - .arg("--extra-index-url") - .arg("https://test.pypi.org/simple") - .arg("--cache-dir") - .arg(cache_dir.path()) - .env("VIRTUAL_ENV", venv.as_os_str()) - .env("PUFFIN_NO_WRAP", "1") - .current_dir(&temp_dir), @r###" - "###); - }); + puffin_snapshot!(filters, command(&context) + {{#environment.prereleases}} + .arg("--prerelease=allow") + {{/environment.prereleases}} + {{#root.requires}} + .arg("{{requirement}}") + {{/root.requires}}, @r###" + "###); {{#expected.explanation_lines}} // {{.}} @@ -94,19 +96,17 @@ fn {{module_name}}() -> Result<()> { {{#expected.satisfiable}} {{#expected.packages}} assert_installed( - &venv, + &context.venv, "{{module_name}}", "{{version}}", - &temp_dir + &context.temp_dir ); {{/expected.packages}} {{/expected.satisfiable}} {{^expected.satisfiable}} {{#root.requires}} - assert_not_installed(&venv, "{{module_name}}", &temp_dir); + assert_not_installed(&context.venv, "{{module_name}}", &context.temp_dir); {{/root.requires}} {{/expected.satisfiable}} - - Ok(()) } {{/scenarios}}