Skip to content

Commit

Permalink
Use helpers in all editable tests (#2339)
Browse files Browse the repository at this point in the history
## Summary

Improves consistency and helps with the kinds of failures seen in
#2320.
  • Loading branch information
charliermarsh authored Mar 10, 2024
1 parent be00b5b commit 7fc8087
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 338 deletions.
65 changes: 18 additions & 47 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg(all(feature = "python", feature = "pypi"))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::disallowed_types))]

use std::env::current_dir;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
Expand Down Expand Up @@ -2450,20 +2451,14 @@ fn compile_editable() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();

uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("compile")
.arg(requirements_in.path())
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
uv_snapshot!(filters, context.compile()
.arg(requirements_in.path())
.current_dir(current_dir()?), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in
-e ${PROJECT_ROOT}/../../scripts/editable-installs/maturin_editable
-e ../../scripts/editable-installs/poetry_editable
-e file://../../scripts/editable-installs/black_editable
Expand Down Expand Up @@ -2574,20 +2569,14 @@ fn compile_editable_url_requirement() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();

uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("compile")
.arg(requirements_in.path())
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
uv_snapshot!(filters, context.compile()
.arg(requirements_in.path())
.current_dir(current_dir()?), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in
-e ../../scripts/editable-installs/hatchling_editable
iniconfig @ https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl
# via hatchling-editable
Expand Down Expand Up @@ -4050,20 +4039,14 @@ fn editable_invalid_extra() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();

uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("compile")
uv_snapshot!(filters, context.compile()
.arg(requirements_in.path())
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
.current_dir(current_dir()?), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in
-e ../../scripts/editable-installs/black_editable
----- stderr -----
Expand Down Expand Up @@ -4235,22 +4218,16 @@ fn override_editable() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();

uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("compile")
uv_snapshot!(filters, context.compile()
.arg(requirements_in.path())
.arg("--override")
.arg(overrides_txt.path())
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
.current_dir(current_dir()?), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --override overrides.txt --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --override overrides.txt
-e ../../scripts/editable-installs/black_editable
----- stderr -----
Expand Down Expand Up @@ -4588,22 +4565,16 @@ fn editable_direct_dependency() -> Result<()> {
.chain(INSTA_FILTERS.to_vec())
.collect();

uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("compile")
uv_snapshot!(filters, context.compile()
.arg(requirements_in.path())
.arg("--resolution")
.arg("lowest-direct")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
.current_dir(current_dir()?), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in --resolution lowest-direct --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in --resolution lowest-direct
-e ../../scripts/editable-installs/setuptools_editable
iniconfig==0.1
# via setuptools-editable
Expand Down
48 changes: 24 additions & 24 deletions crates/uv/tests/pip_freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ fn command(context: &TestContext) -> Command {
command
}

/// Create a `pip install` command with options shared across scenarios.
fn sync_command(context: &TestContext) -> Command {
let mut command = Command::new(get_bin());
command
.arg("pip")
.arg("sync")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.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", (2 * 1024 * 1024).to_string());
}

command
}

/// List multiple installed packages in a virtual environment.
#[test]
fn freeze_many() -> Result<()> {
Expand All @@ -32,13 +52,8 @@ fn freeze_many() -> Result<()> {
requirements_txt.write_str("MarkupSafe==2.1.3\ntomli==2.0.1")?;

// Run `pip sync`.
Command::new(get_bin())
.arg("pip")
.arg("sync")
sync_command(&context)
.arg(requirements_txt.path())
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.assert()
.success();

Expand Down Expand Up @@ -70,13 +85,8 @@ fn freeze_duplicate() -> Result<()> {
requirements_txt.write_str("pip==21.3.1")?;

// Run `pip sync`.
Command::new(get_bin())
.arg("pip")
.arg("sync")
sync_command(&context1)
.arg(requirements_txt.path())
.arg("--cache-dir")
.arg(context1.cache_dir.path())
.env("VIRTUAL_ENV", context1.venv.as_os_str())
.assert()
.success();

Expand All @@ -86,13 +96,8 @@ fn freeze_duplicate() -> Result<()> {
requirements_txt.write_str("pip==22.1.1")?;

// Run `pip sync`.
Command::new(get_bin())
.arg("pip")
.arg("sync")
sync_command(&context2)
.arg(requirements_txt.path())
.arg("--cache-dir")
.arg(context2.cache_dir.path())
.env("VIRTUAL_ENV", context2.venv.as_os_str())
.assert()
.success();

Expand Down Expand Up @@ -148,13 +153,8 @@ fn freeze_url() -> Result<()> {
requirements_txt.write_str("anyio\niniconfig @ https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl")?;

// Run `pip sync`.
Command::new(get_bin())
.arg("pip")
.arg("sync")
sync_command(&context)
.arg(requirements_txt.path())
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.assert()
.success();

Expand Down
66 changes: 18 additions & 48 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,17 +516,10 @@ fn install_editable() -> Result<()> {
.collect::<Vec<_>>();

// Install the editable package.
uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("install")
uv_snapshot!(filters, command(&context)
.arg("-e")
.arg("../../scripts/editable-installs/poetry_editable")
.arg("--strict")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&current_dir)
.env("CARGO_TARGET_DIR", "../../../target/target_install_editable"), @r###"
success: true
exit_code: 0
Expand Down Expand Up @@ -618,16 +611,9 @@ fn install_editable_and_registry() -> Result<()> {
.collect();

// Install the registry-based version of Black.
uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("install")
uv_snapshot!(filters, command(&context)
.arg("black")
.arg("--strict")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&current_dir)
.env("CARGO_TARGET_DIR", "../../../target/target_install_editable"), @r###"
success: true
exit_code: 0
Expand All @@ -647,17 +633,10 @@ fn install_editable_and_registry() -> Result<()> {
);

// Install the editable version of Black. This should remove the registry-based version.
uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("install")
uv_snapshot!(filters, command(&context)
.arg("-e")
.arg("../../scripts/editable-installs/black_editable")
.arg("--strict")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&current_dir)
.env("CARGO_TARGET_DIR", "../../../target/target_install_editable"), @r###"
success: true
exit_code: 0
Expand All @@ -674,16 +653,10 @@ fn install_editable_and_registry() -> Result<()> {

// Re-install the registry-based version of Black. This should be a no-op, since we have a
// version of Black installed (the editable version) that satisfies the requirements.
uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("install")
uv_snapshot!(filters, command(&context)
.arg("black")
.arg("--strict")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&current_dir)
.env("CARGO_TARGET_DIR", "../../../target/target_install_editable"), @r###"
success: true
exit_code: 0
Expand All @@ -703,16 +676,9 @@ fn install_editable_and_registry() -> Result<()> {
.collect();

// Re-install Black at a specific version. This should replace the editable version.
uv_snapshot!(filters2, Command::new(get_bin())
.arg("pip")
.arg("install")
uv_snapshot!(filters2, command(&context)
.arg("black==23.10.0")
.arg("--strict")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&current_dir)
.env("CARGO_TARGET_DIR", "../../../target/target_install_editable"), @r###"
success: true
exit_code: 0
Expand Down Expand Up @@ -856,18 +822,22 @@ fn install_extra_index_url_has_priority() {
// the fix, `uv` will check pypi.org first since it is given
// priority via --extra-index-url.
.arg("black==24.2.0")
.arg("--no-deps")
.arg("--exclude-newer")
.arg("2024-03-09"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Installed 1 package in [TIME]
Resolved 6 packages in [TIME]
Downloaded 6 packages in [TIME]
Installed 6 packages in [TIME]
+ black==24.2.0
+ click==8.1.7
+ mypy-extensions==1.0.0
+ packaging==23.2
+ pathspec==0.12.1
+ platformdirs==4.2.0
"###
);

Expand Down
Loading

0 comments on commit 7fc8087

Please sign in to comment.