Use shared insta filters (#270)

Internal refactoring for consistency between tests
This commit is contained in:
konsti 2023-11-02 16:42:59 +01:00 committed by GitHub
parent 62c474d880
commit c6f2dfd727
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 73 deletions

View file

@ -4,7 +4,9 @@ use anyhow::Result;
use assert_fs::prelude::*;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
const BIN_NAME: &str = "puffin";
use common::BIN_NAME;
mod common;
#[test]
fn missing_pyproject_toml() -> Result<()> {

View file

@ -0,0 +1,8 @@
pub(crate) const BIN_NAME: &str = "puffin";
// Not all tests use them and cargo warns otherwise
#[allow(dead_code)]
pub(crate) const INSTA_FILTERS: &[(&str, &str)] = &[
(r"(\d+\.)?\d+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
];

View file

@ -8,7 +8,9 @@ use assert_fs::prelude::*;
use insta_cmd::_macro_support::insta;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
const BIN_NAME: &str = "puffin";
use common::{BIN_NAME, INSTA_FILTERS};
mod common;
#[test]
fn missing_requirements_in() -> Result<()> {
@ -69,11 +71,7 @@ fn compile_requirements_in() -> Result<()> {
requirements_in.write_str("django==5.0b1")?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
@ -119,11 +117,7 @@ dependencies = [
)?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
@ -163,11 +157,7 @@ fn compile_constraints_txt() -> Result<()> {
constraints_txt.write_str("sqlparse<0.4.4")?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
@ -210,11 +200,7 @@ fn compile_constraints_inline() -> Result<()> {
constraints_txt.write_str("sqlparse<0.4.4")?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
@ -311,11 +297,7 @@ optional-dependencies.foo = [
)?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
@ -364,11 +346,7 @@ optional-dependencies."FrIeNdLy-._.-bArD" = [
)?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
@ -417,11 +395,7 @@ optional-dependencies.foo = [
)?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
@ -470,11 +444,7 @@ optional-dependencies.foo = [
)?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")

View file

@ -8,7 +8,9 @@ use assert_fs::prelude::*;
use insta_cmd::_macro_support::insta;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
const BIN_NAME: &str = "puffin";
use common::{BIN_NAME, INSTA_FILTERS};
mod common;
#[test]
fn missing_requirements_txt() -> Result<()> {
@ -70,9 +72,7 @@ fn install() -> Result<()> {
requirements_txt.write_str("MarkupSafe==2.1.3")?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
@ -115,9 +115,7 @@ fn install_copy() -> Result<()> {
requirements_txt.write_str("MarkupSafe==2.1.3")?;
insta::with_settings!({
filters => vec![
(r"(\d|\.)+(ms|s)", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
@ -162,9 +160,7 @@ fn install_hardlink() -> Result<()> {
requirements_txt.write_str("MarkupSafe==2.1.3")?;
insta::with_settings!({
filters => vec![
(r"\d+ms|\d+\.\d+s", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
@ -209,9 +205,7 @@ fn install_many() -> Result<()> {
requirements_txt.write_str("MarkupSafe==2.1.3\ntomli==2.0.1")?;
insta::with_settings!({
filters => vec![
(r"\d+ms|\d+\.\d+s", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
@ -264,9 +258,7 @@ fn noop() -> Result<()> {
.success();
insta::with_settings!({
filters => vec![
(r"\d+ms|\d+\.\d+s", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
@ -331,9 +323,7 @@ fn link() -> Result<()> {
venv.assert(predicates::path::is_dir());
insta::with_settings!({
filters => vec![
(r"\d+ms|\d+\.\d+s", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
@ -391,9 +381,7 @@ fn add_remove() -> Result<()> {
requirements_txt.write_str("tomli==2.0.1")?;
insta::with_settings!({
filters => vec![
(r"\d+ms|\d+\.\d+s", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
@ -458,9 +446,7 @@ fn install_sequential() -> Result<()> {
requirements_txt.write_str("MarkupSafe==2.1.3\ntomli==2.0.1")?;
insta::with_settings!({
filters => vec![
(r"\d+ms|\d+\.\d+s", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
@ -518,9 +504,7 @@ fn upgrade() -> Result<()> {
requirements_txt.write_str("tomli==2.0.1")?;
insta::with_settings!({
filters => vec![
(r"\d+ms|\d+\.\d+s", "[TIME]"),
]
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")

View file

@ -4,7 +4,9 @@ use anyhow::Result;
use assert_fs::prelude::*;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
const BIN_NAME: &str = "puffin";
use common::BIN_NAME;
mod common;
#[test]
fn no_arguments() -> Result<()> {

View file

@ -4,7 +4,9 @@ use anyhow::Result;
use assert_fs::prelude::*;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
const BIN_NAME: &str = "puffin";
use common::BIN_NAME;
mod common;
#[test]
fn missing_pyproject_toml() -> Result<()> {

View file

@ -7,7 +7,9 @@ use assert_fs::prelude::*;
use insta_cmd::_macro_support::insta;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
const BIN_NAME: &str = "puffin";
use common::BIN_NAME;
mod common;
#[test]
fn create_venv() -> Result<()> {