Skip to content
Closed
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
2 changes: 1 addition & 1 deletion crates/pet-conda/tests/ci_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,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-core/src/python_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ pub fn get_environment_key(env: &PythonEnvironment) -> Option<PathBuf> {

#[cfg(test)]
mod tests {
#[cfg(windows)]
use super::*;

#[test]
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
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
40 changes: 19 additions & 21 deletions crates/pet/tests/ci_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ fn verify_validity_of_discovered_envs() {
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 @@ -288,12 +290,9 @@ fn verify_validity_of_interpreter_info(environment: PythonEnvironment) {
&& interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13")
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
&& interpreter_info.clone().sys_prefix == "/usr/local/python/current")
{
// known issue https://github.com/microsoft/python-environment-tools/issues/64
} else if interpreter_info.clone().executable
== "/home/codespace/.python/current/bin/python"
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
&& interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13")
|| interpreter_info.clone().executable == "/home/codespace/.python/current/bin/python"
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
&& interpreter_info.clone().sys_prefix == "/usr/local/python/3.10.13")
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
&& interpreter_info.clone().sys_prefix == "/home/codespace/.python/current")
{
Expand Down Expand Up @@ -492,13 +491,10 @@ fn compare_environments(actual: PythonEnvironment, expected: PythonEnvironment,
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13")))
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/current")))
{
// known issue https://github.com/microsoft/python-environment-tools/issues/64
actual.prefix = expected.clone().prefix;
} else if actual.clone().executable
== Some(PathBuf::from("/home/codespace/.python/current/bin/python"))
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13")))
|| actual.clone().executable
== Some(PathBuf::from("/home/codespace/.python/current/bin/python"))
&& (prefix.to_str().unwrap() == "/home/codespace/.python/current"
&& actual.clone().prefix == Some(PathBuf::from("/usr/local/python/3.10.13")))
|| (prefix.to_str().unwrap() == "/usr/local/python/3.10.13"
&& actual.clone().prefix == Some(PathBuf::from("/home/codespace/.python/current")))
{
Expand Down Expand Up @@ -591,8 +587,10 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe(
let os_environment = EnvironmentApi::new();
let conda_locator = Arc::new(Conda::from(&os_environment));
let poetry_locator = Arc::new(Poetry::from(&os_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(),
Expand Down Expand Up @@ -720,13 +718,13 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec<String> {
"python".to_string(),
]
} else if let Some(prefix) = env.prefix.clone() {
return vec![
vec![
conda_exe,
"run".to_string(),
"-p".to_string(),
prefix.to_str().unwrap_or_default().to_string(),
"python".to_string(),
];
]
} else {
panic!("Conda environment without name or prefix")
}
Expand All @@ -741,8 +739,8 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec<String> {
}
}

fn get_python_interpreter_info(cli: &Vec<String>) -> InterpreterInfo {
let mut cli = cli.clone();
fn get_python_interpreter_info(cli: &[String]) -> InterpreterInfo {
let mut cli = cli.to_owned();
cli.push(
resolve_test_path(&["interpreterInfo.py"])
.to_str()
Expand Down
6 changes: 3 additions & 3 deletions crates/pet/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub fn resolve_test_path(paths: &[&str]) -> PathBuf {
}

#[allow(dead_code)]
pub fn does_version_match(version: &String, expected_version: &String) -> bool {
pub fn does_version_match(version: &str, expected_version: &str) -> bool {
let version = get_version(version);
expected_version.starts_with(&version)
}

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 captures = PYTHON_VERSION.captures(value).unwrap();
let version = captures.get(1).unwrap().as_str().to_string();
Expand All @@ -39,6 +39,6 @@ fn get_version(value: &String) -> String {
}

#[allow(dead_code)]
pub fn is_valid_version(value: &String) -> bool {
pub fn is_valid_version(value: &str) -> bool {
PYTHON_FULLVERSION.is_match(value)
}
Loading