Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,3 @@ pub fn create_conda_env(name: &str, major: usize, minor: usize) -> Result<(PathB
pub fn test_python_path() -> Option<String> {
env::var("MATURIN_TEST_PYTHON").ok()
}

/// Find index of subslice in a larger slice
pub fn find_subslice<T: PartialEq>(haystack: &[T], needle: &[T]) -> Option<usize> {
if needle.is_empty() {
return Some(0);
}
haystack
.windows(needle.len())
.position(|window| window == needle)
}
32 changes: 25 additions & 7 deletions tests/common/pep517.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::str;

pub fn target_dir(unique_name: &str) -> String {
format!(
"{}/test-crates/targets/{unique_name}",
env!("CARGO_MANIFEST_DIR")
)
}

/// Creates a virtualenv and activates it, checks that the package isn't installed, uses
/// pip install to install it and checks it is working
pub fn test_pep517(
Expand Down Expand Up @@ -47,13 +54,8 @@ pub fn test_pep517(

cmd.arg(package.to_str().expect("package is utf8 path"));

cmd.env(
"CARGO_TARGET_DIR",
format!(
"{}/test-crates/targets/{unique_name}",
env!("CARGO_MANIFEST_DIR")
),
);
let target_dir = target_dir(unique_name);
cmd.env("CARGO_TARGET_DIR", target_dir);

// Building with `--no-build-isolation` means that `maturin` needs to be on PATH _and_
// importable
Expand Down Expand Up @@ -91,3 +93,19 @@ fn insert_path(env_var: &str, new_path: &Path) -> String {
.into_string()
.expect("PATH is not valid utf8")
}

/// Whether cargo built the shared library for the specified cargo profile in the test target
/// directory.
pub fn target_has_profile(unique_name: &str, profile: &str) -> bool {
let shared_library = if cfg!(windows) {
"pyo3_pure.dll"
} else if cfg!(target_os = "macos") {
"libpyo3_pure.dylib"
} else {
"libpyo3_pure.so"
};
PathBuf::from(target_dir(unique_name))
.join(profile)
.join(shared_library)
.is_file()
}
27 changes: 11 additions & 16 deletions tests/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! To speed up the tests, they are tests all collected in a single module

use common::pep517::{target_has_profile, test_pep517};
use common::{
TestInstallBackend, develop, errors, handle_result, integration, other,
test_python_implementation,
Expand All @@ -14,8 +15,6 @@ use std::time::Duration;
use time::macros::datetime;
use which::which;

use crate::common::{find_subslice, pep517};

mod common;

#[test]
Expand Down Expand Up @@ -1004,32 +1003,28 @@ fn sdist_source_date_epoch() {

#[test]
fn pep517_default_profile() {
let output = handle_result(pep517::test_pep517(
let unique_name = "pep517-pyo3-pure";
handle_result(test_pep517(
"test-crates/pyo3-pure",
"pep517-pyo3-pure",
unique_name,
false,
false,
));

assert!(
find_subslice(&output.stderr, b"`release` profile [optimized]").is_some(),
"Output was: {}",
std::str::from_utf8(&output.stderr).unwrap()
);
assert!(target_has_profile(unique_name, "release"));
assert!(!target_has_profile(unique_name, "debug"));
}

#[test]
fn pep517_editable_profile() {
let output = handle_result(pep517::test_pep517(
let unique_name = "pep517-pyo3-pure-editable";
handle_result(test_pep517(
"test-crates/pyo3-pure",
"pep517-pyo3-pure-editable",
unique_name,
false,
true,
));

assert!(
find_subslice(&output.stderr, b"`dev` profile [unoptimized + debuginfo]").is_some(),
"Output was: {}",
std::str::from_utf8(&output.stderr).unwrap()
);
assert!(!target_has_profile(unique_name, "release"));
assert!(target_has_profile(unique_name, "debug"));
}
Loading