From d3244073deeca04cf80ffbc752464e9993e7844b Mon Sep 17 00:00:00 2001 From: Christopher Regali Date: Tue, 25 Jul 2023 12:26:02 +0200 Subject: [PATCH] Fix unit-tests for new api --- src/html.rs | 2 -- src/image.rs | 30 +++++++++++++++--------------- src/properties.rs | 5 +++-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/html.rs b/src/html.rs index 5209edb..9666a69 100644 --- a/src/html.rs +++ b/src/html.rs @@ -116,8 +116,6 @@ mod test { let result = compare_files(actual, nominal, &HTMLCompareConfig::default()).unwrap(); assert!(result.is_error); - - assert!(result.detail_path.is_some()); } #[test] diff --git a/src/image.rs b/src/image.rs index 929f7ad..b8c9fd8 100644 --- a/src/image.rs +++ b/src/image.rs @@ -78,6 +78,7 @@ pub fn compare_paths>( #[cfg(test)] mod test { use crate::image::{compare_paths, ImageCompareConfig}; + use crate::report::DiffDetail; #[test] fn identity() { @@ -99,21 +100,20 @@ mod test { ) .unwrap(); assert!(result.is_error); - assert!(result.detail_path.is_some()); - let img = image::open( - result - .detail_path + if let DiffDetail::Image { + score: _, + diff_image, + } = result.detail.first().unwrap() + { + let img = image::open(diff_image).unwrap().into_rgb8(); + let nom = image::open("tests/integ/data/images/diff_100_DPI.png") .unwrap() - .temp_path - .join("SaveImage_100DPI_default_size.jpgdiff_image.png"), - ) - .expect("Could not load generated diff image") - .into_rgb8(); - let nom = image::open("tests/integ/data/images/diff_100_DPI.png") - .unwrap() - .into_rgb8(); - let diff_result = image_compare::rgb_hybrid_compare(&img, &nom) - .expect("Wrong dimensions of diff images!"); - assert_eq!(diff_result.score, 1.0); + .into_rgb8(); + let diff_result = image_compare::rgb_hybrid_compare(&img, &nom) + .expect("Wrong dimensions of diff images!"); + assert_eq!(diff_result.score, 1.0); + } else { + unreachable!(); + } } } diff --git a/src/properties.rs b/src/properties.rs index 870b22f..94817d5 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -175,13 +175,14 @@ mod tests { let regex_no_spaces = r"[\s]"; assert!( regex_matches_any_path(file_name_mock, file_name_cap_mock, regex_no_capitals) + .unwrap() .unwrap() .is_error ); assert!( - !regex_matches_any_path(file_name_mock, file_name_cap_mock, regex_no_spaces) + regex_matches_any_path(file_name_mock, file_name_cap_mock, regex_no_spaces) .unwrap() - .is_error + .is_none() ); }