Skip to content

Commit de13f02

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

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

crates/uv/tests/it/pip_compile.rs

+82
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,88 @@ 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+
let context = TestContext::new("3.10");
1391+
let requirements_in = context.temp_dir.child("requirements.in");
1392+
requirements_in.write_str("black==23.10.1")?;
1393+
1394+
// Create a "broken" Python executable in the test context `bin`
1395+
let contents = r"#!/bin/sh
1396+
echo 'error: intentionally broken python executable' >&2
1397+
exit 1";
1398+
let python = context
1399+
.bin_dir
1400+
.join(format!("python3{}", std::env::consts::EXE_SUFFIX));
1401+
fs_err::write(&python, contents).unwrap();
1402+
1403+
let mut perms = fs_err::metadata(&python).unwrap().permissions();
1404+
perms.set_mode(0o755);
1405+
fs_err::set_permissions(&python, perms).unwrap();
1406+
1407+
uv_snapshot!(context.filters(), context.pip_compile()
1408+
.arg("requirements.in")
1409+
.arg("--python-version")
1410+
.arg("3.12")
1411+
// In tests, we ignore `PATH` during Python discovery so we need to add the context `bin`
1412+
.env("UV_TEST_PYTHON_PATH", context.bin_dir.as_os_str()), @r###"
1413+
success: false
1414+
exit_code: 2
1415+
----- stdout -----
1416+
1417+
----- stderr -----
1418+
error: Failed to inspect Python interpreter from search path at `[BIN]/python3`
1419+
Caused by: Querying Python at `[BIN]/python3` failed with exit status exit status: 1
1420+
1421+
[stderr]
1422+
error: intentionally broken python executable
1423+
"###
1424+
);
1425+
1426+
Ok(())
1427+
}
1428+
13471429
/// Resolve a specific version of Black at Python 3.12 without deps.
13481430
#[test]
13491431
fn compile_python_312_no_deps() -> Result<()> {

0 commit comments

Comments
 (0)