Skip to content

Commit 5770a5a

Browse files
Copilotkarthiknadig
andcommitted
Complete clippy fixes: resolve remaining identical if blocks and ptr_arg issues
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
1 parent 5094581 commit 5770a5a

File tree

12 files changed

+94
-149
lines changed

12 files changed

+94
-149
lines changed

crates/pet-conda/src/conda_rc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ envs_path:
353353
"#;
354354

355355
assert_eq!(
356-
parse_conda_rc_contents(&cfg).unwrap().env_dirs,
356+
parse_conda_rc_contents(cfg).unwrap().env_dirs,
357357
[
358358
PathBuf::from("/Users/username/dev/envs"),
359359
PathBuf::from("/opt/conda/envs"),
@@ -373,7 +373,7 @@ envs_dirs:
373373
"#;
374374

375375
assert_eq!(
376-
parse_conda_rc_contents(&cfg).unwrap().env_dirs,
376+
parse_conda_rc_contents(cfg).unwrap().env_dirs,
377377
["/Users/username/dev/envs", "/opt/conda/envs",].map(PathBuf::from)
378378
);
379379

@@ -388,7 +388,7 @@ envs_path:
388388
"#;
389389

390390
assert_eq!(
391-
parse_conda_rc_contents(&cfg).unwrap().env_dirs,
391+
parse_conda_rc_contents(cfg).unwrap().env_dirs,
392392
[
393393
PathBuf::from("/opt/somep lace/envs"),
394394
expand_path(PathBuf::from("~/dev/envs2"))
@@ -402,7 +402,7 @@ channels:
402402
channel_priority: strict
403403
"#;
404404

405-
assert!(parse_conda_rc_contents(&cfg).unwrap().env_dirs.is_empty(),);
406-
assert!(parse_conda_rc_contents(&cfg).unwrap().files.is_empty(),);
405+
assert!(parse_conda_rc_contents(cfg).unwrap().env_dirs.is_empty(),);
406+
assert!(parse_conda_rc_contents(cfg).unwrap().files.is_empty(),);
407407
}
408408
}

crates/pet-conda/tests/ci_test.rs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn detect_conda_root_from_path() {
8484
let python_env = PythonEnv::new(exe, Some(conda_dir.clone()), None);
8585
let env = conda.try_from(&python_env).unwrap();
8686

87-
assert_eq!(env.manager.is_some(), true);
87+
assert!(env.manager.is_some());
8888

8989
let manager = env.manager.unwrap();
9090
assert_eq!(manager.executable, conda_dir.join("bin").join("conda"));
@@ -132,13 +132,8 @@ fn detect_new_conda_env() {
132132
let env = environments
133133
.iter()
134134
.find(|x| x.name == Some(env_name.into()))
135-
.expect(
136-
format!(
137-
"New Environment not created, detected envs {:?}",
138-
environments
139-
)
140-
.as_str(),
141-
);
135+
.unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}",
136+
environments));
142137

143138
let prefix = conda_dir.clone().join("envs").join(env_name);
144139
assert_eq!(env.prefix, prefix.clone().into());
@@ -182,7 +177,7 @@ fn detect_conda_env_from_path() {
182177
let python_env = PythonEnv::new(exe.clone(), Some(prefix.clone()), None);
183178
let env = conda.try_from(&python_env).unwrap();
184179

185-
assert_eq!(env.manager.is_some(), true);
180+
assert!(env.manager.is_some());
186181

187182
let manager = env.manager.unwrap();
188183
assert_eq!(manager.executable, conda_dir.join("bin").join("conda"));
@@ -231,20 +226,15 @@ fn detect_new_conda_env_without_python() {
231226
let env = environments
232227
.iter()
233228
.find(|x| x.name == Some(env_name.into()))
234-
.expect(
235-
format!(
236-
"New Environment not created, detected envs {:?}",
237-
environments
238-
)
239-
.as_str(),
240-
);
229+
.unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}",
230+
environments));
241231

242232
let prefix = conda_dir.clone().join("envs").join(env_name);
243233
assert_eq!(env.prefix, prefix.clone().into());
244234
assert_eq!(env.name, Some(env_name.into()));
245235
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
246-
assert_eq!(env.executable.is_none(), true);
247-
assert_eq!(env.version.is_none(), true);
236+
assert!(env.executable.is_none());
237+
assert!(env.version.is_none());
248238

