Skip to content

Commit 8834092

Browse files
committed
Add test coverage for #10978
1 parent 7949672 commit 8834092

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

crates/uv/tests/it/pip_compile.rs

+84
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,90 @@ fn compile_python_312_annotation_line() -> Result<()> {
13441344
Ok(())
13451345
}
13461346

1347+
/// Compile for 3.12 when only a different interpreter version is available.
1348+
#[test]
1349+
fn compile_fallback_interpreter() -> Result<()> {
1350+
let context = TestContext::new("3.10");
1351+
let requirements_in = context.temp_dir.child("requirements.in");
1352+
requirements_in.write_str("black==23.10.1")?;
1353+
1354+
uv_snapshot!(context.filters(), context.pip_compile()
1355+
.arg("requirements.in")
1356+
.arg("--python-version")
1357+
.arg("3.12"), @r###"
1358+
success: true
1359+
exit_code: 0
1360+
----- stdout -----
1361+
# This file was autogenerated by uv via the following command:
1362+
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-version 3.12
1363+
black==23.10.[X]
1364+
# via -r requirements.in
1365+
click==8.1.7
1366+
# via black
1367+
mypy-extensions==1.0.0
1368+
# via black
1369+
packaging==24.0
1370+
# via black
1371+
pathspec==0.12.1
1372+
# via black
1373+
platformdirs==4.2.0
1374+
# via black
1375+
1376+
----- stderr -----
1377+
warning: The requested Python version 3.12 is not available; 3.10.[X] will be used to build dependencies instead.
1378+
Resolved 6 packages in [TIME]
1379+
"###
1380+
);
1381+
1382+
Ok(())
1383+
}
1384+
1385+
/// Compile for 3.12 when only a different interpreter version is available, there's also
1386+
/// a broken interpreter in the PATH.
1387+
#[test]
1388+
#[cfg(unix)]
1389+
fn compile_fallback_interpreter_broken_in_path() -> Result<()> {
1390+
use std::os::unix::fs::PermissionsExt;
1391+
1392+
let context = TestContext::new("3.10");
1393+
let requirements_in = context.temp_dir.child("requirements.in");
1394+
requirements_in.write_str("black==23.10.1")?;
1395+
1396+
// Create a "broken" Python executable in the test context `bin`
1397+
let contents = r"#!/bin/sh
1398+
echo 'error: intentionally broken python executable' >&2
1399+
exit 1";
1400+
let python = context
1401+
.bin_dir
1402+
.join(format!("python3{}", std::env::consts::EXE_SUFFIX));
1403+
fs_err::write(&python, contents).unwrap();
1404+
1405+
let mut perms = fs_err::metadata(&python).unwrap().permissions();
1406+
perms.set_mode(0o755);
1407+
fs_err::set_permissions(&python, perms).unwrap();
1408+
1409+
uv_snapshot!(context.filters(), context.pip_compile()
1410+
.arg("requirements.in")
1411+
.arg("--python-version")
1412+
.arg("3.12")
1413+
// In tests, we ignore `PATH` during Python discovery so we need to add the context `bin`
1414+
.env("UV_TEST_PYTHON_PATH", context.bin_dir.as_os_str()), @r###"
1415+
success: false
1416+
exit_code: 2
1417+
----- stdout -----
1418+
1419+
----- stderr -----
1420+
error: Failed to inspect Python interpreter from search path at `[BIN]/python3`
1421+
Caused by: Querying Python at `[BIN]/python3` failed with exit status exit status: 1
1422+
1423+
[stderr]
1424+
error: intentionally broken python executable
1425+
"###
1426+
);
1427+
1428+
Ok(())
1429+
}
1430+
13471431
/// Resolve a specific version of Black at Python 3.12 without deps.
13481432
#[test]
13491433
fn compile_python_312_no_deps() -> Result<()> {

0 commit comments

Comments
 (0)