Adjust when we write .diff and .new snapshot images (#7571)
This commit is contained in:
parent
a450b1c989
commit
4fb4072ce8
|
|
@ -397,13 +397,6 @@ fn try_image_snapshot_options_impl(
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Always write a `.new` file so the user can compare:
|
|
||||||
new.save(&new_path)
|
|
||||||
.map_err(|err| SnapshotError::WriteSnapshot {
|
|
||||||
err,
|
|
||||||
path: new_path.clone(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let previous = match image::open(&snapshot_path) {
|
let previous = match image::open(&snapshot_path) {
|
||||||
Ok(image) => image.to_rgba8(),
|
Ok(image) => image.to_rgba8(),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -433,7 +426,7 @@ fn try_image_snapshot_options_impl(
|
||||||
|
|
||||||
// Compare existing image to the new one:
|
// Compare existing image to the new one:
|
||||||
let threshold = if mode == Mode::UpdateAll {
|
let threshold = if mode == Mode::UpdateAll {
|
||||||
0.0
|
0.0 // Produce diff for any error, however small
|
||||||
} else {
|
} else {
|
||||||
*threshold
|
*threshold
|
||||||
};
|
};
|
||||||
|
|
@ -441,39 +434,47 @@ fn try_image_snapshot_options_impl(
|
||||||
let result =
|
let result =
|
||||||
dify::diff::get_results(previous, new.clone(), threshold, true, None, &None, &None);
|
dify::diff::get_results(previous, new.clone(), threshold, true, None, &None, &None);
|
||||||
|
|
||||||
if let Some((num_wrong_pixels, diff_image)) = result {
|
let Some((num_wrong_pixels, diff_image)) = result else {
|
||||||
|
return Ok(()); // Difference below threshold
|
||||||
|
};
|
||||||
|
|
||||||
|
let below_threshold = num_wrong_pixels as i64 <= *failed_pixel_count_threshold as i64;
|
||||||
|
|
||||||
|
if !below_threshold {
|
||||||
diff_image
|
diff_image
|
||||||
.save(diff_path.clone())
|
.save(diff_path.clone())
|
||||||
.map_err(|err| SnapshotError::WriteSnapshot {
|
.map_err(|err| SnapshotError::WriteSnapshot {
|
||||||
path: diff_path.clone(),
|
path: diff_path.clone(),
|
||||||
err,
|
err,
|
||||||
})?;
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
let is_sameish = num_wrong_pixels as i64 <= *failed_pixel_count_threshold as i64;
|
match mode {
|
||||||
|
Mode::Test => {
|
||||||
|
if below_threshold {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
new.save(&new_path)
|
||||||
|
.map_err(|err| SnapshotError::WriteSnapshot {
|
||||||
|
err,
|
||||||
|
path: new_path.clone(),
|
||||||
|
})?;
|
||||||
|
|
||||||
match mode {
|
Err(SnapshotError::Diff {
|
||||||
Mode::Test => {
|
name,
|
||||||
if is_sameish {
|
diff: num_wrong_pixels,
|
||||||
Ok(())
|
diff_path,
|
||||||
} else {
|
})
|
||||||
Err(SnapshotError::Diff {
|
|
||||||
name,
|
|
||||||
diff: num_wrong_pixels,
|
|
||||||
diff_path,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Mode::UpdateFailing => {
|
|
||||||
if is_sameish {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
update_snapshot()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Mode::UpdateAll => update_snapshot(),
|
|
||||||
}
|
}
|
||||||
} else {
|
Mode::UpdateFailing => {
|
||||||
Ok(())
|
if below_threshold {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
update_snapshot()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Mode::UpdateAll => update_snapshot(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue