Refactor remaining integration tests (#1220)

Mostly a mechanical refactor to use the `puffin_snapshot!` and
`TestContext` infrastructure in the add, remove, venv and pip uninstall
tests, in preparation for adding programmatic windows testing filters.
The is only one remaining usage of `assert_cmd_snapshot!` now in the
`puffin_snapshot!` macro.
This commit is contained in:
konsti 2024-02-02 10:26:59 +01:00 committed by GitHub
parent 6b050a1972
commit 0925e446a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 306 additions and 333 deletions

View file

@ -2,8 +2,9 @@ use std::process::Command;
use anyhow::Result;
use assert_fs::prelude::*;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
use insta_cmd::get_cargo_bin;
use crate::common::puffin_snapshot;
use common::BIN_NAME;
mod common;
@ -13,7 +14,7 @@ fn missing_pyproject_toml() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("flask")
.current_dir(&temp_dir), @r###"
@ -39,7 +40,7 @@ fn missing_project_table() -> Result<()> {
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("flask")
.current_dir(&temp_dir), @r###"
@ -72,7 +73,7 @@ name = "project"
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("flask")
.current_dir(&temp_dir), @r###"
@ -109,7 +110,7 @@ dependencies = [
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("flask==2.0.0")
.current_dir(&temp_dir), @r###"
@ -144,7 +145,7 @@ dependencies = ["flask==1.0.0"]
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("add")
.arg("requests")
.current_dir(&temp_dir), @r###"

View file

@ -111,11 +111,11 @@ pub fn create_venv(temp_dir: &TempDir, cache_dir: &TempDir, python: &str) -> Pat
venv.to_path_buf()
}
/// Run [`assert_cmd_snapshot!`] with our default filters.
/// Run [`assert_cmd_snapshot!`], with default filters or with custom filters.
#[allow(unused_macros)]
macro_rules! puffin_snapshot {
($spawnable:expr, @$snapshot:literal) => {{
puffin_snapshot!(INSTA_FILTERS.to_vec(), $spawnable, @$snapshot);
puffin_snapshot!($crate::common::INSTA_FILTERS.to_vec(), $spawnable, @$snapshot);
}};
($filters:expr, $spawnable:expr, @$snapshot:literal) => {{
::insta::with_settings!({

View file

@ -4,13 +4,13 @@ use std::process::Command;
use anyhow::Result;
use assert_cmd::prelude::*;
use assert_fs::prelude::*;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
use insta_cmd::get_cargo_bin;
use url::Url;
use common::{BIN_NAME, INSTA_FILTERS};
use common::{puffin_snapshot, BIN_NAME, INSTA_FILTERS};
use puffin_fs::NormalizedDisplay;
use crate::common::{create_venv, venv_to_interpreter};
use crate::common::{venv_to_interpreter, TestContext};
mod common;
@ -18,13 +18,10 @@ mod common;
fn no_arguments() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
insta::with_settings!({
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.current_dir(&temp_dir), @r###"
.current_dir(&temp_dir), @r###"
success: false
exit_code: 2
----- stdout -----
@ -36,8 +33,8 @@ fn no_arguments() -> Result<()> {
Usage: puffin pip uninstall <PACKAGE|--requirement <REQUIREMENT>|--editable <EDITABLE>>
For more information, try '--help'.
"###);
});
"###
);
Ok(())
}
@ -46,7 +43,7 @@ fn no_arguments() -> Result<()> {
fn invalid_requirement() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("flask==1.0.x")
@ -69,15 +66,12 @@ fn invalid_requirement() -> Result<()> {
fn missing_requirements_txt() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
insta::with_settings!({
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("-r")
.arg("requirements.txt")
.current_dir(&temp_dir), @r###"
.arg("-r")
.arg("requirements.txt")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 2
----- stdout -----
@ -85,8 +79,8 @@ fn missing_requirements_txt() -> Result<()> {
----- stderr -----
error: failed to open file `requirements.txt`
Caused by: No such file or directory (os error 2)
"###);
});
"###
);
Ok(())
}
@ -98,7 +92,7 @@ fn invalid_requirements_txt_requirement() -> Result<()> {
requirements_txt.touch()?;
requirements_txt.write_str("flask==1.0.x")?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("-r")
@ -122,15 +116,12 @@ fn invalid_requirements_txt_requirement() -> Result<()> {
fn missing_pyproject_toml() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
insta::with_settings!({
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("-r")
.arg("pyproject.toml")
.current_dir(&temp_dir), @r###"
.arg("-r")
.arg("pyproject.toml")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 2
----- stdout -----
@ -138,8 +129,8 @@ fn missing_pyproject_toml() -> Result<()> {
----- stderr -----
error: failed to open file `pyproject.toml`
Caused by: No such file or directory (os error 2)
"###);
});
"###
);
Ok(())
}
@ -151,7 +142,7 @@ fn invalid_pyproject_toml_syntax() -> Result<()> {
pyproject_toml.touch()?;
pyproject_toml.write_str("123 - 456")?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("-r")
@ -181,7 +172,7 @@ fn invalid_pyproject_toml_schema() -> Result<()> {
pyproject_toml.touch()?;
pyproject_toml.write_str("[project]")?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("-r")
@ -216,7 +207,7 @@ dependencies = ["flask==1.0.x"]
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("-r")
@ -243,11 +234,9 @@ dependencies = ["flask==1.0.x"]
#[test]
fn uninstall() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = create_venv(&temp_dir, &cache_dir, "3.12");
let context = TestContext::new("3.12");
let requirements_txt = temp_dir.child("requirements.txt");
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("MarkupSafe==2.1.3")?;
@ -256,44 +245,41 @@ fn uninstall() -> Result<()> {
.arg("sync")
.arg("requirements.txt")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir)
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&context.temp_dir)
.assert()
.success();
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import markupsafe")
.current_dir(&temp_dir)
.current_dir(&context.temp_dir)
.assert()
.success();
insta::with_settings!({
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("MarkupSafe")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("MarkupSafe")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&context.temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Uninstalled 1 package in [TIME]
- markupsafe==2.1.3
"###);
});
----- stderr -----
Uninstalled 1 package in [TIME]
- markupsafe==2.1.3
"###
);
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import markupsafe")
.current_dir(&temp_dir)
.current_dir(&context.temp_dir)
.assert()
.failure();
@ -302,11 +288,9 @@ fn uninstall() -> Result<()> {
#[test]
fn missing_record() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = create_venv(&temp_dir, &cache_dir, "3.12");
let context = TestContext::new("3.12");
let requirements_txt = temp_dir.child("requirements.txt");
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("MarkupSafe==2.1.3")?;
@ -315,27 +299,31 @@ fn missing_record() -> Result<()> {
.arg("sync")
.arg("requirements.txt")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir)
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&context.temp_dir)
.assert()
.success();
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import markupsafe")
.current_dir(&temp_dir)
.current_dir(&context.temp_dir)
.assert()
.success();
// Delete the RECORD file.
let dist_info = fs_err::canonicalize(if cfg!(unix) {
venv.join("lib")
context
.venv
.join("lib")
.join("python3.12")
.join("site-packages")
.join("MarkupSafe-2.1.3.dist-info")
} else if cfg!(windows) {
venv.join("Lib")
context
.venv
.join("Lib")
.join("site-packages")
.join("MarkupSafe-2.1.3.dist-info")
} else {
@ -355,27 +343,21 @@ fn missing_record() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();
insta::with_settings!(
{
filters => filters,
},
{
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("MarkupSafe")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir), @r###"
success: false
exit_code: 2
----- stdout -----
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("MarkupSafe")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&context.temp_dir), @r###"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Cannot uninstall package; RECORD file not found at: [DIST_INFO]/RECORD
"###);
}
----- stderr -----
error: Cannot uninstall package; RECORD file not found at: [DIST_INFO]/RECORD
"###
);
Ok(())
@ -383,9 +365,7 @@ fn missing_record() -> Result<()> {
#[test]
fn uninstall_editable_by_name() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = create_venv(&temp_dir, &cache_dir, "3.12");
let context = TestContext::new("3.12");
let current_dir = std::env::current_dir()?;
let workspace_dir = regex::escape(
@ -398,7 +378,7 @@ fn uninstall_editable_by_name() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();
let requirements_txt = temp_dir.child("requirements.txt");
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("-e ../../scripts/editable-installs/poetry_editable")?;
@ -407,40 +387,36 @@ fn uninstall_editable_by_name() -> Result<()> {
.arg("sync")
.arg(requirements_txt.path())
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.assert()
.success();
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import poetry_editable")
.assert()
.success();
// Uninstall the editable by name.
insta::with_settings!({
filters => filters.clone()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("poetry-editable")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
, @r###"
success: true
exit_code: 0
----- stdout -----
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("poetry-editable")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Uninstalled 1 package in [TIME]
- poetry-editable==0.1.0 (from file://[WORKSPACE_DIR]/scripts/editable-installs/poetry_editable)
"###);
});
----- stderr -----
Uninstalled 1 package in [TIME]
- poetry-editable==0.1.0 (from file://[WORKSPACE_DIR]/scripts/editable-installs/poetry_editable)
"###
);
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import poetry_editable")
.assert()
@ -451,9 +427,7 @@ fn uninstall_editable_by_name() -> Result<()> {
#[test]
fn uninstall_editable_by_path() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = create_venv(&temp_dir, &cache_dir, "3.12");
let context = TestContext::new("3.12");
let current_dir = std::env::current_dir()?;
let workspace_dir = regex::escape(
@ -466,7 +440,7 @@ fn uninstall_editable_by_path() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();
let requirements_txt = temp_dir.child("requirements.txt");
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("-e ../../scripts/editable-installs/poetry_editable")?;
@ -475,40 +449,37 @@ fn uninstall_editable_by_path() -> Result<()> {
.arg("sync")
.arg(requirements_txt.path())
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.assert()
.success();
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import poetry_editable")
.assert()
.success();
// Uninstall the editable by path.
insta::with_settings!({
filters => filters.clone()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("-e")
.arg("../../scripts/editable-installs/poetry_editable")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("-e")
.arg("../../scripts/editable-installs/poetry_editable")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Uninstalled 1 package in [TIME]
- poetry-editable==0.1.0 (from file://[WORKSPACE_DIR]/scripts/editable-installs/poetry_editable)
"###);
});
----- stderr -----
Uninstalled 1 package in [TIME]
- poetry-editable==0.1.0 (from file://[WORKSPACE_DIR]/scripts/editable-installs/poetry_editable)
"###
);
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import poetry_editable")
.assert()
@ -519,9 +490,7 @@ fn uninstall_editable_by_path() -> Result<()> {
#[test]
fn uninstall_duplicate_editable() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = create_venv(&temp_dir, &cache_dir, "3.12");
let context = TestContext::new("3.12");
let current_dir = std::env::current_dir()?;
let workspace_dir = regex::escape(
@ -534,7 +503,7 @@ fn uninstall_duplicate_editable() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();
let requirements_txt = temp_dir.child("requirements.txt");
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("-e ../../scripts/editable-installs/poetry_editable")?;
@ -543,41 +512,38 @@ fn uninstall_duplicate_editable() -> Result<()> {
.arg("sync")
.arg(requirements_txt.path())
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.assert()
.success();
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import poetry_editable")
.assert()
.success();
// Uninstall the editable by both path and name.
insta::with_settings!({
filters => filters.clone()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("poetry-editable")
.arg("-e")
.arg("../../scripts/editable-installs/poetry_editable")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("pip")
.arg("uninstall")
.arg("poetry-editable")
.arg("-e")
.arg("../../scripts/editable-installs/poetry_editable")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Uninstalled 1 package in [TIME]
- poetry-editable==0.1.0 (from file://[WORKSPACE_DIR]/scripts/editable-installs/poetry_editable)
"###);
});
----- stderr -----
Uninstalled 1 package in [TIME]
- poetry-editable==0.1.0 (from file://[WORKSPACE_DIR]/scripts/editable-installs/poetry_editable)
"###
);
Command::new(venv_to_interpreter(&venv))
Command::new(venv_to_interpreter(&context.venv))
.arg("-c")
.arg("import poetry_editable")
.assert()

View file

@ -2,10 +2,12 @@ use std::process::Command;
use anyhow::Result;
use assert_fs::prelude::*;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
use insta_cmd::get_cargo_bin;
use common::BIN_NAME;
use crate::common::puffin_snapshot;
mod common;
#[test]
@ -13,7 +15,7 @@ fn missing_pyproject_toml() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let pyproject_toml = temp_dir.child("pyproject.toml");
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("flask")
.current_dir(&temp_dir), @r###"
@ -39,7 +41,7 @@ fn missing_project_table() -> Result<()> {
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.touch()?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("flask")
.current_dir(&temp_dir), @r###"
@ -70,7 +72,7 @@ name = "project"
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("flask")
.current_dir(&temp_dir), @r###"
@ -108,7 +110,7 @@ dependencies = [
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("requests")
.current_dir(&temp_dir), @r###"
@ -150,7 +152,7 @@ dependencies = [
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("flask")
.current_dir(&temp_dir), @r###"
@ -187,7 +189,7 @@ dependencies = [
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("requests")
.current_dir(&temp_dir), @r###"
@ -223,7 +225,7 @@ dependencies = [
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("Flask")
.current_dir(&temp_dir), @r###"
@ -258,7 +260,7 @@ dependencies = ["flask==1.0.0", "requests"]
"#,
)?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
puffin_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("remove")
.arg("requests")
.current_dir(&temp_dir), @r###"

View file

@ -4,12 +4,12 @@ use std::process::Command;
use anyhow::Result;
use assert_fs::prelude::*;
use insta_cmd::_macro_support::insta;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
use puffin_fs::NormalizedDisplay;
use insta_cmd::get_cargo_bin;
use common::BIN_NAME;
use puffin_fs::NormalizedDisplay;
use crate::common::puffin_snapshot;
mod common;
@ -20,29 +20,30 @@ fn create_venv() -> Result<()> {
let venv = temp_dir.child(".venv");
let filter_venv = regex::escape(&venv.normalized_display().to_string());
insta::with_settings!({
filters => vec![
(r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]"),
(&filter_venv, "/home/ferris/project/.venv"),
]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--python")
.arg("3.12")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
let filters = &[
(
r"Using Python 3\.\d+\.\d+ interpreter at .+",
"Using Python [VERSION] interpreter at [PATH]",
),
(&filter_venv, "/home/ferris/project/.venv"),
];
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--python")
.arg("3.12")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Using Python [VERSION] interpreter at [PATH]
Creating virtualenv at: /home/ferris/project/.venv
"###);
});
----- stderr -----
Using Python [VERSION] interpreter at [PATH]
Creating virtualenv at: /home/ferris/project/.venv
"###
);
venv.assert(predicates::path::is_dir());
@ -56,28 +57,29 @@ fn create_venv_defaults_to_cwd() -> Result<()> {
let venv = temp_dir.child(".venv");
let filter_venv = regex::escape(&venv.normalized_display().to_string());
insta::with_settings!({
filters => vec![
(r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]"),
(&filter_venv, "/home/ferris/project/.venv"),
]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg("--python")
.arg("3.12")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
let filters = &[
(
r"Using Python 3\.\d+\.\d+ interpreter at .+",
"Using Python [VERSION] interpreter at [PATH]",
),
(&filter_venv, "/home/ferris/project/.venv"),
];
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg("--python")
.arg("3.12")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Using Python [VERSION] interpreter at [PATH]
Creating virtualenv at: .venv
"###);
});
----- stderr -----
Using Python [VERSION] interpreter at [PATH]
Creating virtualenv at: .venv
"###
);
venv.assert(predicates::path::is_dir());
@ -91,33 +93,34 @@ fn seed() -> Result<()> {
let venv = temp_dir.child(".venv");
let filter_venv = regex::escape(&venv.normalized_display().to_string());
insta::with_settings!({
filters => vec![
(r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]"),
(&filter_venv, "/home/ferris/project/.venv"),
]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--seed")
.arg("--python")
.arg("3.12")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
let filters = &[
(
r"Using Python 3\.\d+\.\d+ interpreter at .+",
"Using Python [VERSION] interpreter at [PATH]",
),
(&filter_venv, "/home/ferris/project/.venv"),
];
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--seed")
.arg("--python")
.arg("3.12")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Using Python [VERSION] interpreter at [PATH]
Creating virtualenv at: /home/ferris/project/.venv
+ setuptools==69.0.3
+ pip==23.3.2
+ wheel==0.42.0
"###);
});
----- stderr -----
Using Python [VERSION] interpreter at [PATH]
Creating virtualenv at: /home/ferris/project/.venv
+ setuptools==69.0.3
+ pip==23.3.2
+ wheel==0.42.0
"###
);
venv.assert(predicates::path::is_dir());
@ -131,28 +134,29 @@ fn create_venv_unknown_python_minor() -> Result<()> {
let venv = temp_dir.child(".venv");
let filter_venv = regex::escape(&venv.display().to_string());
insta::with_settings!({
filters => vec![
(r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]"),
(&filter_venv, "/home/ferris/project/.venv"),
]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--python")
.arg("3.15")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
let filters = &[
(
r"Using Python 3\.\d+\.\d+ interpreter at .+",
"Using Python [VERSION] interpreter at [PATH]",
),
(&filter_venv, "/home/ferris/project/.venv"),
];
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--python")
.arg("3.15")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× Couldn't find `python3.15` in PATH. Is this Python version installed?
"###);
});
----- stderr -----
× Couldn't find `python3.15` in PATH. Is this Python version installed?
"###
);
venv.assert(predicates::path::missing());
@ -166,28 +170,29 @@ fn create_venv_unknown_python_patch() -> Result<()> {
let venv = temp_dir.child(".venv");
let filter_venv = regex::escape(&venv.normalized_display().to_string());
insta::with_settings!({
filters => vec![
(r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]"),
(&filter_venv, "/home/ferris/project/.venv"),
]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--python")
.arg("3.8.0")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
let filters = &[
(
r"Using Python 3\.\d+\.\d+ interpreter at .+",
"Using Python [VERSION] interpreter at [PATH]",
),
(&filter_venv, "/home/ferris/project/.venv"),
];
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--python")
.arg("3.8.0")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× Couldn't find `python3.8.0` in PATH. Is this Python version installed?
"###);
});
----- stderr -----
× Couldn't find `python3.8.0` in PATH. Is this Python version installed?
"###
);
venv.assert(predicates::path::missing());
@ -201,29 +206,27 @@ fn create_venv_python_patch() -> Result<()> {
let venv = temp_dir.child(".venv");
let filter_venv = regex::escape(&venv.normalized_display().to_string());
insta::with_settings!({
filters => vec![
(r"interpreter at .+", "interpreter at [PATH]"),
(&filter_venv, "/home/ferris/project/.venv"),
]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--python")
.arg("3.12.1")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
let filters = &[
(r"interpreter at .+", "interpreter at [PATH]"),
(&filter_venv, "/home/ferris/project/.venv"),
];
puffin_snapshot!(filters, Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--python")
.arg("3.12.1")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Using Python 3.12.1 interpreter at [PATH]
Creating virtualenv at: /home/ferris/project/.venv
"###);
});
----- stderr -----
Using Python 3.12.1 interpreter at [PATH]
Creating virtualenv at: /home/ferris/project/.venv
"###
);
venv.assert(predicates::path::is_dir());