Skip to content

Commit

Permalink
Avoid filtering Python executables names during install tests (astral…
Browse files Browse the repository at this point in the history
…-sh#9458)

These were erroneously being filtered, interfering with the snapshots in
astral-sh#8650
  • Loading branch information
zanieb authored Nov 27, 2024
1 parent 8074917 commit b503a25
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 45 deletions.
3 changes: 2 additions & 1 deletion crates/uv/tests/it/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ impl TestContext {
pub fn with_filtered_python_keys(mut self) -> Self {
// Filter platform keys
self.filters.push((
r"((?:cpython|pypy)-\d+\.\d+(?:\.(?:\[X\]|\d+))?[a-z]?(?:\+[a-z]+)?)-.*".to_string(),
r"((?:cpython|pypy)-\d+\.\d+(?:\.(?:\[X\]|\d+))?[a-z]?(?:\+[a-z]+)?)-[a-z0-9]+-[a-z0-9_]+-[a-z]+"
.to_string(),
"$1-[PLATFORM]".to_string(),
));
self
Expand Down
136 changes: 92 additions & 44 deletions crates/uv/tests/it/python_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::common::{uv_snapshot, TestContext};

#[test]
fn python_install() {
let context: TestContext = TestContext::new_with_versions(&[]).with_filtered_python_keys();
let context: TestContext = TestContext::new_with_versions(&[])
.with_filtered_python_keys()
.with_filtered_exe_suffix();

// Install the latest version
uv_snapshot!(context.filters(), context.python_install(), @r###"
Expand Down Expand Up @@ -85,7 +87,7 @@ fn python_install() {
----- stderr -----
Searching for Python versions matching: Python 3.13
Uninstalled Python 3.13.0 in [TIME]
- cpython-3.13.0-[PLATFORM]
- cpython-3.13.0-[PLATFORM] (python3.13)
"###);
}

Expand All @@ -103,7 +105,7 @@ fn python_install_preview() {
----- stderr -----
Installed Python 3.13.0 in [TIME]
+ cpython-3.13.0-[PLATFORM]
+ cpython-3.13.0-[PLATFORM] (python3.13)
"###);

let bin_python = context
Expand Down Expand Up @@ -147,7 +149,7 @@ fn python_install_preview() {
----- stderr -----
Installed Python 3.13.0 in [TIME]
~ cpython-3.13.0-[PLATFORM]
~ cpython-3.13.0-[PLATFORM] (python3.13)
"###);

// The executable should still be present in the bin directory
Expand All @@ -161,7 +163,7 @@ fn python_install_preview() {
----- stderr -----
Installed Python 3.13.0 in [TIME]
+ cpython-3.13.0-[PLATFORM]
+ cpython-3.13.0-[PLATFORM] (python3.13)
"###);

// The executable should still be present in the bin directory
Expand All @@ -188,7 +190,7 @@ fn python_install_preview() {
----- stderr -----
Installed Python 3.13.0 in [TIME]
+ cpython-3.13.0-[PLATFORM]
+ cpython-3.13.0-[PLATFORM] (python3.13)
"###);

bin_python.assert(predicate::path::exists());
Expand Down Expand Up @@ -220,7 +222,7 @@ fn python_install_preview() {
----- stderr -----
Searching for Python versions matching: Python 3.13
Uninstalled Python 3.13.0 in [TIME]
- cpython-3.13.0-[PLATFORM]
- cpython-3.13.0-[PLATFORM] (python3.13)
"###);

// The executable should be removed
Expand All @@ -229,7 +231,9 @@ fn python_install_preview() {

#[test]
fn python_install_preview_upgrade() {
let context = TestContext::new_with_versions(&[]).with_filtered_python_keys();
let context = TestContext::new_with_versions(&[])
.with_filtered_python_keys()
.with_filtered_exe_suffix();

let bin_python = context
.temp_dir
Expand All @@ -244,7 +248,7 @@ fn python_install_preview_upgrade() {
----- stderr -----
Installed Python 3.12.5 in [TIME]
+ cpython-3.12.5-[PLATFORM]
+ cpython-3.12.5-[PLATFORM] (python3.12)
"###);

// Installing 3.12.4 should not replace the executable, but also shouldn't fail
Expand All @@ -258,13 +262,23 @@ fn python_install_preview_upgrade() {
+ cpython-3.12.4-[PLATFORM]
"###);

insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.5-[PLATFORM]"
);
});
if cfg!(unix) {
insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.5-[PLATFORM]/bin/python3.12"
);
});
} else {
insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.5-[PLATFORM]/python"
);
});
}

// Using `--reinstall` is not sufficient to replace it either
uv_snapshot!(context.filters(), context.python_install().arg("--preview").arg("3.12.4").arg("--reinstall"), @r###"
Expand All @@ -277,13 +291,23 @@ fn python_install_preview_upgrade() {
~ cpython-3.12.4-[PLATFORM]
"###);

insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.5-[PLATFORM]"
);
});
if cfg!(unix) {
insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.5-[PLATFORM]/bin/python3.12"
);
});
} else {
insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.5-[PLATFORM]/python"
);
});
}

