Refactor pip scenario tests (#1212)
Mostly a mechanical refactor to use the `puffin_snapshot!` and `TestContext` infrastructure in the pip compile and pip install scenarios, in preparation for adding programmatic windows testing filters.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}};
|
||||
}
|
||||
|
||||
/// <https://stackoverflow.com/a/31749071/3549270>
|
||||
#[allow(unused_imports)]
|
||||
pub(crate) use puffin_snapshot;
|
||||
|
||||
@@ -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<()> {
|
||||
|
||||
@@ -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<PathBuf> {
|
||||
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(())
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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<PathBuf> {
|
||||
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###"<snapshot>
|
||||
"###);
|
||||
});
|
||||
puffin_snapshot!(filters, command(&context, python_versions)
|
||||
{{#environment.prereleases}}
|
||||
.arg("--prerelease=allow")
|
||||
{{/environment.prereleases}}
|
||||
{{#resolver_options.python}}
|
||||
.arg("--python-version={{.}}")
|
||||
{{/resolver_options.python}}, @r###"<snapshot>
|
||||
"###
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -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###"<snapshot>
|
||||
"###);
|
||||
});
|
||||
puffin_snapshot!(filters, command(&context)
|
||||
{{#environment.prereleases}}
|
||||
.arg("--prerelease=allow")
|
||||
{{/environment.prereleases}}
|
||||
{{#root.requires}}
|
||||
.arg("{{requirement}}")
|
||||
{{/root.requires}}, @r###"<snapshot>
|
||||
"###);
|
||||
|
||||
{{#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}}
|
||||
|
||||
Reference in New Issue
Block a user