Skip to content

Commit 5094581

Browse files
Copilotkarthiknadig
andcommitted
Fix repetitive clippy patterns: needless struct updates, useless conversions, assert_eq with bool
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
1 parent 5a5d71c commit 5094581

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

crates/pet-poetry/src/config.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ create = false
242242
"#;
243243

244244
assert_eq!(
245-
parse_contents(&cfg.to_string())
245+
parse_contents(cfg)
246246
.unwrap()
247247
.virtualenvs_in_project
248248
.unwrap_or_default(),
@@ -256,7 +256,7 @@ create = false
256256
257257
"#;
258258
assert_eq!(
259-
parse_contents(&cfg.to_string())
259+
parse_contents(cfg)
260260
.unwrap()
261261
.virtualenvs_in_project
262262
.unwrap_or_default(),
@@ -269,7 +269,7 @@ create = false
269269
270270
"#;
271271
assert_eq!(
272-
parse_contents(&cfg.to_string())
272+
parse_contents(cfg)
273273
.unwrap()
274274
.virtualenvs_in_project
275275
.unwrap_or_default(),
@@ -279,22 +279,20 @@ create = false
279279
let cfg = r#"
280280
virtualenvs.in-project = true # comment
281281
"#;
282-
assert_eq!(
283-
parse_contents(&cfg.to_string())
282+
assert!(
283+
parse_contents(&cfg)
284284
.unwrap()
285285
.virtualenvs_in_project
286-
.unwrap_or_default(),
287-
true
286+
.unwrap_or_default()
288287
);
289288

290289
let cfg = r#"
291290
"#;
292-
assert_eq!(
293-
parse_contents(&cfg.to_string())
291+
assert!(
292+
!parse_contents(&cfg)
294293
.unwrap()
295294
.virtualenvs_in_project
296-
.unwrap_or_default(),
297-
false
295+
.unwrap_or_default()
298296
);
299297
}
300298

@@ -305,15 +303,15 @@ cache-dir = "/path/to/cache/directory"
305303
306304
"#;
307305
assert_eq!(
308-
parse_contents(&cfg.to_string()).unwrap().cache_dir,
306+
parse_contents(cfg).unwrap().cache_dir,
309307
Some(PathBuf::from("/path/to/cache/directory".to_string()))
310308
);
311309

312310
let cfg = r#"
313311
some-other-value = 1234
314312
315313
"#;
316-
assert_eq!(parse_contents(&cfg.to_string()).unwrap().cache_dir, None);
314+
assert_eq!(parse_contents(cfg).unwrap().cache_dir, None);
317315
}
318316

319317
#[test]
@@ -323,7 +321,7 @@ virtualenvs.path = "/path/to/virtualenvs"
323321
324322
"#;
325323
assert_eq!(
326-
parse_contents(&cfg.to_string()).unwrap().virtualenvs_path,
324+
parse_contents(cfg).unwrap().virtualenvs_path,
327325
Some(PathBuf::from("/path/to/virtualenvs".to_string()))
328326
);
329327

@@ -332,7 +330,7 @@ some-other-value = 1234
332330
333331
"#;
334332
assert_eq!(
335-
parse_contents(&cfg.to_string()).unwrap().virtualenvs_path,
333+
parse_contents(cfg).unwrap().virtualenvs_path,
336334
None
337335
);
338336
}
@@ -343,7 +341,7 @@ some-other-value = 1234
343341
cache-dir = "/path/to/cache/directory"
344342
"#;
345343
assert_eq!(
346-
parse_contents(&cfg.to_string()).unwrap().virtualenvs_path,
344+
parse_contents(cfg).unwrap().virtualenvs_path,
347345
Some(PathBuf::from("/path/to/cache/directory/virtualenvs"))
348346
);
349347
}

crates/pet-poetry/src/pyproject_toml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ requires = ["poetry-core"]
9090
build-backend = "poetry.core.masonry.api"
9191
"#;
9292
assert_eq!(
93-
parse_contents(&cfg.to_string(), Path::new("pyproject.toml"))
93+
parse_contents(cfg, Path::new("pyproject.toml"))
9494
.unwrap()
9595
.name,
9696
"poetry-demo"

crates/pet-pyenv/tests/common.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,29 @@ pub struct TestEnvironment {
3434
root: Option<PathBuf>,
3535
globals_locations: Vec<PathBuf>,
3636
}
37+
38+
impl Environment for TestEnvironment {
39+
fn get_env_var(&self, key: String) -> Option<String> {
40+
self.vars.get(&key).cloned()
41+
}
42+
fn get_root(&self) -> Option<PathBuf> {
43+
self.root.clone()
44+
}
45+
fn get_user_home(&self) -> Option<PathBuf> {
46+
self.home.clone()
47+
}
48+
fn get_know_global_search_locations(&self) -> Vec<PathBuf> {
49+
self.globals_locations.clone()
50+
}
51+
}
52+
3753
#[allow(dead_code)]
3854
pub fn create_test_environment(
3955
vars: HashMap<String, String>,
4056
home: Option<PathBuf>,
4157
globals_locations: Vec<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-
self.globals_locations.clone()
56-
}
57-
}
5860
TestEnvironment {
5961
vars,
6062
home,

crates/pet-pyenv/tests/pyenv_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ fn does_not_find_any_pyenv_envs() {
2929
let environments = reporter.environments.lock().unwrap().clone();
3030
let managers = reporter.managers.lock().unwrap().clone();
3131

32-
assert_eq!(managers.is_empty(), true);
33-
assert_eq!(environments.is_empty(), true);
32+
assert!(managers.is_empty());
33+
assert!(environments.is_empty());
3434
}
3535

3636
#[test]
@@ -63,7 +63,7 @@ fn does_not_find_any_pyenv_envs_even_with_pyenv_installed() {
6363
let environment = create_test_environment(
6464
HashMap::new(),
6565
Some(home.clone()),
66-
vec![PathBuf::from(homebrew_bin)],
66+
vec![homebrew_bin],
6767
None,
6868
);
6969

@@ -119,7 +119,7 @@ fn find_pyenv_envs() {
119119
let environment = create_test_environment(
120120
HashMap::new(),
121121
Some(home.clone()),
122-
vec![PathBuf::from(homebrew_bin)],
122+
vec![homebrew_bin],
123123
None,
124124
);
125125

0 commit comments

Comments
 (0)