Skip to content

Commit 232fa5e

Browse files
committed
fix: return inaccuracy info from comparison function, improve test assertions, pin tempfile version
1 parent 42df4c5 commit 232fa5e

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

crates/pet-telemetry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ lazy_static = "1.4.0"
1717
regex = "1.10.4"
1818

1919
[dev-dependencies]
20-
tempfile = "3"
20+
tempfile = "3.10"

crates/pet-telemetry/src/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn report_inaccuracies_identified_after_resolving(
2121
_reporter: &dyn Reporter,
2222
env: &PythonEnvironment,
2323
resolved: &PythonEnvironment,
24-
) -> Option<()> {
24+
) -> Option<InaccuratePythonEnvironmentInfo> {
2525
let known_symlinks = env.symlinks.clone().unwrap_or_default();
2626
let resolved_executable = &resolved.executable.clone()?;
2727
let norm_cased_executable = norm_case(resolved_executable);
@@ -84,8 +84,9 @@ pub fn report_inaccuracies_identified_after_resolving(
8484
env, resolved, event
8585
);
8686
// reporter.report_telemetry(TelemetryEvent::InaccuratePythonEnvironmentInfo(event));
87+
return Some(event);
8788
}
88-
Option::Some(())
89+
None
8990
}
9091

9192
fn are_versions_different(actual: &str, expected: &str) -> Option<bool> {
@@ -136,9 +137,8 @@ mod tests {
136137
let env = make_env(exe.clone(), prefix.clone(), "3.12.7", vec![exe.clone()]);
137138
let resolved = make_env(exe.clone(), prefix, "3.12.7", vec![exe]);
138139

139-
// Should not warn — prefixes are identical
140140
let result = report_inaccuracies_identified_after_resolving(&NoopReporter, &env, &resolved);
141-
assert!(result.is_some());
141+
assert!(result.is_none(), "identical prefixes should not be flagged");
142142
}
143143

144144
#[cfg(unix)]
@@ -157,9 +157,11 @@ mod tests {
157157
// Resolution (spawning Python) returns the canonical path
158158
let resolved = make_env(exe.clone(), real_prefix, "3.12.7", vec![exe]);
159159

160-
// Should NOT warn — both paths resolve to the same directory
161160
let result = report_inaccuracies_identified_after_resolving(&NoopReporter, &env, &resolved);
162-
assert!(result.is_some());
161+
assert!(
162+
result.is_none(),
163+
"symlinked prefix to the same directory should not be flagged"
164+
);
163165
}
164166

165167
#[test]
@@ -175,10 +177,9 @@ mod tests {
175177
let env = make_env(exe.clone(), prefix_a, "3.12.7", vec![exe.clone()]);
176178
let resolved = make_env(exe.clone(), prefix_b, "3.12.7", vec![exe]);
177179

178-
// Should warn — prefixes are genuinely different
179-
// The function still returns Some(()), but the warn! macro fires internally.
180180
let result = report_inaccuracies_identified_after_resolving(&NoopReporter, &env, &resolved);
181-
assert!(result.is_some());
181+
let event = result.expect("genuinely different prefixes should be flagged");
182+
assert_eq!(event.invalid_prefix, Some(true));
182183
}
183184

184185
#[test]
@@ -196,6 +197,9 @@ mod tests {
196197
let resolved = make_env(exe.clone(), prefix, "3.12.7", vec![exe]);
197198

198199
let result = report_inaccuracies_identified_after_resolving(&NoopReporter, &env, &resolved);
199-
assert!(result.is_some());
200+
assert!(
201+
result.is_none(),
202+
"None prefix should not cause any inaccuracy flag"
203+
);
200204
}
201205
}

0 commit comments

Comments
 (0)