249239
assert_eq!(env.manager, Some(manager.clone()));
250240
}
@@ -281,19 +271,14 @@ fn detect_new_conda_env_created_with_p_flag_without_python() {
281271
let env = environments
282272
.iter()
283273
.find(|x| x.prefix == Some(prefix.clone()))
284-
.expect(
285-
format!(
286-
"New Environment ({:?}) not created, detected envs {:?}",
287-
prefix, environments
288-
)
289-
.as_str(),
290-
);
274+
.unwrap_or_else(|| panic!("New Environment ({:?}) not created, detected envs {:?}",
275+
prefix, environments));
291276

292277
assert_eq!(env.prefix, prefix.clone().into());
293278
assert_eq!(env.name, None);
294279
assert_eq!(env.kind, Some(PythonEnvironmentKind::Conda));
295-
assert_eq!(env.executable.is_none(), true);
296-
assert_eq!(env.version.is_none(), true);
280+
assert!(env.executable.is_none());
281+
assert!(env.version.is_none());
297282

298283
assert_eq!(env.manager, Some(manager.clone()));
299284
}
@@ -334,13 +319,8 @@ fn detect_new_conda_env_created_with_p_flag_with_python() {
334319
let env = environments
335320
.iter()
336321
.find(|x| x.prefix == Some(prefix.clone()))
337-
.expect(
338-
format!(
339-
"New Environment not created, detected envs {:?}",
340-
environments
341-
)
342-
.as_str(),
343-
);
322+
.unwrap_or_else(|| panic!("New Environment not created, detected envs {:?}",
323+
environments));
344324

345325
assert_eq!(env.prefix, prefix.clone().into());
346326
assert_eq!(env.name, None);
@@ -409,7 +389,7 @@ fn create_conda_env(mode: &CondaCreateEnvNameOrPath, python_version: Option<Stri
409389
.expect("Failed to execute command");
410390
}
411391

412-
fn get_version(value: &String) -> String {
392+
fn get_version(value: &str) -> String {
413393
// Regex to extract just the d.d.d version from the full version string
414394
let re = regex::Regex::new(r"\d+\.\d+\.\d+").unwrap();
415395
let captures = re.captures(value).unwrap();

crates/pet-conda/tests/environment_locations_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ fn non_existent_envrionments_txt() {
99
use common::{create_env_variables, resolve_test_path};
1010
use pet_conda::environment_locations::get_conda_envs_from_environment_txt;
1111

12-
let root = resolve_test_path(&["unix", "root_empty"]).into();
13-
let home = resolve_test_path(&["unix", "bogus directory"]).into();
12+
let root = resolve_test_path(&["unix", "root_empty"]);
13+
let home = resolve_test_path(&["unix", "bogus directory"]);
1414
let env = create_env_variables(home, root);
1515

1616
let environments = get_conda_envs_from_environment_txt(&env);

crates/pet-conda/tests/lib_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn find_conda_env_without_manager() {
2020

2121
let env = locator
2222
.try_from(&PythonEnv::new(
23-
path.join("bin").join("python").into(),
24-
Some(path.clone().into()),
23+
path.join("bin").join("python"),
24+
Some(path.clone()),
2525
None,
2626
))
2727
.unwrap();
@@ -71,8 +71,8 @@ fn find_conda_env_without_manager_but_detect_manager_from_history() {
7171

7272
let env = locator
7373
.try_from(&PythonEnv::new(
74-
path.join("bin").join("python").into(),
75-
Some(path.clone().into()),
74+
path.join("bin").join("python"),
75+
Some(path.clone()),
7676
None,
7777
))
7878
.unwrap();

crates/pet-conda/tests/manager_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ fn does_not_find_conda_env_for_bogus_dirs() {
4848

4949
let path = resolve_test_path(&["unix", "bogus_directory"]);
5050

51-
assert_eq!(CondaManager::from(&path).is_none(), true);
51+
assert!(CondaManager::from(&path).is_none());
5252
}

crates/pet-conda/tests/package_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use common::resolve_test_path;
1010
#[cfg(unix)]
1111
#[test]
1212
fn empty_result_for_bogus_paths() {
13-
let path: PathBuf = resolve_test_path(&["unix", "bogus_path"]).into();
13+
let path: PathBuf = resolve_test_path(&["unix", "bogus_path"]);
1414
let pkg = CondaPackageInfo::from(&path, &package::Package::Conda);
1515

1616
assert!(pkg.is_none());
@@ -19,7 +19,7 @@ fn empty_result_for_bogus_paths() {
1919
#[cfg(unix)]
2020
#[test]
2121
fn get_conda_package_info() {
22-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into();
22+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]);
2323
let pkg = CondaPackageInfo::from(&path, &package::Package::Conda).unwrap();
2424

2525
assert_eq!(pkg.package, package::Package::Conda);
@@ -38,7 +38,7 @@ fn get_conda_package_info() {
3838
#[cfg(unix)]
3939
#[test]
4040
fn get_python_package_info() {
41-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into();
41+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]);
4242
let pkg = CondaPackageInfo::from(&path, &package::Package::Python).unwrap();
4343

4444
assert_eq!(pkg.package, package::Package::Python);
@@ -57,7 +57,7 @@ fn get_python_package_info() {
5757
#[cfg(unix)]
5858
#[test]
5959
fn get_conda_package_info_without_history() {
60-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into();
60+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]);
6161
let pkg = CondaPackageInfo::from(&path, &package::Package::Conda).unwrap();
6262

6363
assert_eq!(pkg.package, package::Package::Conda);
@@ -76,7 +76,7 @@ fn get_conda_package_info_without_history() {
7676
#[cfg(unix)]
7777
#[test]
7878
fn get_python_package_info_without_history() {
79-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into();
79+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]);
8080
let pkg = CondaPackageInfo::from(&path, &package::Package::Python).unwrap();
8181

8282
assert_eq!(pkg.package, package::Package::Python);

crates/pet-conda/tests/utils_test.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,48 @@ use std::path::PathBuf;
99
#[cfg(unix)]
1010
#[test]
1111
fn is_conda_install() {
12-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into();
12+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]);
1313
assert!(utils::is_conda_install(&path));
1414

15-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into();
15+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]);
1616
assert!(utils::is_conda_install(&path));
1717
}
1818

1919
#[cfg(unix)]
2020
#[test]
2121
fn is_not_conda_install() {
22-
let path: PathBuf = resolve_test_path(&["unix", "some bogus directory"]).into();
23-
assert_eq!(utils::is_conda_install(&path), false);
22+
let path: PathBuf = resolve_test_path(&["unix", "some bogus directory"]);
23+
assert!(!utils::is_conda_install(&path));
2424

2525
// Conda env is not an install location.
2626
let path: PathBuf =
27-
resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]).into();
28-
assert_eq!(utils::is_conda_install(&path), false);
27+
resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]);
28+
assert!(!utils::is_conda_install(&path));
2929
}
3030

