-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scenario tests for
pip-compile
(#1011)
e.g. for scenarios that test resolution _without_ installation. This refactors the `update` script to generate scenario test files for `pip compile` _and_ `pip install`. We don't overlap scenarios to save time. We only generate `pip compile` test cases for scenarios we cannot represent with `pip install` e.g. a `--python-version` override. The _one_ scenario I added happened to reveal a bug in our resolver where we were incorrectly filtering versions by the installed version when wheels were available. Per the comment at #883 (comment), we should _only_ need to check for a compatible installed Python version when using a different _target_ Python version if we need to build a source distribution. 53bce68 resolves this by removing the excessive constraints — the correct Python version incompatibilities are applied elsewhere.
- Loading branch information
Showing
6 changed files
with
226 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//! DO NOT EDIT | ||
//! | ||
//! Generated with ./scripts/scenarios/update.py | ||
//! Scenarios from <https://github.com/zanieb/packse/tree/9a836122ad43eb9c8115ef09f3beb7779512cd78/scenarios> | ||
//! | ||
#![cfg(all(feature = "python", feature = "pypi"))] | ||
|
||
use std::process::Command; | ||
|
||
use anyhow::Result; | ||
use assert_fs::fixture::{FileWriteStr, PathChild}; | ||
use insta_cmd::_macro_support::insta; | ||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; | ||
|
||
use common::{create_venv, BIN_NAME, INSTA_FILTERS}; | ||
|
||
mod common; | ||
|
||
/// requires-python-version-greater-than-current-resolver-override | ||
/// | ||
/// The user requires a package which requires a Python version greater than the | ||
/// current version, but they use an alternative Python version for package | ||
/// resolution. | ||
/// | ||
/// ```text | ||
/// b6505624 | ||
/// ├── environment | ||
/// │ └── python3.9 | ||
/// ├── root | ||
/// │ └── requires a==1.0.0 | ||
/// │ └── satisfied by a-1.0.0 | ||
/// └── a | ||
/// └── a-1.0.0 | ||
/// └── requires python>=3.10 (incompatible with environment) | ||
/// ``` | ||
#[test] | ||
fn requires_python_version_greater_than_current_resolver_override() -> Result<()> { | ||
let temp_dir = assert_fs::TempDir::new()?; | ||
let cache_dir = assert_fs::TempDir::new()?; | ||
let venv = create_venv(&temp_dir, &cache_dir, "python3.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-b6505624", "albatross")); | ||
filters.push((r"-b6505624", "")); | ||
|
||
let requirements_in = temp_dir.child("requirements.in"); | ||
requirements_in.write_str("a-b6505624==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") | ||
.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 | ||
----- stderr ----- | ||
Resolved 1 package in [TIME] | ||
"###); | ||
}); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//! DO NOT EDIT | ||
//! | ||
//! Generated with {{generated_with}} | ||
//! Scenarios from <{{generated_from}}> | ||
//! | ||
#![cfg(all(feature = "python", feature = "pypi"))] | ||
|
||
use std::process::Command; | ||
|
||
use anyhow::Result; | ||
use assert_fs::fixture::{FileWriteStr, PathChild}; | ||
use insta_cmd::_macro_support::insta; | ||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; | ||
|
||
use common::{create_venv, BIN_NAME, INSTA_FILTERS}; | ||
|
||
mod common; | ||
{{#scenarios}} | ||
|
||
/// {{name}} | ||
/// | ||
{{#description_lines}} | ||
/// {{.}} | ||
{{/description_lines}} | ||
/// | ||
/// ```text | ||
/// {{version}} | ||
{{#tree}} | ||
/// {{.}} | ||
{{/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, "python{{environment.python}}"); | ||
// In addition to the standard filters, swap out package names for more realistic messages | ||
let mut filters = INSTA_FILTERS.to_vec(); | ||
{{#packages}} | ||
filters.push((r"{{name}}", "{{cute_name}}")); | ||
{{/packages}} | ||
filters.push((r"-{{version}}", "")); | ||
|
||
let requirements_in = temp_dir.child("requirements.in"); | ||
{{#root.requires}} | ||
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)) | ||
.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") | ||
.current_dir(&temp_dir), @r###"<snapshot> | ||
"###); | ||
}); | ||
|
||
Ok(()) | ||
} | ||
{{/scenarios}} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters