Skip to content

Commit 5a5d71c

Browse files
Copilotkarthiknadig
andcommitted
Fix more clippy warnings: field assignments, expect_fun_call, ptr_arg, and cfg conditions
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
1 parent eada485 commit 5a5d71c

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed

crates/pet-poetry/tests/common.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,27 @@ pub struct TestEnvironment {
3535
home: Option<PathBuf>,
3636
root: Option<PathBuf>,
3737
}
38+
39+
impl Environment for TestEnvironment {
40+
fn get_env_var(&self, key: String) -> Option<String> {
41+
self.vars.get(&key).cloned()
42+
}
43+
fn get_root(&self) -> Option<PathBuf> {
44+
self.root.clone()
45+
}
46+
fn get_user_home(&self) -> Option<PathBuf> {
47+
self.home.clone()
48+
}
49+
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
50+
vec![]
51+
}
52+
}
53+
3854
#[allow(dead_code)]
3955
pub fn create_test_environment(
4056
vars: HashMap<String, String>,
4157
home: Option<PathBuf>,
4258
root: Option<PathBuf>,
4359
) -> TestEnvironment {
44-
impl Environment for TestEnvironment {
45-
fn get_env_var(&self, key: String) -> Option<String> {
46-
self.vars.get(&key).cloned()
47-
}
48-
fn get_root(&self) -> Option<PathBuf> {
49-
self.root.clone()
50-
}
51-
fn get_user_home(&self) -> Option<PathBuf> {
52-
self.home.clone()
53-
}
54-
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
55-
vec![]
56-
}
57-
}
5860
TestEnvironment { vars, home, root }
5961
}

crates/pet-poetry/tests/config_test.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
mod common;
55

