Skip to content

Commit

Permalink
Add test coverage for #10978 (#11029)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored Jan 28, 2025
1 parent 7949672 commit 0ae3fce
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions crates/uv/tests/it/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,90 @@ fn compile_python_312_annotation_line() -> Result<()> {
Ok(())
}

/// Compile for 3.12 when only a different interpreter version is available.
#[test]
fn compile_fallback_interpreter() -> Result<()> {
let context = TestContext::new("3.10");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("black==23.10.1")?;

uv_snapshot!(context.filters(), context.pip_compile()
.arg("requirements.in")
.arg("--python-version")
.arg("3.12"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-version 3.12
black==23.10.[X]
# via -r requirements.in
click==8.1.7
# via black
mypy-extensions==1.0.0
# via black
packaging==24.0
# via black
pathspec==0.12.1
# via black
platformdirs==4.2.0
# via black
----- stderr -----
warning: The requested Python version 3.12 is not available; 3.10.[X] will be used to build dependencies instead.
Resolved 6 packages in [TIME]
"###
);

Ok(())
}

/// Compile for 3.12 when only a different interpreter version is available, there's also
/// a broken interpreter in the PATH.
#[test]
#[cfg(unix)]
fn compile_fallback_interpreter_broken_in_path() -> Result<()> {
use std::os::unix::fs::PermissionsExt;

let context = TestContext::new("3.10");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("black==23.10.1")?;

// Create a "broken" Python executable in the test context `bin`
let contents = r"#!/bin/sh
echo 'error: intentionally broken python executable' >&2
exit 1";
let python = context
.bin_dir
.join(format!("python3{}", std::env::consts::EXE_SUFFIX));
fs_err::write(&python, contents).unwrap();

let mut perms = fs_err::metadata(&python).unwrap().permissions();
perms.set_mode(0o755);
fs_err::set_permissions(&python, perms).unwrap();

uv_snapshot!(context.filters(), context.pip_compile()
.arg("requirements.in")
.arg("--python-version")
.arg("3.12")
// In tests, we ignore `PATH` during Python discovery so we need to add the context `bin`
.env("UV_TEST_PYTHON_PATH", context.bin_dir.as_os_str()), @r###"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Failed to inspect Python interpreter from search path at `[BIN]/python3`
Caused by: Querying Python at `[BIN]/python3` failed with exit status exit status: 1
[stderr]
error: intentionally broken python executable
"###
);

Ok(())
}

/// Resolve a specific version of Black at Python 3.12 without deps.
#[test]
fn compile_python_312_no_deps() -> Result<()> {
Expand Down

0 comments on commit 0ae3fce

Please sign in to comment.