Skip to content

Commit 1a486d1

Browse files
Add coverage for Python build upgrades (#21320)
Adds regression coverage for same-version managed Python build upgrades through both `uv python install --upgrade` and `uv python upgrade`. The tests capture the current behavior: the command reports a replacement, but invoking the interpreter still observes contents from the previous build. ```console $ uv python upgrade 3.12 Installed Python 3.12.<latest> ~ cpython-3.12.<latest>-<platform> $ python3.12 -c 'import sys; print(sys.version.split()[0])' 3.12.0 ``` Co-authored-by: Zanie Blue <[email protected]>
1 parent 17b195b commit 1a486d1

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎crates/uv/tests/python/python_install.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,6 +3951,21 @@ fn python_install_upgrade_build_version() {
39513951
));
39523952
let build_file = installation_dir.join("BUILD");
39533953
fs_err::write(&build_file, "19000101").unwrap();
3954+
// A build upgrade retains the Python version and installation key, so set the interpreter's
3955+
// modification time to a known value to detect whether the interpreter is replaced.
3956+
let python_executable = if cfg!(windows) {
3957+
installation_dir.join("python.exe")
3958+
} else {
3959+
installation_dir.join("bin").join("python3.12")
3960+
};
3961+
filetime::set_file_mtime(
3962+
&python_executable,
3963+
filetime::FileTime::from_unix_time(1_700_000_000, 0),
3964+
)
3965+
.unwrap();
3966+
let previous_mtime = filetime::FileTime::from_last_modification_time(
3967+
&fs_err::metadata(&python_executable).unwrap(),
3968+
);
39543969

39553970
// Now upgrade should detect the outdated build version and reinstall
39563971
uv_snapshot!(context.filters(), context.python_install().arg("--upgrade").arg("3.12"), @"
@@ -3960,6 +3975,13 @@ fn python_install_upgrade_build_version() {
39603975
~ cpython-3.12.[LATEST]-[PLATFORM]
39613976
");
39623977

3978+
assert_eq!(
3979+
filetime::FileTime::from_last_modification_time(
3980+
&fs_err::metadata(&python_executable).unwrap()
3981+
),
3982+
previous_mtime
3983+
);
3984+
39633985
// Should be a no-op again after upgrade
39643986
uv_snapshot!(context.filters(), context.python_install().arg("--upgrade").arg("3.12"), @"
39653987
exit_code: 0 (success)

‎crates/uv/tests/python/python_upgrade.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,21 @@ fn python_upgrade_build_version() {
644644
));
645645
let build_file = installation_dir.join("BUILD");
646646
fs_err::write(&build_file, "19000101").unwrap();
647+
// A build upgrade retains the Python version and installation key, so set the interpreter's
648+
// modification time to a known value to detect whether the interpreter is replaced.
649+
let python_executable = if cfg!(windows) {
650+
installation_dir.join("python.exe")
651+
} else {
652+
installation_dir.join("bin").join("python3.12")
653+
};
654+
filetime::set_file_mtime(
655+
&python_executable,
656+
filetime::FileTime::from_unix_time(1_700_000_000, 0),
657+
)
658+
.unwrap();
659+
let previous_mtime = filetime::FileTime::from_last_modification_time(
660+
&fs_err::metadata(&python_executable).unwrap(),
661+
);
647662

648663
// Now upgrade should detect the outdated build version and reinstall
649664
uv_snapshot!(context.filters(), context.python_upgrade().arg("3.12"), @"
@@ -653,6 +668,13 @@ fn python_upgrade_build_version() {
653668
~ cpython-3.12.[LATEST]-[PLATFORM]
654669
");
655670

671+
assert_eq!(
672+
filetime::FileTime::from_last_modification_time(
673+
&fs_err::metadata(&python_executable).unwrap()
674+
),
675+
previous_mtime
676+
);
677+
656678
// Should be a no-op again after upgrade
657679
uv_snapshot!(context.filters(), context.python_upgrade().arg("3.12"), @"
658680
exit_code: 0 (success)

0 commit comments

Comments
 (0)