Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Feb 22, 2024
1 parent e772c05 commit c4c98f3
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ impl TestContext {
self.assert_command(
format!("import {package} as package; print(package.__version__, end='')").as_str(),
)
.success()
.stdout(version);
.success()
.stdout(version);
}
}

Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn create_bin_with_executables(
&Platform::current().unwrap(),
&Cache::temp().unwrap(),
)?
.ok_or(uv_interpreter::Error::NoSuchPython(request.to_string()))?;
.ok_or(uv_interpreter::Error::NoSuchPython(request.to_string()))?;
let name = interpreter
.sys_executable()
.file_name()
Expand All @@ -244,7 +244,7 @@ pub fn run_and_format<'a>(
let output = command
.borrow_mut()
.output()
.unwrap_or_else(|_| panic!("Failed to spawn {program}"));
.unwrap_or_else(|err| panic!("Failed to spawn {program}: {err}"));

let mut snapshot = format!(
"success: {:?}\nexit_code: {}\n----- stdout -----\n{}\n----- stderr -----\n{}",
Expand Down
93 changes: 93 additions & 0 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(all(feature = "python", feature = "pypi"))]

use std::io::ErrorKind;
use std::process::Command;

use anyhow::Result;
Expand Down Expand Up @@ -1391,3 +1392,95 @@ fn direct_url_zip_file_bunk_permissions() -> Result<()> {

Ok(())
}

#[test]
fn entrypoint_script() -> Result<()> {
let context = TestContext::new("3.12");
let project_root = fs_err::canonicalize(std::env::current_dir()?.join("../.."))?;

uv_snapshot!(command(&context)
.arg(format!("simple_launcher@{}", project_root.join("scripts/wheels/simple_launcher-0.1.0-py3-none-any.whl").display()))
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Installed 1 package in [TIME]
+ simple-launcher==0.1.0 (from file:///C:/Users/Micha/astral/puffin/scripts/wheels/simple_launcher-0.1.0-py3-none-any.whl)
"###
);

let bin_path = if cfg!(windows) { "Scripts" } else { "bin" };

uv_snapshot!(Command::new(
context.venv.join(bin_path).join("simple_launcher")
), @r###"
success: true
exit_code: 0
----- stdout -----
Hi from the simple launcher!
----- stderr -----
"###);

Ok(())
}

#[test]
fn entrypoint_script_symlink() -> Result<()> {
let context = TestContext::new("3.12");
let project_root = fs_err::canonicalize(std::env::current_dir()?.join("../.."))?;

uv_snapshot!(command(&context)
.arg(format!("simple_launcher@{}", project_root.join("scripts/wheels/simple_launcher-0.1.0-py3-none-any.whl").display()))
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Installed 1 package in [TIME]
+ simple-launcher==0.1.0 (from file:///C:/Users/Micha/astral/puffin/scripts/wheels/simple_launcher-0.1.0-py3-none-any.whl)
"###
);

#[cfg(windows)]
if let Err(error) = std::os::windows::fs::symlink_file(
context.venv.join("Scripts\\simple_launcher.exe"),
context.temp_dir.join("simple_launcher.exe"),
) {
if error.kind() == ErrorKind::PermissionDenied {
// Not running as an administrator or developer mode isn't enabled.
// Ignore the test
return Ok(());
}
}

#[cfg(unix)]
std::os::unix::fs::symlink(
context.venv.join("bin/simple_launcher"),
context.temp_dir.join("simple_launcher"),
)?;

// Only support windows or linux
#[cfg(not(any(windows, unix)))]
return Ok(());

uv_snapshot!(Command::new(
context.temp_dir.join("simple_launcher")
), @r###"
success: true
exit_code: 0
----- stdout -----
Hi from the simple launcher!
----- stderr -----
"###);

Ok(())
}
Binary file not shown.

0 comments on commit c4c98f3

Please sign in to comment.