π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[rust] Prune low-value OCR tests
laurenspriem25d04e5b7181
diff --git a/rust/crates/ml/src/ocr/assets.rs b/rust/crates/ml/src/ocr/assets.rsindex c5b3f81f00..7f84f646f6 100644--- a/rust/crates/ml/src/ocr/assets.rs+++ b/rust/crates/ml/src/ocr/assets.rs@@ -116,19 +116,10 @@ pub async fn ensure_models(store: &AssetStore) -> MlResult<OcrModelPaths> {#[cfg(test)]mod tests {- use std::collections::HashSet;use std::path::Path;use super::*;- #[test]- fn catalog_keys_and_names_are_unique() {- let keys: HashSet<&str> = CATALOG.iter().map(|file| file.key).collect();- let names: HashSet<&str> = CATALOG.iter().map(|file| file.name).collect();- assert_eq!(keys.len(), CATALOG.len());- assert_eq!(names.len(), CATALOG.len());- }-#[test]fn catalog_directories_do_not_collide_with_the_indexing_catalog() {let store = AssetStore::new(Path::new("cache"));@@ -148,39 +139,4 @@ mod tests {}}}-- #[test]- fn catalog_points_at_the_pp_ocrv5_cdn_directory() {- assert_eq!(DETECTION.url(), "https://models.ente.com/PP-OCRv5/det.onnx");- assert_eq!(- DICTIONARY.url(),- "https://models.ente.com/PP-OCRv5/ppocrv5_dict.txt"- );- assert_eq!(model_assets().len(), 4);- }-- #[test]- fn model_paths_live_under_the_store_models_directory() {- let store = AssetStore::new(Path::new("cache"));- for file in CATALOG {- let path = file.path(&store);- assert!(path.starts_with("cache/models/"), "{path}");- assert!(path.ends_with(file.name), "{path}");- assert!(!store.is_downloaded(&file.asset()));- }- }-- #[test]- fn local_copies_match_the_catalog_sizes() {- let local = Path::new(- "/private/tmp/claude-501/-Users-laurens-dev-ente-repo-ente8/a307b632-3b09-4f43-884c-2830ff54fe8f/scratchpad/models",- );- if !local.is_dir() {- return;- }- for file in CATALOG {- let metadata = std::fs::metadata(local.join(file.name)).unwrap();- assert_eq!(metadata.len(), file.size, "{}", file.name);- }- }}diff --git a/rust/crates/ml/src/ocr/classify.rs b/rust/crates/ml/src/ocr/classify.rsindex 759ed4fad3..6c8ec05d81 100644--- a/rust/crates/ml/src/ocr/classify.rs+++ b/rust/crates/ml/src/ocr/classify.rs@@ -172,16 +172,6 @@ mod tests {}}- #[test]- fn resized_width_scales_to_the_input_height_and_caps_at_the_input_width() {- assert_eq!(resized_width(100, 48), 100);- assert_eq!(resized_width(50, 24), 100);- assert_eq!(resized_width(1000, 48), INPUT_WIDTH);- assert_eq!(resized_width(10, 48), 10);- assert_eq!(resized_width(1, 4096), 1);- assert_eq!(resized_width(7, 3), 112);- }-#[test]fn rotation_needs_the_flipped_class_to_win_with_high_confidence() {assert!(!scores(0.95, 0.05).needs_rotation());diff --git a/rust/crates/ml/src/ocr/crop.rs b/rust/crates/ml/src/ocr/crop.rsindex d2ddaea64f..2bb7926eaa 100644--- a/rust/crates/ml/src/ocr/crop.rs+++ b/rust/crates/ml/src/ocr/crop.rs@@ -101,12 +101,6 @@ mod tests {assert_eq!(size, (100, 20));}- #[test]- fn crop_size_never_collapses_below_one_pixel() {- let size = crop_size(&quad([(5.0, 5.0), (5.4, 5.0), (5.4, 5.3), (5.0, 5.3)]));- assert_eq!(size, (1, 1));- }-#[test]fn axis_aligned_crop_reproduces_the_source_pixels() {let source = gradient_image(40, 30);@@ -143,35 +137,4 @@ mod tests {assert_eq!(pixel(&crop.image, 0, 1), pixel(&source, 4, 2));assert_eq!(pixel(&crop.image, 2, 1), pixel(&source, 4, 4));}-- #[test]- fn aspect_of_exactly_one_and_a_half_counts_as_vertical() {- assert!(is_vertical(2, 3));- assert!(!is_vertical(3, 4));- assert!(!is_vertical(1, 1));- }-- #[test]- fn counter_clockwise_rotation_moves_the_top_right_corner_to_the_top_left() {- let [a, b, c, d, e, f] = [1u8, 2, 3, 4, 5, 6];- let source = ImageU8::new(- 2,- 3,- 3,- [a, b, c, d, e, f].iter().flat_map(|&v| [v, v, v]).collect(),- )- .unwrap();-- let rotated = rotate_counter_clockwise(&source).unwrap();-- assert_eq!((rotated.width, rotated.height), (3, 2));- let values: Vec<u8> = rotated- .data- .as_chunks::<3>()- .0- .iter()- .map(|px| px[0])- .collect();- assert_eq!(values, [b, d, f, a, c, e]);- }}diff --git a/rust/crates/ml/src/ocr/detect.rs b/rust/crates/ml/src/ocr/detect.rsindex 6f7e1561ce..0c8bfda640 100644--- a/rust/crates/ml/src/ocr/detect.rs+++ b/rust/crates/ml/src/ocr/detect.rs@@ -438,12 +438,6 @@ mod tests {assert_eq!(order, [(10.0, 50.0), (100.0, 40.0), (5.0, 50.5)]);}- #[test]- fn rejects_probability_map_with_wrong_length() {- let error = candidates_from_probability_map(&[0.0; 10], 4, 4, 4, 4).unwrap_err();- assert!(matches!(error, MlError::Postprocess(_)), "{error}");- }-#[test]fn detector_input_truncates_then_rounds_half_to_even_to_a_multiple_of_32() {assert_eq!(detector_input_size(1000, 700), (960, 672));@@ -471,16 +465,4 @@ mod tests {assert!((actual - expected).abs() <= 1e-6, "{planes:?}");}}-- #[test]- fn detector_planes_are_laid_out_plane_by_plane() {- let two_pixels = ImageU8::new(2, 1, 3, vec![255, 0, 0, 0, 0, 255]).unwrap();- let planes = normalized_bgr_planes(&two_pixels).unwrap();- let blue_of = |value: f32| (value / 255.0 - 0.485) / 0.229;- let red_of = |value: f32| (value / 255.0 - 0.406) / 0.225;- assert!((planes[0] - blue_of(0.0)).abs() <= 1e-6);- assert!((planes[1] - blue_of(255.0)).abs() <= 1e-6);- assert!((planes[4] - red_of(255.0)).abs() <= 1e-6);- assert!((planes[5] - red_of(0.0)).abs() <= 1e-6);- }}diff --git a/rust/crates/ml/src/ocr/dictionary.rs b/rust/crates/ml/src/ocr/dictionary.rsindex b0da00b2b8..8e669c3b5b 100644--- a/rust/crates/ml/src/ocr/dictionary.rs+++ b/rust/crates/ml/src/ocr/dictionary.rs@@ -32,9 +32,6 @@ mod tests {use super::*;- const LOCAL_DICTIONARY: &str = "/private/tmp/claude-501/-Users-laurens-dev-ente-repo-ente8/a307b632-3b09-4f43-884c-2830ff54fe8f/scratchpad/models/ppocrv5_dict.txt";- const PPOCRV5_VOCABULARY: usize = 18385;-fn temp_dictionary(contents: &[u8]) -> tempfile::NamedTempFile {let mut file = tempfile::NamedTempFile::new().unwrap();file.write_all(contents).unwrap();@@ -42,19 +39,6 @@ mod tests {file}- #[test]- fn loads_local_ppocrv5_dictionary() {- let path = Path::new(LOCAL_DICTIONARY);- if !path.exists() {- return;- }- let entries = load_dictionary(path, PPOCRV5_VOCABULARY).unwrap();- assert_eq!(entries.len(), PPOCRV5_VOCABULARY);- assert_eq!(entries[0], "blank");- assert_eq!(entries[1], "\u{3000}");- assert_eq!(entries.last().unwrap(), " ");- }-#[test]fn wraps_lines_with_blank_and_space() {let file = temp_dictionary("\u{3000}\r\na\n \nb\n".as_bytes());@@ -69,11 +53,4 @@ mod tests {assert!(matches!(error, MlError::CorruptModel(_)), "{error}");assert!(error.to_string().contains("has 5 entries"), "{error}");}-- #[test]- fn rejects_missing_file() {- let dir = tempfile::tempdir().unwrap();- let error = load_dictionary(&dir.path().join("missing.txt"), 3).unwrap_err();- assert!(matches!(error, MlError::CorruptModel(_)), "{error}");- }}diff --git a/rust/crates/ml/src/ocr/geometry.rs b/rust/crates/ml/src/ocr/geometry.rsindex 3cab319ee7..3119e88e74 100644--- a/rust/crates/ml/src/ocr/geometry.rs+++ b/rust/crates/ml/src/ocr/geometry.rs@@ -295,49 +295,6 @@ mod tests {}}- #[test]- fn min_area_rect_of_axis_aligned_points() {- let points = [- (40, 30),- (100, 30),- (139, 30),- (139, 69),- (60, 69),- (40, 69),- (90, 50),- ];- let rect = order_corners(min_area_rect(&points).expect("rect"));- assert_eq!(- rect,- [- Point::new(40.0, 30.0),- Point::new(139.0, 30.0),- Point::new(139.0, 69.0),- Point::new(40.0, 69.0),- ]- );- assert!(min_area_rect(&[(0, 0), (1, 1)]).is_none());- }-- #[test]- fn clip_to_bounds_clamps_corners() {- let quad = [- Point::new(-5.0, -3.0),- Point::new(120.0, -3.0),- Point::new(120.0, 45.0),- Point::new(-5.0, 45.0),- ];- assert_eq!(- clip_to_bounds(&quad, 100.0, 40.0),- [- Point::new(0.0, 0.0),- Point::new(100.0, 0.0),- Point::new(100.0, 40.0),- Point::new(0.0, 40.0),- ]- );- }-#[test]fn mean_inside_quad_averages_rasterised_pixels() {let width = 10;diff --git a/rust/crates/ml/src/ocr/mod.rs b/rust/crates/ml/src/ocr/mod.rsindex 8aac580be1..e2b12c1f4c 100644--- a/rust/crates/ml/src/ocr/mod.rs+++ b/rust/crates/ml/src/ocr/mod.rs@@ -564,19 +564,6 @@ mod tests {}}- #[test]- fn engine_requires_a_detection_model_path() {- let error = OcrEngine::new(OcrModelPaths {- detection: String::new(),- classification: "cls.onnx".to_string(),- recognition: "rec.onnx".to_string(),- dictionary: "dict.txt".to_string(),- })- .err()- .expect("empty detection path is rejected");- assert!(matches!(error, MlError::InvalidRequest(_)), "{error}");- }-#[test]fn engine_accepts_a_detector_only_path_set_without_loading_it() {let engine = detector_only_engine();diff --git a/rust/crates/ml/src/ocr/recognize.rs b/rust/crates/ml/src/ocr/recognize.rsindex 333d66b758..a9f7591b2f 100644--- a/rust/crates/ml/src/ocr/recognize.rs+++ b/rust/crates/ml/src/ocr/recognize.rs@@ -431,13 +431,6 @@ mod tests {assert_close(recognition.confidence, (0.8 + 0.5 + 0.4) / 3.0);}- #[test]- fn argmax_picks_the_first_of_equal_maxima() {- let best = argmax(&[0.2, 0.5, 0.5, 0.1]);- assert_eq!(best.index, 1);- assert_close(best.probability, 0.5);- }-#[test]fn padded_spans_are_stretched_then_clamped_with_the_minimum_span() {let steps = [(1, 1.0), (0, 1.0), (0, 1.0), (2, 1.0)];@@ -447,27 +440,6 @@ mod tests {assert_span(&recognition.spans[1], "b", 1.0, 0.5, 1.0);}- #[test]- fn minimum_span_never_drops_below_one_thousandth() {- let mut steps = vec![(0usize, 1.0f32); 2000];- steps[0] = (1, 1.0);- let recognition = ctc_decode(- &logits(2, &steps),- 2,- &["blank".to_string(), "a".to_string()],- 1.0,- );- assert_span(&recognition.spans[0], "a", 1.0, 0.0, 1e-3);- }-- #[test]- fn indices_outside_the_dictionary_are_skipped() {- let recognition = ctc_decode(&logits(5, &[(4, 0.9), (1, 0.8)]), 5, &dictionary(), 1.0);- assert_eq!(recognition.text, "a");- assert_eq!(recognition.spans.len(), 1);- assert_close(recognition.confidence, 0.8);- }-#[test]fn target_width_truncates_and_content_width_ceils() {assert_eq!(@@ -572,21 +544,4 @@ mod tests {assert!(matches!(error, OcrError::Cancelled), "{error}");}-- #[test]- fn a_short_result_list_is_reported_as_a_corrupt_model() {- let crops = [solid(4, 4, [0; 3]), solid(4, 4, [0; 3])];- let registry = RequestRegistry::default();- let request = registry.begin(None);-- let error = recognize_in_batches(&crops.iter().collect::<Vec<_>>(), &request, |_| {- Ok(vec![Recognition::default()])- })- .unwrap_err();-- assert!(- matches!(error, OcrError::Ml(MlError::CorruptModel(_))),- "{error}"- );- }}diff --git a/rust/crates/ml/src/ocr/source.rs b/rust/crates/ml/src/ocr/source.rsindex 9bb04cea40..b8a906d275 100644--- a/rust/crates/ml/src/ocr/source.rs+++ b/rust/crates/ml/src/ocr/source.rs@@ -128,18 +128,6 @@ mod tests {assert_eq!(source.working.width, source.working.height);}- #[test]- fn small_image_is_kept_as_is() {- let dir = tempfile::tempdir().unwrap();- let path = write_png(dir.path(), "small.png", 640, 480);-- let source = load_source(&path, REGIONS_CAP).unwrap();-- assert_eq!((source.decoded_width, source.decoded_height), (640, 480));- assert_eq!((source.working.width, source.working.height), (640, 480));- assert_eq!(source.working.data.len(), 640 * 480 * 3);- }-#[test]fn missing_file_is_reported_before_decoding() {let dir = tempfile::tempdir().unwrap();@@ -156,15 +144,4 @@ mod tests {"{error}");}-- #[test]- fn regions_cap_applies_the_smaller_of_both_limits() {- assert_eq!(REGIONS_CAP.working_size(5000, 1000), (1280, 256));- assert_eq!(REGIONS_CAP.working_size(2000, 2000), (1280, 1280));- assert_eq!(REGIONS_CAP.working_size(1280, 960), (1280, 960));- assert_eq!(FULL_TEXT_CAP.working_size(4000, 3000), (4000, 3000));- assert_eq!(FULL_TEXT_CAP.working_size(5000, 3000), (4096, 2458));- assert_eq!(FULL_TEXT_CAP.working_size(4000, 4000), (3464, 3464));- assert_eq!(FULL_TEXT_CAP.working_size(1, 9000), (1, 4096));- }}diff --git a/rust/crates/ml/src/ocr/tensor.rs b/rust/crates/ml/src/ocr/tensor.rsindex aa8d6bdeba..82cffa9ac8 100644--- a/rust/crates/ml/src/ocr/tensor.rs+++ b/rust/crates/ml/src/ocr/tensor.rs@@ -110,21 +110,4 @@ mod tests {assert!((actual - expected).abs() <= 1e-6, "{planes:?}");}}-- #[test]- fn images_that_do_not_fit_the_planes_are_rejected() {- let rgb = ImageU8::new(4, 1, 3, vec![0; 12]).unwrap();- let mut planes = vec![0.0f32; 3 * 3];-- let too_wide = write_bgr_planes(&rgb, &mut planes, 3, BgrNormalization::CENTERED);- assert!(matches!(too_wide, Err(MlError::Preprocess(_))));-- let too_short = write_bgr_planes(&rgb, &mut planes, 4, BgrNormalization::CENTERED);- assert!(matches!(too_short, Err(MlError::Preprocess(_))));-- let gray = ImageU8::new(1, 1, 1, vec![0]).unwrap();- let wrong_channels =- write_bgr_planes(&gray, &mut planes[..3], 1, BgrNormalization::CENTERED);- assert!(matches!(wrong_channels, Err(MlError::Preprocess(_))));- }}