66
#[cfg(unix)]
7-
#[cfg_attr(any(feature = "ci",), test)]
7+
#[test]
88
#[allow(dead_code)]
99
fn global_config_with_defaults() {
1010
use common::create_env_variables;
@@ -37,7 +37,7 @@ fn global_config_with_defaults() {
3737
}
3838

3939
#[cfg(unix)]
40-
#[cfg_attr(any(feature = "ci",), test)]
40+
#[test]
4141
#[allow(dead_code)]
4242
fn global_config_with_specific_values() {
4343
use std::path::PathBuf;
@@ -69,13 +69,12 @@ fn global_config_with_specific_values() {
6969
"config.toml"
7070
]))
7171
);
72-
assert_eq!(
72+
assert!(
7373
config
7474
.clone()
7575
.unwrap()
7676
.virtualenvs_in_project
77-
.unwrap_or_default(),
78-
true
77+
.unwrap_or_default()
7978
);
8079
assert_eq!(
8180
config.clone().unwrap().virtualenvs_path,
@@ -84,9 +83,8 @@ fn global_config_with_specific_values() {
8483
}
8584

8685
#[cfg(unix)]
87-
#[cfg_attr(any(feature = "ci",), test)]
86+
#[test]
8887
#[allow(dead_code)]
89-
9088
fn local_config_with_specific_values() {
9189
use std::path::PathBuf;
9290

@@ -117,13 +115,12 @@ fn local_config_with_specific_values() {
117115
"poetry.toml"
118116
]))
119117
);
120-
assert_eq!(
121-
config
118+
assert!(
119+
!config
122120
.clone()
123121
.unwrap()
124122
.virtualenvs_in_project
125-
.unwrap_or_default(),
126-
false
123+
.unwrap_or_default()
127124
);
128125
assert_eq!(
129126
config.clone().unwrap().virtualenvs_path,

crates/pet/tests/ci_test.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn verify_validity_of_discovered_envs() {
6666
use pet::{find::find_and_report_envs, locators::create_locators};
6767
use pet_conda::Conda;
6868
use pet_core::{os_environment::EnvironmentApi, Configuration};
69-
use std::{env, sync::Arc, thread};
69+
use std::{env, sync::Arc};
7070

7171
setup();
7272

@@ -75,8 +75,10 @@ fn verify_validity_of_discovered_envs() {
7575
let environment = EnvironmentApi::new();
7676
let conda_locator = Arc::new(Conda::from(&environment));
7777
let poetry_locator = Arc::new(Poetry::from(&environment));
78-
let mut config = Configuration::default();
79-
config.workspace_directories = Some(vec![workspace_dir.clone()]);
78+
let config = Configuration {
79+
workspace_directories: Some(vec![workspace_dir.clone()]),
80+
..Default::default()
81+
};
8082
let locators = create_locators(conda_locator.clone(), poetry_locator.clone(), &environment);
8183
for locator in locators.iter() {
8284
locator.configure(&config);
@@ -205,7 +207,7 @@ fn check_if_pipenv_exists() {
205207
env.kind == Some(PythonEnvironmentKind::Pipenv)
206208
&& env.project == Some(workspace_dir.clone())
207209
})
208-
.expect(format!("Pipenv environment not found, found {environments:?}").as_str());
210+
.unwrap_or_else(|| panic!("Pipenv environment not found, found {environments:?}"));
209211
}
210212

211213
#[cfg(unix)]
@@ -367,10 +369,7 @@ fn verify_we_can_get_same_env_info_using_from_with_exe(
367369
let env = PythonEnv::new(executable.clone(), None, None);
368370
let resolved =
369371
identify_python_environment_using_locators(&env, &locators, &global_env_search_paths)
370-
.expect(
371-
format!("Failed to resolve environment using `resolve` for {environment:?}")
372-
.as_str(),
373-
);
372+
.unwrap_or_else(|| panic!("Failed to resolve environment using `resolve` for {environment:?}"));
374373
trace!(
375374
"For exe {:?} we got Environment = {:?}, To compare against {:?}",
376375
executable,
@@ -603,8 +602,10 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe(
603602
let os_environment = EnvironmentApi::new();
604603
let conda_locator = Arc::new(Conda::from(&os_environment));
605604
let poetry_locator = Arc::new(Poetry::from(&os_environment));
606-
let mut config = Configuration::default();
607-
config.workspace_directories = Some(vec![workspace_dir.clone()]);
605+
let config = Configuration {
606+
workspace_directories: Some(vec![workspace_dir.clone()]),
607+
..Default::default()
608+
};
608609
let locators = create_locators(
609610
conda_locator.clone(),
610611
poetry_locator.clone(),
@@ -614,9 +615,8 @@ fn verify_we_can_get_same_env_info_using_resolve_with_exe(
614615
locator.configure(&config);
615616
}
616617

617-
let env = resolve_environment(&executable, &locators, &os_environment).expect(
618-
format!("Failed to resolve environment using `resolve` for {environment:?}").as_str(),
619-
);
618+
let env = resolve_environment(executable, &locators, &os_environment)
619+
.unwrap_or_else(|| panic!("Failed to resolve environment using `resolve` for {environment:?}"));
620620
trace!(
621621
"For exe {:?} we got Environment = {:?}, To compare against {:?}",
622622
executable,
@@ -724,21 +724,21 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec<String> {
724724
None => get_conda_exe().to_string(),
725725
};
726726
if let Some(name) = env.name.clone() {
727-
return vec![
727+
vec![
728728
conda_exe,
729729
"run".to_string(),
730730
"-n".to_string(),
731731
name,
732732
"python".to_string(),
733-
];
733+
]
734734
} else if let Some(prefix) = env.prefix.clone() {
735-
return vec![
735+
vec![
736736
conda_exe,
737737
"run".to_string(),
738738
"-p".to_string(),
739739
prefix.to_str().unwrap_or_default().to_string(),
740740
"python".to_string(),
741-
];
741+
]
742742
} else {
743743
panic!("Conda environment without name or prefix")
744744
}
@@ -753,8 +753,8 @@ fn get_python_run_command(env: &PythonEnvironment) -> Vec<String> {
753753
}
754754
}
755755

756-
fn get_python_interpreter_info(cli: &Vec<String>) -> InterpreterInfo {
757-
let mut cli = cli.clone();
756+
fn get_python_interpreter_info(cli: &[String]) -> InterpreterInfo {
757+
let mut cli = cli.to_owned();
758758
cli.push(
759759
resolve_test_path(&["interpreterInfo.py"])
760760
.to_str()
@@ -765,13 +765,13 @@ fn get_python_interpreter_info(cli: &Vec<String>) -> InterpreterInfo {
765765
let output = std::process::Command::new(cli.first().unwrap())
766766
.args(&cli[1..])
767767
.output()
768-
.expect(format!("Failed to execute command {cli:?}").as_str());
768+
.unwrap_or_else(|_| panic!("Failed to execute command {cli:?}"));
769769
let output = String::from_utf8(output.stdout).unwrap();
770770
trace!("Get Interpreter Info: {:?} => {:?}", cli, output);
771771
let output = output
772772
.split_once("503bebe7-c838-4cea-a1bc-0f2963bcb657")
773773
.unwrap()
774774
.1;
775-
let info: InterpreterInfo = serde_json::from_str(&output).unwrap();
775+
let info: InterpreterInfo = serde_json::from_str(output).unwrap();
776776
info
777777
}

0 commit comments

Comments
 (0)