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
3 changes: 2 additions & 1 deletion crates/pet-conda/tests/ci_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#![cfg(unix)]

use serde::Deserialize;
use std::path::PathBuf;
Expand Down Expand Up @@ -387,7 +388,7 @@ fn create_conda_env(mode: &CondaCreateEnvNameOrPath, python_version: Option<Stri
.expect("Failed to execute command");
}

fn get_version(value: &String) -> String {
fn get_version(value: &str) -> String {
// Regex to extract just the d.d.d version from the full version string
let re = regex::Regex::new(r"\d+\.\d+\.\d+").unwrap();
let captures = re.captures(value).unwrap();
Expand Down
30 changes: 16 additions & 14 deletions crates/pet-conda/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,29 @@ pub struct TestEnvironment {
root: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
}

impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}

#[allow(dead_code)]
pub fn create_test_environment(
vars: HashMap<String, String>,
home: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
root: Option<PathBuf>,
) -> TestEnvironment {
impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}
TestEnvironment {
vars,
home,
Expand Down
1 change: 1 addition & 0 deletions crates/pet-conda/tests/environments_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#![cfg(unix)]

mod common;
use common::resolve_test_path;
Expand Down
1 change: 1 addition & 0 deletions crates/pet-conda/tests/package_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#![cfg(unix)]

mod common;
use pet_conda::package::{self, CondaPackageInfo};
Expand Down
1 change: 1 addition & 0 deletions crates/pet-conda/tests/utils_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#![cfg(unix)]

mod common;
use common::resolve_test_path;
Expand Down
5 changes: 4 additions & 1 deletion crates/pet-core/src/python_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option<PathBuf> {

#[cfg(test)]
mod tests {
use super::*;
#[cfg(windows)]
use super::{get_shortest_executable, PythonEnvironmentKind};
#[cfg(windows)]
use std::path::PathBuf;

#[test]
#[cfg(windows)]
Expand Down
3 changes: 1 addition & 2 deletions crates/pet-homebrew/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ fn get_prefix(_resolved_file: &Path) -> Option<PathBuf> {
None
}

#[cfg(test)]
#[cfg(all(test, unix))]
mod tests {
use super::*;

#[test]
#[cfg(unix)]
fn extract_version() {
assert_eq!(
get_version(&PathBuf::from(
Expand Down
3 changes: 3 additions & 0 deletions crates/pet-poetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ regex = "1.10.4"
sha2 = "0.10.6"
base64 = "0.22.0"
toml = "0.8.14"

[features]
ci = []
30 changes: 16 additions & 14 deletions crates/pet-poetry/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ pub struct TestEnvironment {
home: Option<PathBuf>,
root: Option<PathBuf>,
}

impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
vec![]
}
}

#[allow(dead_code)]
pub fn create_test_environment(
vars: HashMap<String, String>,
home: Option<PathBuf>,
root: Option<PathBuf>,
) -> TestEnvironment {
impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
vec![]
}
}
TestEnvironment { vars, home, root }
}
1 change: 0 additions & 1 deletion crates/pet-poetry/tests/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn global_config_with_specific_values() {
#[cfg(unix)]
#[cfg_attr(any(feature = "ci",), test)]
#[allow(dead_code)]

fn local_config_with_specific_values() {
use std::path::PathBuf;

Expand Down
30 changes: 16 additions & 14 deletions crates/pet-pyenv/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,29 @@ pub struct TestEnvironment {
root: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
}

impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}

#[allow(dead_code)]
pub fn create_test_environment(
vars: HashMap<String, String>,
home: Option<PathBuf>,
globals_locations: Vec<PathBuf>,
root: Option<PathBuf>,
) -> TestEnvironment {
impl Environment for TestEnvironment {
fn get_env_var(&self, key: String) -> Option<String> {
self.vars.get(&key).cloned()
}
fn get_root(&self) -> Option<PathBuf> {
self.root.clone()
}
fn get_user_home(&self) -> Option<PathBuf> {
self.home.clone()
}
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
self.globals_locations.clone()
}
}
TestEnvironment {
vars,
home,
Expand Down
12 changes: 0 additions & 12 deletions crates/pet-pyenv/tests/pyenv_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.9.9/bin/python",
])]),
..Default::default()
};
let expected_virtual_env = PythonEnvironment {
display_name: None,
Expand All @@ -186,7 +185,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/my-virtual-env/bin/python",
])]),
..Default::default()
};
let expected_3_12_1 = PythonEnvironment {
display_name: None,
Expand All @@ -208,7 +206,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.12.1/bin/python",
])]),
..Default::default()
};
let expected_3_13_dev = PythonEnvironment {
display_name: None,
Expand All @@ -230,7 +227,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.13-dev/bin/python",
])]),
..Default::default()
};
let expected_3_12_1a3 = PythonEnvironment {
display_name: None,
Expand All @@ -252,7 +248,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/3.12.1a3/bin/python",
])]),
..Default::default()
};
let expected_no_gil = PythonEnvironment {
display_name: None,
Expand All @@ -274,7 +269,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/nogil-3.9.10-1/bin/python",
])]),
..Default::default()
};
let expected_pypy = PythonEnvironment {
display_name: None,
Expand All @@ -296,7 +290,6 @@ fn find_pyenv_envs() {
home.to_str().unwrap(),
".pyenv/versions/pypy3.9-7.3.15/bin/python",
])]),
..Default::default()
};

