Skip to content

Commit eed0881

Browse files
refactor: lint
1 parent ab03568 commit eed0881

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

packages/treetime-utils/src/assert.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@ pub fn format_array(s: impl AsRef<str>) -> String {
4242
let re = regex::Regex::new(r", shape=.*").unwrap();
4343
re.replace(&format_newlines(s), "").into_owned()
4444
}
45+
46+
#[macro_export]
47+
macro_rules! assert_error {
48+
($result:expr, $expected_message:expr) => {{
49+
let error = $result.unwrap_err();
50+
let actual_message = $crate::error::report_to_string(&error);
51+
pretty_assertions::assert_eq!(actual_message, $expected_message);
52+
}};
53+
}

packages/treetime/src/commands/clock/clock_model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl ClockModel {
3535
let det = clock_set.determinant();
3636
if det <= 0.0 {
3737
debug!("ClockSet: {}", json_write_str(clock_set, JsonPretty(true))?);
38-
debug!("ClockSet determinant: {}", det);
38+
debug!("ClockSet determinant: {det}");
3939
return make_error!("No variation in sampling dates! Please specify your clock rate explicitly.");
4040
}
4141

packages/treetime/src/commands/timetree/inference/runner.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::commands::clock::clock_model::ClockModel;
22
use crate::commands::clock::clock_regression::{ClockOptions, estimate_clock_model_with_reroot};
3+
use crate::commands::clock::clock_set::ClockSet;
34
use crate::commands::clock::find_best_root::params::BranchPointOptimizationParams;
45
use crate::commands::optimize::optimize_unified::OptimizationContribution;
56
use crate::commands::timetree::inference::backward_pass::propagate_distributions_backward;
@@ -33,15 +34,15 @@ pub fn run_timetree(
3334
}
3435
}
3536
// Reset clock set to ensure clean state for each iteration
36-
node.clock_total = Default::default();
37+
node.clock_total = ClockSet::default();
3738
}
3839

3940
// Reset edge clock sets as well
4041
for edge_ref in graph.get_edges() {
4142
let mut edge = edge_ref.write_arc().payload().write_arc();
42-
edge.clock_to_parent = Default::default();
43-
edge.clock_to_child = Default::default();
44-
edge.clock_from_child = Default::default();
43+
edge.clock_to_parent = ClockSet::default();
44+
edge.clock_to_child = ClockSet::default();
45+
edge.clock_from_child = ClockSet::default();
4546
}
4647

4748
log::info!("## Estimating clock rate from root-to-tip regression");

packages/treetime/src/distribution/distribution_convolution.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,10 @@ mod tests {
412412
let uniform_x = array![0.0, 1.0, 2.0];
413413
let uniform = Distribution::function(uniform_x, y).unwrap();
414414

415-
let result = distribution_convolution(&non_uniform, &uniform);
416-
result.unwrap_err();
415+
assert_error!(
416+
distribution_convolution(&non_uniform, &uniform),
417+
"Function distributions must use uniform grids for convolution"
418+
);
417419
}
418420

419421
#[test]

packages/treetime/src/distribution/distribution_division.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ mod tests {
101101
use super::*;
102102
use approx::assert_ulps_eq;
103103
use ndarray::array;
104+
use treetime_utils::assert_error;
104105

105106
#[test]
106107
fn test_divide_empty_by_any() {
@@ -114,8 +115,10 @@ mod tests {
114115
fn test_divide_by_empty_fails() {
115116
let point = Distribution::point(1.0, 2.0);
116117
let empty = Distribution::empty();
117-
let result = distribution_division(&point, &empty);
118-
result.unwrap_err();
118+
assert_error!(
119+
distribution_division(&point, &empty),
120+
"Cannot divide by empty distribution"
121+
);
119122
}
120123

121124
#[test]

0 commit comments

Comments
 (0)