248d6f89ef
The snapshot filtering situation has gotten way out of hand, with each
test hand-rolling it's own filters on top of copied cruft from previous
tests.
I've attempted to address this holistically:
- `TestContext.filters()` has everything you should need
- This was introduced a while ago, but needed a few more filters for it
to be generalized everywhere
- Using `INSTA_FILTERS` is **not recommended** unless you do not want
the context filters
- It is okay to extend these filters for things unrelated to paths
- If you have to write a custom path filter, please highlight it in
review so we can address it in the common module
- `TestContext.site_packages()` gives cross-platform access to the
site-packages directory
- Do not manually construct the path to site-packages from the venv
- Do not turn off tests on Windows because you manually constructed a
Unix path to site-packages
- `TestContext.workspace_root` gives access to uv's repository directory
- Use this for installing from `scripts/packages/`
- If you need coverage for relative paths, copy the test package into
the `temp_dir` don't change the working directory of the test fixture
There is additional work that can be done here, such as:
- Auditing and removing additional uses of `INSTA_FILTERS`
- Updating manual construction of `Command` instances to use a utility
- The `venv` tests are particularly frightening in their lack of a test
context and could use some love
- Improving the developer experience i.e. apply context filters to
snapshots by default
112 lines
3.2 KiB
Plaintext
112 lines
3.2 KiB
Plaintext
//! DO NOT EDIT
|
|
//!
|
|
//! Generated with {{generated_with}}
|
|
//! Scenarios from <{{generated_from}}>
|
|
//!
|
|
#![cfg(all(feature = "python", feature = "pypi"))]
|
|
|
|
use std::env;
|
|
use std::process::Command;
|
|
|
|
use anyhow::Result;
|
|
use assert_cmd::assert::OutputAssertExt;
|
|
use assert_fs::fixture::{FileWriteStr, PathChild};
|
|
use predicates::prelude::predicate;
|
|
|
|
use common::{create_bin_with_executables, get_bin, uv_snapshot, TestContext, INSTA_FILTERS};
|
|
|
|
mod common;
|
|
|
|
/// 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_bin());
|
|
command
|
|
.arg("pip")
|
|
.arg("compile")
|
|
.arg("requirements.in")
|
|
.arg("--index-url")
|
|
.arg("{{index_url}}")
|
|
.arg("--find-links")
|
|
.arg("{{vendor_links}}")
|
|
.arg("--cache-dir")
|
|
.arg(context.cache_dir.path())
|
|
.env("VIRTUAL_ENV", context.venv.as_os_str())
|
|
.env("UV_NO_WRAP", "1")
|
|
.env("UV_TEST_PYTHON_PATH", bin)
|
|
.current_dir(&context.temp_dir);
|
|
|
|
if cfg!(all(windows, debug_assertions)) {
|
|
// TODO(konstin): Reduce stack usage in debug mode enough that the tests pass with the
|
|
// default windows stack of 1MB
|
|
command.env("UV_STACK_SIZE", (8 * 1024 * 1024).to_string());
|
|
}
|
|
|
|
command
|
|
}
|
|
|
|
{{#scenarios}}
|
|
|
|
{{#description_lines}}
|
|
/// {{.}}
|
|
{{/description_lines}}
|
|
///
|
|
/// ```text
|
|
/// {{name}}
|
|
{{#tree}}
|
|
/// {{.}}
|
|
{{/tree}}
|
|
/// ```
|
|
#[test]
|
|
fn {{module_name}}() -> Result<()> {
|
|
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 shorter messages
|
|
let mut filters = context.filters();
|
|
filters.push((r"{{name}}-", "package-"));
|
|
|
|
let requirements_in = context.temp_dir.child("requirements.in");
|
|
{{#root.requires}}
|
|
requirements_in.write_str("{{requirement}}")?;
|
|
{{/root.requires}}
|
|
|
|
{{#expected.explanation_lines}}
|
|
// {{.}}
|
|
{{/expected.explanation_lines}}
|
|
let output = uv_snapshot!(filters, command(&context, python_versions)
|
|
{{#resolver_options.prereleases}}
|
|
.arg("--prerelease=allow")
|
|
{{/resolver_options.prereleases}}
|
|
{{#resolver_options.no_build}}
|
|
.arg("--only-binary")
|
|
.arg("{{.}}")
|
|
{{/resolver_options.no_build}}
|
|
{{#resolver_options.no_binary}}
|
|
.arg("--no-binary")
|
|
.arg("{{.}}")
|
|
{{/resolver_options.no_binary}}
|
|
{{#resolver_options.python}}
|
|
.arg("--python-version={{.}}")
|
|
{{/resolver_options.python}}, @r###"<snapshot>
|
|
"###
|
|
);
|
|
|
|
output
|
|
.assert()
|
|
{{#expected.satisfiable}}
|
|
.success()
|
|
{{#expected.packages}}
|
|
.stdout(predicate::str::contains("{{name}}=={{version}}"))
|
|
{{/expected.packages}}
|
|
{{/expected.satisfiable}}
|
|
{{^expected.satisfiable}}
|
|
.failure()
|
|
{{/expected.satisfiable}}
|
|
;
|
|
|
|
Ok(())
|
|
}
|
|
{{/scenarios}}
|