3131
#[cfg(unix)]
3232
#[test]
3333
fn is_conda_env() {
34-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into();
34+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]);
3535
assert!(utils::is_conda_env(&path));
3636

37-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into();
37+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]);
3838
assert!(utils::is_conda_env(&path));
3939

4040
let path: PathBuf =
41-
resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]).into();
41+
resolve_test_path(&["unix", "anaconda3-2023.03", "envs", "env_python_3"]);
4242
assert!(utils::is_conda_env(&path));
4343
}
4444

4545
#[cfg(unix)]
4646
#[test]
4747
fn is_not_conda_env() {
48-
let path: PathBuf = resolve_test_path(&["unix", "some bogus directory"]).into();
49-
assert_eq!(utils::is_conda_env(&path), false);
48+
let path: PathBuf = resolve_test_path(&["unix", "some bogus directory"]);
49+
assert!(!utils::is_conda_env(&path));
5050

51-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]).into();
51+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03"]);
5252
assert!(utils::is_conda_env(&path));
5353

54-
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]).into();
54+
let path: PathBuf = resolve_test_path(&["unix", "anaconda3-2023.03-without-history"]);
5555
assert!(utils::is_conda_env(&path));
5656
}

crates/pet-poetry/src/config.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,11 @@ create = false
241241
242242
"#;
243243

244-
assert_eq!(
245-
parse_contents(cfg)
244+
assert!(
245+
!parse_contents(cfg)
246246
.unwrap()
247247
.virtualenvs_in_project
248-
.unwrap_or_default(),
249-
false
248+
.unwrap_or_default()
250249
);
251250

252251
let cfg = r#"
@@ -255,32 +254,30 @@ in-project = true
255254
create = false
256255
257256
"#;
258-
assert_eq!(
257+
assert!(
259258
parse_contents(cfg)
260259
.unwrap()
261260
.virtualenvs_in_project
262-
.unwrap_or_default(),
263-
true
261+
.unwrap_or_default()
264262
);
265263

266264
let cfg = r#"
267265
[virtualenvs]
268266
create = false
269267
270268
"#;
271-
assert_eq!(
272-
parse_contents(cfg)
269+
assert!(
270+
!parse_contents(cfg)
273271
.unwrap()
274272
.virtualenvs_in_project
275-
.unwrap_or_default(),
276-
false
273+
.unwrap_or_default()
277274
);
278275

279276
let cfg = r#"
280277
virtualenvs.in-project = true # comment
281278
"#;
282279
assert!(
283-
parse_contents(&cfg)
280+
parse_contents(cfg)
284281
.unwrap()
285282
.virtualenvs_in_project
286283
.unwrap_or_default()
@@ -289,7 +286,7 @@ virtualenvs.in-project = true # comment
289286
let cfg = r#"
290287
"#;
291288
assert!(
292-
!parse_contents(&cfg)
289+
!parse_contents(cfg)
293290
.unwrap()
294291
.virtualenvs_in_project
295292
.unwrap_or_default()

0 commit comments

Comments
 (0)