Skip to content

Commit

Permalink
Add test cases for uv tool install (#4509)
Browse files Browse the repository at this point in the history
Adds test cases for functionality in #4492.

Includes #4520 which was needed to pass CI.
  • Loading branch information
zanieb authored Jun 26, 2024
1 parent fe13ea3 commit dc40814
Show file tree
Hide file tree
Showing 3 changed files with 443 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/uv/src/commands/tool/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use tracing::debug;
use uv_cache::Cache;
use uv_client::Connectivity;
use uv_configuration::{Concurrency, PreviewMode};
use uv_fs::{replace_symlink, Simplified};
#[cfg(unix)]
use uv_fs::replace_symlink;
use uv_fs::Simplified;
use uv_installer::SitePackages;
use uv_requirements::RequirementsSource;
use uv_tool::{entrypoint_paths, find_executable_directory, InstalledTools, Tool};
Expand Down Expand Up @@ -122,7 +124,10 @@ pub(crate) async fn install(
for (name, path) in entrypoints {
let target = executable_directory.join(path.file_name().unwrap());
debug!("Installing {name} to {}", target.user_display());
#[cfg(unix)]
replace_symlink(&path, &target).context("Failed to install entrypoint")?;
#[cfg(windows)]
fs_err::copy(&path, &target).context("Failed to install entrypoint")?;
}

debug!("Adding `{name}` to {}", path.user_display());
Expand Down
31 changes: 31 additions & 0 deletions crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,26 @@ impl TestContext {
command
}

/// Create a `uv tool install` command with options shared across scenarios.
pub fn tool_install(&self) -> std::process::Command {
let mut command = self.tool_install_without_exclude_newer();
command.arg("--exclude-newer").arg(EXCLUDE_NEWER);
command
}

/// Create a `uv tool install` command with no `--exclude-newer` option.
///
/// One should avoid using this in tests to the extent possible because
/// it can result in tests failing when the index state changes. Therefore,
/// if you use this, there should be some other kind of mitigation in place.
/// For example, pinning package versions.
pub fn tool_install_without_exclude_newer(&self) -> std::process::Command {
let mut command = std::process::Command::new(get_bin());
command.arg("tool").arg("install");
self.add_shared_args(&mut command);
command
}

/// Create a `uv add` command for the given requirements.
pub fn add(&self, reqs: &[&str]) -> Command {
let mut command = Command::new(get_bin());
Expand Down Expand Up @@ -641,6 +661,7 @@ pub fn python_toolchains_for_versions(

#[derive(Debug, Copy, Clone)]
pub enum WindowsFilters {
CachedPlatform,
Platform,
Universal,
}
Expand Down Expand Up @@ -721,6 +742,10 @@ pub fn run_and_format<T: AsRef<str>>(
WindowsFilters::Platform => {
["Resolved", "Prepared", "Installed", "Uninstalled"].iter()
}
// When cached, "Prepared" should not change.
WindowsFilters::CachedPlatform => {
["Resolved", "Installed", "Uninstalled"].iter()
}
WindowsFilters::Universal => {
["Prepared", "Installed", "Uninstalled"].iter()
}
Expand Down Expand Up @@ -814,6 +839,12 @@ macro_rules! uv_snapshot {
::insta::assert_snapshot!(snapshot, @$snapshot);
output
}};
($filters:expr, cached_windows_filters=true, $spawnable:expr, @$snapshot:literal) => {{
// Take a reference for backwards compatibility with the vec-expecting insta filters.
let (snapshot, output) = $crate::common::run_and_format($spawnable, &$filters, function_name!(), Some($crate::common::WindowsFilters::CachedPlatform));
::insta::assert_snapshot!(snapshot, @$snapshot);
output
}};
}

/// <https://stackoverflow.com/a/31749071/3549270>
Expand Down
Loading

0 comments on commit dc40814

Please sign in to comment.