Skip to content

Commit de60ad5

Browse files
authored
Use latest Python version filtering in more places (#18273)
Add `with_filtered_latest_python_versions()` to tests that were using hardcoded patch versions for latest Python releases. This makes the tests resilient to Python version bumps by using `[LATEST]` placeholders instead of specific version numbers like `3.12.12` or `3.10.19`. Also use `LATEST_PYTHON_3_12` constant for constructing directory paths in the build version upgrade tests.
1 parent 1eb571b commit de60ad5

5 files changed

Lines changed: 94 additions & 75 deletions

File tree

crates/uv/tests/it/pip_install.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13830,7 +13830,8 @@ fn install_with_system_interpreter() {
1383013830
let context = uv_test::test_context_with_versions!(&[])
1383113831
.with_python_download_cache()
1383213832
.with_managed_python_dirs()
13833-
.with_filtered_python_keys();
13833+
.with_filtered_python_keys()
13834+
.with_filtered_latest_python_versions();
1383413835

1383513836
// We use a managed Python version here to ensure consistent output across systems
1383613837
context.python_install().arg("3.12").assert().success();
@@ -13843,8 +13844,8 @@ fn install_with_system_interpreter() {
1384313844
----- stdout -----
1384413845
1384513846
----- stderr -----
13846-
Using Python 3.12.13 environment at: managed/cpython-3.12.13-[PLATFORM]
13847-
error: The interpreter at managed/cpython-3.12.13-[PLATFORM] is externally managed, and indicates the following:
13847+
Using Python 3.12.[LATEST] environment at: managed/cpython-3.12.[LATEST]-[PLATFORM]
13848+
error: The interpreter at managed/cpython-3.12.[LATEST]-[PLATFORM] is externally managed, and indicates the following:
1384813849
1384913850
This Python installation is managed by uv and should not be modified.
1385013851
@@ -13913,7 +13914,8 @@ fn install_missing_python_version_with_target() {
1391313914
// Create a context that only has Python 3.11 available.
1391413915
let context = uv_test::test_context!("3.11")
1391513916
.with_python_download_cache()
13916-
.with_managed_python_dirs();
13917+
.with_managed_python_dirs()
13918+
.with_filtered_latest_python_versions();
1391713919

1391813920
let target_dir = context.temp_dir.child("target-dir");
1391913921

@@ -13927,7 +13929,7 @@ fn install_missing_python_version_with_target() {
1392713929
----- stdout -----
1392813930
1392913931
----- stderr -----
13930-
Using CPython 3.12.13
13932+
Using CPython 3.12.[LATEST]
1393113933
Resolved 3 packages in [TIME]
1393213934
Prepared 3 packages in [TIME]
1393313935
Installed 3 packages in [TIME]

crates/uv/tests/it/pip_sync.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6189,7 +6189,8 @@ fn sync_with_target_installs_missing_python() -> Result<()> {
61896189
// Create a context that only has Python 3.11 available.
61906190
let context = uv_test::test_context!("3.11")
61916191
.with_python_download_cache()
6192-
.with_managed_python_dirs();
6192+
.with_managed_python_dirs()
6193+
.with_filtered_latest_python_versions();
61936194

61946195
let target_dir = context.temp_dir.child("target-dir");
61956196
let requirements = context.temp_dir.child("requirements.txt");
@@ -6205,7 +6206,7 @@ fn sync_with_target_installs_missing_python() -> Result<()> {
62056206
----- stdout -----
62066207
62076208
----- stderr -----
6208-
Using CPython 3.12.13
6209+
Using CPython 3.12.[LATEST]
62096210
Resolved 1 package in [TIME]
62106211
Prepared 1 package in [TIME]
62116212
Installed 1 package in [TIME]

crates/uv/tests/it/python_install.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use assert_fs::{
1212
use indoc::indoc;
1313
use predicates::prelude::predicate;
1414
use tracing::debug;
15-
use uv_test::uv_snapshot;
15+
use uv_test::{LATEST_PYTHON_3_12, uv_snapshot};
1616

1717
use uv_fs::Simplified;
1818
use uv_python::managed::platform_key_from_env;
@@ -207,7 +207,8 @@ fn python_reinstall_patch() {
207207
.with_filtered_python_keys()
208208
.with_filtered_exe_suffix()
209209
.with_managed_python_dirs()
210-
.with_python_download_cache();
210+
.with_python_download_cache()
211+
.with_filtered_latest_python_versions();
211212

212213
// Install a couple patch versions
213214
uv_snapshot!(context.filters(), context.python_install().arg("3.12.6").arg("3.12.7"), @"
@@ -230,8 +231,8 @@ fn python_reinstall_patch() {
230231
----- stdout -----
231232
232233
----- stderr -----
233-
Installed Python 3.12.13 in [TIME]
234-
+ cpython-3.12.13-[PLATFORM] (python3.12)
234+
Installed Python 3.12.[LATEST] in [TIME]
235+
+ cpython-3.12.[LATEST]-[PLATFORM] (python3.12)
235236
");
236237
}
237238

@@ -4220,7 +4221,8 @@ fn python_install_upgrade_build_version() {
42204221
.with_python_download_cache()
42214222
.with_filtered_python_keys()
42224223
.with_filtered_exe_suffix()
4223-
.with_managed_python_dirs();
4224+
.with_managed_python_dirs()
4225+
.with_filtered_latest_python_versions();
42244226

42254227
// Install Python 3.12
42264228
uv_snapshot!(context.filters(), context.python_install().arg("3.12"), @"
@@ -4229,8 +4231,8 @@ fn python_install_upgrade_build_version() {
42294231
----- stdout -----
42304232
42314233
----- stderr -----
4232-
Installed Python 3.12.13 in [TIME]
4233-
+ cpython-3.12.13-[PLATFORM] (python3.12)
4234+
Installed Python 3.12.[LATEST] in [TIME]
4235+
+ cpython-3.12.[LATEST]-[PLATFORM] (python3.12)
42344236
");
42354237

42364238
// Should be a no-op when already installed at latest version
@@ -4245,7 +4247,8 @@ fn python_install_upgrade_build_version() {
42454247

42464248
// Overwrite the BUILD file with an older build version
42474249
let installation_dir = context.temp_dir.child("managed").child(format!(
4248-
"cpython-3.12.13-{}",
4250+
"cpython-{}-{}",
4251+
LATEST_PYTHON_3_12,
42494252
platform_key_from_env().unwrap()
42504253
));
42514254
let build_file = installation_dir.join("BUILD");
@@ -4258,8 +4261,8 @@ fn python_install_upgrade_build_version() {
42584261
----- stdout -----
42594262
42604263
----- stderr -----
4261-
Installed Python 3.12.13 in [TIME]
4262-
~ cpython-3.12.13-[PLATFORM]
4264+
Installed Python 3.12.[LATEST] in [TIME]
4265+
~ cpython-3.12.[LATEST]-[PLATFORM]
42634266
");
42644267

42654268
// Should be a no-op again after upgrade

crates/uv/tests/it/python_list.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,19 @@ fn python_list_duplicate_path_entries() {
360360

361361
#[test]
362362
fn python_list_downloads() {
363-
let context = uv_test::test_context_with_versions!(&[]).with_filtered_python_keys();
363+
let context = uv_test::test_context_with_versions!(&[])
364+
.with_filtered_python_keys()
365+
.with_filtered_latest_python_versions();
364366

365367
// We do not test showing all interpreters — as it differs per platform
366-
// Instead, we choose a Python version where our available distributions are stable
368+
// Instead, we choose a Python version where our available distributions are stable
367369

368370
// Test the default display, which requires reverting the test context disabling Python downloads
369371
uv_snapshot!(context.filters(), context.python_list().arg("3.10").env_remove(EnvVars::UV_PYTHON_DOWNLOADS), @"
370372
success: true
371373
exit_code: 0
372374
----- stdout -----
373-
cpython-3.10.20-[PLATFORM] <download available>
375+
cpython-3.10.[LATEST]-[PLATFORM] <download available>
374376
pypy-3.10.16-[PLATFORM] <download available>
375377
graalpy-3.10.0-[PLATFORM] <download available>
376378
@@ -382,7 +384,7 @@ fn python_list_downloads() {
382384
success: true
383385
exit_code: 0
384386
----- stdout -----
385-
cpython-3.10.20-[PLATFORM] <download available>
387+
cpython-3.10.[LATEST]-[PLATFORM] <download available>
386388
cpython-3.10.19-[PLATFORM] <download available>
387389
cpython-3.10.18-[PLATFORM] <download available>
388390
cpython-3.10.17-[PLATFORM] <download available>
@@ -420,17 +422,18 @@ fn python_list_downloads_installed() {
420422
.with_filtered_python_keys()
421423
.with_filtered_python_install_bin()
422424
.with_filtered_python_names()
423-
.with_managed_python_dirs();
425+
.with_managed_python_dirs()
426+
.with_filtered_latest_python_versions();
424427

425-
// We do not test showing all interpreters as it differs per platform
426-
// Instead, we choose a Python version where our available distributions are stable
428+
// We do not test showing all interpreters - as it differs per platform
429+
// Instead, we choose a Python version where our available distributions are stable
427430

428431
// First, the download is shown as available
429432
uv_snapshot!(context.filters(), context.python_list().arg("3.10").env_remove(EnvVars::UV_PYTHON_DOWNLOADS), @"
430433
success: true
431434
exit_code: 0
432435
----- stdout -----
433-
cpython-3.10.20-[PLATFORM] <download available>
436+
cpython-3.10.[LATEST]-[PLATFORM] <download available>
434437
pypy-3.10.16-[PLATFORM] <download available>
435438
graalpy-3.10.0-[PLATFORM] <download available>
436439
@@ -457,7 +460,7 @@ fn python_list_downloads_installed() {
457460
success: true
458461
exit_code: 0
459462
----- stdout -----
460-
cpython-3.10.20-[PLATFORM] managed/cpython-3.10-[PLATFORM]/[INSTALL-BIN]/[PYTHON]
463+
cpython-3.10.[LATEST]-[PLATFORM] managed/cpython-3.10-[PLATFORM]/[INSTALL-BIN]/[PYTHON]
461464
pypy-3.10.16-[PLATFORM] <download available>
462465
graalpy-3.10.0-[PLATFORM] <download available>
463466
@@ -469,7 +472,7 @@ fn python_list_downloads_installed() {
469472
success: true
470473
exit_code: 0
471474
----- stdout -----
472-
cpython-3.10.20-[PLATFORM] <download available>
475+
cpython-3.10.[LATEST]-[PLATFORM] <download available>
473476
pypy-3.10.16-[PLATFORM] <download available>
474477
graalpy-3.10.0-[PLATFORM] <download available>
475478
@@ -596,6 +599,7 @@ fn python_list_with_mirrors() {
596599
let context = uv_test::test_context_with_versions!(&[])
597600
.with_filtered_python_keys()
598601
.with_collapsed_whitespace()
602+
.with_filtered_latest_python_versions()
599603
// Add filters to normalize file paths in URLs
600604
.with_filter((
601605
r"(https://mirror\.example\.com/).*".to_string(),
@@ -666,7 +670,7 @@ fn python_list_with_mirrors() {
666670
success: true
667671
exit_code: 0
668672
----- stdout -----
669-
cpython-3.10.20-[PLATFORM] https://python-mirror.example.com/[FILE-PATH]
673+
cpython-3.10.[LATEST]-[PLATFORM] https://python-mirror.example.com/[FILE-PATH]
670674
pypy-3.10.16-[PLATFORM] https://pypy-mirror.example.com/[FILE-PATH]
671675
graalpy-3.10.0-[PLATFORM] https://github.com/oracle/graalpython/releases/download/[FILE-PATH]
672676
@@ -681,7 +685,7 @@ fn python_list_with_mirrors() {
681685
success: true
682686
exit_code: 0
683687
----- stdout -----
684-
cpython-3.10.20-[PLATFORM] https://releases.astral.sh/github/python-build-standalone/releases/download/[FILE-PATH]
688+
cpython-3.10.[LATEST]-[PLATFORM] https://releases.astral.sh/github/python-build-standalone/releases/download/[FILE-PATH]
685689
pypy-3.10.16-[PLATFORM] https://downloads.python.org/pypy/[FILE-PATH]
686690
graalpy-3.10.0-[PLATFORM] https://github.com/oracle/graalpython/releases/download/[FILE-PATH]
687691

0 commit comments

Comments
 (0)