mirror of https://github.com/astral-sh/uv
Add assertions that `pip compile` scenario test matches expected outcome
This commit is contained in:
parent
5cc4e5d31e
commit
ecba550152
|
|
@ -9,6 +9,7 @@ use std::path::PathBuf;
|
|||
use std::process::Command;
|
||||
|
||||
use anyhow::Result;
|
||||
use assert_cmd::assert::OutputAssertExt;
|
||||
use assert_fs::fixture::{FileWriteStr, PathChild};
|
||||
use common::{create_venv, BIN_NAME, INSTA_FILTERS};
|
||||
#[cfg(unix)]
|
||||
|
|
@ -17,6 +18,7 @@ use fs_err::os::unix::fs::symlink as symlink_file;
|
|||
use fs_err::os::windows::fs::symlink_file;
|
||||
use insta_cmd::_macro_support::insta;
|
||||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
|
||||
use predicates::prelude::predicate;
|
||||
use puffin_interpreter::find_requested_python;
|
||||
|
||||
mod common;
|
||||
|
|
@ -71,10 +73,8 @@ fn requires_incompatible_python_version_compatible_override() -> Result<()> {
|
|||
let requirements_in = 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))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -86,7 +86,12 @@ fn requires_incompatible_python_version_compatible_override() -> Result<()> {
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
|
@ -100,6 +105,11 @@ fn requires_incompatible_python_version_compatible_override() -> Result<()> {
|
|||
"###);
|
||||
});
|
||||
|
||||
command
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("a-006fed96==1.0.0"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -135,10 +145,8 @@ fn requires_compatible_python_version_incompatible_override() -> Result<()> {
|
|||
let requirements_in = 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))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -150,7 +158,12 @@ fn requires_compatible_python_version_incompatible_override() -> Result<()> {
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
|
|
@ -163,6 +176,8 @@ fn requires_compatible_python_version_incompatible_override() -> Result<()> {
|
|||
"###);
|
||||
});
|
||||
|
||||
command.assert().failure();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -199,13 +214,8 @@ fn requires_incompatible_python_version_compatible_override_no_wheels() -> Resul
|
|||
let requirements_in = 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))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -217,7 +227,12 @@ fn requires_incompatible_python_version_compatible_override_no_wheels() -> Resul
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
|
|
@ -230,6 +245,11 @@ fn requires_incompatible_python_version_compatible_override_no_wheels() -> Resul
|
|||
"###);
|
||||
});
|
||||
|
||||
// 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.
|
||||
command.assert().failure();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -269,12 +289,8 @@ fn requires_incompatible_python_version_compatible_override_no_wheels_available_
|
|||
let requirements_in = 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))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -286,7 +302,12 @@ fn requires_incompatible_python_version_compatible_override_no_wheels_available_
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
|
@ -299,6 +320,10 @@ fn requires_incompatible_python_version_compatible_override_no_wheels_available_
|
|||
"###);
|
||||
});
|
||||
|
||||
// Since there is a compatible Python version available on the system, it should be
|
||||
// used to build the source distributions.
|
||||
command.assert().success();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -335,13 +360,8 @@ fn requires_incompatible_python_version_compatible_override_no_compatible_wheels
|
|||
let requirements_in = 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))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -353,7 +373,12 @@ fn requires_incompatible_python_version_compatible_override_no_compatible_wheels
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
|
|
@ -366,6 +391,11 @@ fn requires_incompatible_python_version_compatible_override_no_compatible_wheels
|
|||
"###);
|
||||
});
|
||||
|
||||
// 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.
|
||||
command.assert().failure();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -406,14 +436,8 @@ fn requires_incompatible_python_version_compatible_override_other_wheel() -> Res
|
|||
let requirements_in = 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))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -425,7 +449,12 @@ fn requires_incompatible_python_version_compatible_override_other_wheel() -> Res
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
|
|
@ -446,6 +475,12 @@ fn requires_incompatible_python_version_compatible_override_other_wheel() -> Res
|
|||
"###);
|
||||
});
|
||||
|
||||
// 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.
|
||||
command.assert().failure();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -481,12 +516,8 @@ fn requires_python_patch_version_override_no_patch() -> Result<()> {
|
|||
let requirements_in = 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))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -498,7 +529,12 @@ fn requires_python_patch_version_override_no_patch() -> Result<()> {
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"
|
||||
success: false
|
||||
exit_code: 1
|
||||
----- stdout -----
|
||||
|
|
@ -510,6 +546,10 @@ fn requires_python_patch_version_override_no_patch() -> Result<()> {
|
|||
"###);
|
||||
});
|
||||
|
||||
// Since the resolver is asked to solve with 3.8, the minimum compatible Python
|
||||
// requirement is treated as 3.8.0.
|
||||
command.assert().failure();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -545,10 +585,8 @@ fn requires_python_patch_version_override_patch_compatible() -> Result<()> {
|
|||
let requirements_in = 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))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -560,7 +598,12 @@ fn requires_python_patch_version_override_patch_compatible() -> Result<()> {
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
|
@ -574,5 +617,10 @@ fn requires_python_patch_version_override_patch_compatible() -> Result<()> {
|
|||
"###);
|
||||
});
|
||||
|
||||
command
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("a-844899bd==1.0.0"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use std::path::PathBuf;
|
|||
use std::process::Command;
|
||||
|
||||
use anyhow::Result;
|
||||
use assert_cmd::assert::OutputAssertExt;
|
||||
use assert_fs::fixture::{FileWriteStr, PathChild};
|
||||
use common::{create_venv, BIN_NAME, INSTA_FILTERS};
|
||||
#[cfg(unix)]
|
||||
|
|
@ -17,6 +18,7 @@ use fs_err::os::unix::fs::symlink as symlink_file;
|
|||
use fs_err::os::windows::fs::symlink_file;
|
||||
use insta_cmd::_macro_support::insta;
|
||||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
|
||||
use predicates::prelude::predicate;
|
||||
use puffin_interpreter::find_requested_python;
|
||||
|
||||
mod common;
|
||||
|
|
@ -33,7 +35,7 @@ pub(crate) fn create_bin_with_executables(
|
|||
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()?)
|
||||
}
|
||||
|
|
@ -71,13 +73,8 @@ fn {{module_name}}() -> Result<()> {
|
|||
requirements_in.write_str("{{requirement}}")?;
|
||||
{{/root.requires}}
|
||||
|
||||
{{#expected.explanation_lines}}
|
||||
// {{.}}
|
||||
{{/expected.explanation_lines}}
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
let mut inner = Command::new(get_cargo_bin(BIN_NAME));
|
||||
let mut command = inner
|
||||
.arg("pip")
|
||||
.arg("compile")
|
||||
.arg("requirements.in")
|
||||
|
|
@ -94,10 +91,31 @@ fn {{module_name}}() -> Result<()> {
|
|||
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||
.env("PUFFIN_NO_WRAP", "1")
|
||||
.env("PUFFIN_PYTHON_PATH", bin)
|
||||
.current_dir(&temp_dir), @r###"<snapshot>
|
||||
.current_dir(&temp_dir);
|
||||
|
||||
insta::with_settings!({
|
||||
filters => filters
|
||||
}, {
|
||||
assert_cmd_snapshot!(command, @r###"<snapshot>
|
||||
"###);
|
||||
});
|
||||
|
||||
{{#expected.explanation_lines}}
|
||||
// {{.}}
|
||||
{{/expected.explanation_lines}}
|
||||
command
|
||||
.assert()
|
||||
{{#expected.satisfiable}}
|
||||
.success()
|
||||
{{#expected.packages}}
|
||||
.stdout(predicate::str::contains("{{name}}=={{version}}"));
|
||||
{{/expected.packages}}
|
||||
{{/expected.satisfiable}}
|
||||
{{^expected.satisfiable}}
|
||||
.failure()
|
||||
{{/expected.satisfiable}}
|
||||
;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
{{/scenarios}}
|
||||
|
|
|
|||
Loading…
Reference in New Issue