mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
scripts/scenarios: update 'generate.py' to handle universal tests
This commit adds a template and does some light surgery on `generate.py` to make use of that template. In particular, the universal tests require using the "workspace"-aware version of `uv`, so we can't use the existing `uv pip {compile,install}` tests.
This commit is contained in:
parent
459966a132
commit
7b736fc238
2 changed files with 88 additions and 5 deletions
|
@ -49,12 +49,14 @@ TOOL_ROOT = Path(__file__).parent
|
||||||
TEMPLATES = TOOL_ROOT / "templates"
|
TEMPLATES = TOOL_ROOT / "templates"
|
||||||
INSTALL_TEMPLATE = TEMPLATES / "install.mustache"
|
INSTALL_TEMPLATE = TEMPLATES / "install.mustache"
|
||||||
COMPILE_TEMPLATE = TEMPLATES / "compile.mustache"
|
COMPILE_TEMPLATE = TEMPLATES / "compile.mustache"
|
||||||
|
LOCK_TEMPLATE = TEMPLATES / "lock.mustache"
|
||||||
PACKSE = TOOL_ROOT / "packse-scenarios"
|
PACKSE = TOOL_ROOT / "packse-scenarios"
|
||||||
REQUIREMENTS = TOOL_ROOT / "requirements.txt"
|
REQUIREMENTS = TOOL_ROOT / "requirements.txt"
|
||||||
PROJECT_ROOT = TOOL_ROOT.parent.parent
|
PROJECT_ROOT = TOOL_ROOT.parent.parent
|
||||||
TESTS = PROJECT_ROOT / "crates" / "uv" / "tests"
|
TESTS = PROJECT_ROOT / "crates" / "uv" / "tests"
|
||||||
INSTALL_TESTS = TESTS / "pip_install_scenarios.rs"
|
INSTALL_TESTS = TESTS / "pip_install_scenarios.rs"
|
||||||
COMPILE_TESTS = TESTS / "pip_compile_scenarios.rs"
|
COMPILE_TESTS = TESTS / "pip_compile_scenarios.rs"
|
||||||
|
LOCK_TESTS = TESTS / "lock_scenarios.rs"
|
||||||
TESTS_COMMON_MOD_RS = TESTS / "common/mod.rs"
|
TESTS_COMMON_MOD_RS = TESTS / "common/mod.rs"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -106,7 +108,8 @@ def main(scenarios: list[Path], snapshot_update: bool = True):
|
||||||
targets = []
|
targets = []
|
||||||
for target in scenarios:
|
for target in scenarios:
|
||||||
if target.is_dir():
|
if target.is_dir():
|
||||||
targets.extend(target.glob("*.json"))
|
targets.extend(target.glob("**/*.json"))
|
||||||
|
targets.extend(target.glob("**/*.toml"))
|
||||||
else:
|
else:
|
||||||
targets.append(target)
|
targets.append(target)
|
||||||
|
|
||||||
|
@ -119,8 +122,8 @@ def main(scenarios: list[Path], snapshot_update: bool = True):
|
||||||
data["scenarios"] = [
|
data["scenarios"] = [
|
||||||
scenario
|
scenario
|
||||||
for scenario in data["scenarios"]
|
for scenario in data["scenarios"]
|
||||||
# Drop the example scenario
|
# Drop example scenarios
|
||||||
if scenario["name"] != "example"
|
if not scenario["name"].startswith("example")
|
||||||
]
|
]
|
||||||
|
|
||||||
# Wrap the description onto multiple lines
|
# Wrap the description onto multiple lines
|
||||||
|
@ -158,12 +161,17 @@ def main(scenarios: list[Path], snapshot_update: bool = True):
|
||||||
"We do not have correct behavior for local version identifiers yet"
|
"We do not have correct behavior for local version identifiers yet"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Split scenarios into `install` and `compile` cases
|
# Split scenarios into `install`, `compile` and `lock` cases
|
||||||
install_scenarios = []
|
install_scenarios = []
|
||||||
compile_scenarios = []
|
compile_scenarios = []
|
||||||
|
lock_scenarios = []
|
||||||
|
|
||||||
for scenario in data["scenarios"]:
|
for scenario in data["scenarios"]:
|
||||||
if (scenario["resolver_options"] or {}).get("python") is not None:
|
resolver_options = scenario["resolver_options"] or {}
|
||||||
|
if resolver_options.get("universal"):
|
||||||
|
print(scenario["name"])
|
||||||
|
lock_scenarios.append(scenario)
|
||||||
|
elif resolver_options.get("python") is not None:
|
||||||
compile_scenarios.append(scenario)
|
compile_scenarios.append(scenario)
|
||||||
else:
|
else:
|
||||||
install_scenarios.append(scenario)
|
install_scenarios.append(scenario)
|
||||||
|
@ -171,6 +179,7 @@ def main(scenarios: list[Path], snapshot_update: bool = True):
|
||||||
for template, tests, scenarios in [
|
for template, tests, scenarios in [
|
||||||
(INSTALL_TEMPLATE, INSTALL_TESTS, install_scenarios),
|
(INSTALL_TEMPLATE, INSTALL_TESTS, install_scenarios),
|
||||||
(COMPILE_TEMPLATE, COMPILE_TESTS, compile_scenarios),
|
(COMPILE_TEMPLATE, COMPILE_TESTS, compile_scenarios),
|
||||||
|
(LOCK_TEMPLATE, LOCK_TESTS, lock_scenarios),
|
||||||
]:
|
]:
|
||||||
data = {"scenarios": scenarios}
|
data = {"scenarios": scenarios}
|
||||||
|
|
||||||
|
|
74
scripts/scenarios/templates/lock.mustache
Normal file
74
scripts/scenarios/templates/lock.mustache
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
//! DO NOT EDIT
|
||||||
|
//!
|
||||||
|
//! Generated with `{{generated_with}}`
|
||||||
|
//! Scenarios from <{{generated_from}}>
|
||||||
|
//!
|
||||||
|
#![cfg(all(feature = "python", feature = "pypi"))]
|
||||||
|
#![allow(clippy::needless_raw_string_hashes)]
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use assert_fs::prelude::*;
|
||||||
|
use insta::assert_snapshot;
|
||||||
|
|
||||||
|
use common::{uv_snapshot, TestContext};
|
||||||
|
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
{{#scenarios}}
|
||||||
|
|
||||||
|
{{#description_lines}}
|
||||||
|
/// {{.}}
|
||||||
|
{{/description_lines}}
|
||||||
|
///
|
||||||
|
/// ```text
|
||||||
|
/// {{name}}
|
||||||
|
{{#tree}}
|
||||||
|
/// {{.}}
|
||||||
|
{{/tree}}
|
||||||
|
/// ```
|
||||||
|
#[test]
|
||||||
|
fn {{module_name}}() -> Result<()> {
|
||||||
|
let context = TestContext::new("{{environment.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 pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||||
|
pyproject_toml.write_str(
|
||||||
|
r###"
|
||||||
|
[project]
|
||||||
|
name = "project"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
{{#root.requires}}
|
||||||
|
'''{{requirement}}''',
|
||||||
|
{{/root.requires}}
|
||||||
|
]
|
||||||
|
"###
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let mut cmd = context.lock_without_exclude_newer();
|
||||||
|
cmd.arg("--index-url").arg("{{index_url}}");
|
||||||
|
{{#expected.explanation_lines}}
|
||||||
|
// {{.}}
|
||||||
|
{{/expected.explanation_lines}}
|
||||||
|
uv_snapshot!(filters, cmd, @r###"<snapshot>
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
|
||||||
|
{{#expected.satisfiable}}
|
||||||
|
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock"))?;
|
||||||
|
insta::with_settings!({
|
||||||
|
filters => filters,
|
||||||
|
}, {
|
||||||
|
assert_snapshot!(
|
||||||
|
lock, @r###"<snapshot>
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
});
|
||||||
|
{{/expected.satisfiable}}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
{{/scenarios}}
|
Loading…
Add table
Add a link
Reference in a new issue