let expected_conda_root = PythonEnvironment {
Expand All @@ -310,7 +303,6 @@ fn find_pyenv_envs() {
manager: Some(expected_conda_manager.clone()),
arch: Some(Architecture::X64),
symlinks: Some(vec![conda_dir.join("bin").join("python")]),
..Default::default()
};
let expected_conda_one = PythonEnvironment {
display_name: None,
Expand All @@ -323,7 +315,6 @@ fn find_pyenv_envs() {
manager: Some(expected_conda_manager.clone()),
arch: None,
symlinks: Some(vec![conda_dir.join("envs").join("one").join("python")]),
..Default::default()
};
let expected_conda_two = PythonEnvironment {
display_name: None,
Expand All @@ -336,7 +327,6 @@ fn find_pyenv_envs() {
manager: Some(expected_conda_manager.clone()),
symlinks: Some(vec![conda_dir.join("envs").join("two").join("python")]),
arch: None,
..Default::default()
};

let mut expected_envs = vec![
Expand Down Expand Up @@ -406,7 +396,6 @@ fn resolve_pyenv_environment() {
manager: Some(expected_manager.clone()),
arch: None,
symlinks: Some(vec![executable]),
..Default::default()
};
let expected_virtual_env = PythonEnvironment {
display_name: None,
Expand All @@ -428,7 +417,6 @@ fn resolve_pyenv_environment() {
home.to_str().unwrap(),
".pyenv/versions/my-virtual-env/bin/python",
])]),
..Default::default()
};

// Resolve regular Python installs in Pyenv
Expand Down
1 change: 1 addition & 0 deletions crates/pet-python-utils/tests/executable_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#![cfg(unix)]

mod common;
use pet_python_utils::executable;
Expand Down
1 change: 1 addition & 0 deletions crates/pet-python-utils/tests/sys_prefix_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#![cfg(unix)]

mod common;
use pet_python_utils::version;
Expand Down
1 change: 1 addition & 0 deletions crates/pet/tests/ci_homebrew_container.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#![cfg(unix)]

use std::sync::Once;

Expand Down
1 change: 1 addition & 0 deletions crates/pet/tests/ci_jupyter_container.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#![cfg(unix)]

use std::sync::Once;

Expand Down
12 changes: 8 additions & 4 deletions crates/pet/tests/ci_poetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ fn verify_ci_poetry_global() {
let environment = EnvironmentApi::new();
let conda_locator = Arc::new(Conda::from(&environment));
let poetry_locator = Arc::new(Poetry::from(&environment));
let mut config = Configuration::default();
config.workspace_directories = Some(vec![workspace_dir.clone()]);
let config = Configuration {
workspace_directories: Some(vec![workspace_dir.clone()]),
..Default::default()
};
let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment);
for locator in locators.iter() {
locator.configure(&config);
Expand Down Expand Up @@ -110,8 +112,10 @@ fn verify_ci_poetry_project() {
let environment = EnvironmentApi::new();
let conda_locator = Arc::new(Conda::from(&environment));
let poetry_locator = Arc::new(Poetry::from(&environment));
let mut config = Configuration::default();
config.workspace_directories = Some(vec![workspace_dir.clone()]);
let config = Configuration {
workspace_directories: Some(vec![workspace_dir.clone()]),
..Default::default()
};
let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment);
for locator in locators.iter() {
locator.configure(&config);
Expand Down
Loading
Loading