// But `--force` is
uv_snapshot!(context.filters(), context.python_install().arg("--preview").arg("3.12.4").arg("--force"), @r###"
Expand All @@ -293,16 +317,26 @@ fn python_install_preview_upgrade() {
----- stderr -----
Installed Python 3.12.4 in [TIME]
+ cpython-3.12.4-[PLATFORM]
+ cpython-3.12.4-[PLATFORM] (python3.12)
"###);

insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.4-[PLATFORM]"
);
});
if cfg!(unix) {
insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.4-[PLATFORM]/bin/python3.12"
);
});
} else {
insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.4-[PLATFORM]/python"
);
});
}

// But installing 3.12.6 should upgrade automatically
uv_snapshot!(context.filters(), context.python_install().arg("--preview").arg("3.12.6"), @r###"
Expand All @@ -312,21 +346,33 @@ fn python_install_preview_upgrade() {
----- stderr -----
Installed Python 3.12.6 in [TIME]
+ cpython-3.12.6-[PLATFORM]
+ cpython-3.12.6-[PLATFORM] (python3.12)
"###);

insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.6-[PLATFORM]"
);
});
if cfg!(unix) {
insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.6-[PLATFORM]/bin/python3.12"
);
});
} else {
insta::with_settings!({
filters => context.filters(),
}, {
insta::assert_snapshot!(
read_link_path(&bin_python), @"[TEMP_DIR]/managed/cpython-3.12.6-[PLATFORM]/python"
);
});
}
}

#[test]
fn python_install_freethreaded() {
let context: TestContext = TestContext::new_with_versions(&[]).with_filtered_python_keys();
let context: TestContext = TestContext::new_with_versions(&[])
.with_filtered_python_keys()
.with_filtered_exe_suffix();

// Install the latest version
uv_snapshot!(context.filters(), context.python_install().arg("--preview").arg("3.13t"), @r###"
Expand All @@ -336,7 +382,7 @@ fn python_install_freethreaded() {
----- stderr -----
Installed Python 3.13.0 in [TIME]
+ cpython-3.13.0+freethreaded-[PLATFORM]
+ cpython-3.13.0+freethreaded-[PLATFORM] (python3.13t)
"###);

let bin_python = context
Expand Down Expand Up @@ -391,14 +437,16 @@ fn python_install_freethreaded() {
----- stderr -----
Searching for Python installations
Uninstalled 2 versions in [TIME]
- cpython-3.13.0-[PLATFORM]
- cpython-3.13.0+freethreaded-[PLATFORM]
- cpython-3.13.0-[PLATFORM] (python3.13)
- cpython-3.13.0+freethreaded-[PLATFORM] (python3.13t)
"###);
}

#[test]
fn python_install_invalid_request() {
let context: TestContext = TestContext::new_with_versions(&[]).with_filtered_python_keys();
let context: TestContext = TestContext::new_with_versions(&[])
.with_filtered_python_keys()
.with_filtered_exe_suffix();

// Request something that is not a Python version
uv_snapshot!(context.filters(), context.python_install().arg("foobar"), @r###"
Expand Down

0 comments on commit b503a25

Please sign in to comment.