Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix metadata test lint

Neeraj Guptaf9d9d107c550
diff --git a/mobile/apps/photos/test/module/metadata/photo_test.dart b/mobile/apps/photos/test/module/metadata/photo_test.dart
index 34a1db1c96..d8c07028f8 100644
--- a/mobile/apps/photos/test/module/metadata/photo_test.dart
+++ b/mobile/apps/photos/test/module/metadata/photo_test.dart
@@ -49,15 +49,9 @@ void main() {
),
);
- expect(
- file.creationTime,
- 1786450130 * Duration.microsecondsPerSecond,
- );
+ expect(file.creationTime, 1786450130 * Duration.microsecondsPerSecond);
applyCreationTimeMetadata(file, null);
- expect(
- file.creationTime,
- 1786450130 * Duration.microsecondsPerSecond,
- );
+ expect(file.creationTime, 1786450130 * Duration.microsecondsPerSecond);
});
test(
diff --git a/rust/crates/photos/tests/metadata_test.rs b/rust/crates/photos/tests/metadata_test.rs
index 6565013367..2650cea81f 100644
--- a/rust/crates/photos/tests/metadata_test.rs
+++ b/rust/crates/photos/tests/metadata_test.rs
@@ -3,11 +3,13 @@ use std::io::Write;
use ente_exif::{DateTimeSource, Dimensions, Location, namespace};
use ente_photos::metadata::{PhotoMetadata, read_photo_metadata};
+type TestResult<T = ()> = Result<T, Box<dyn std::error::Error>>;
+
#[test]
-fn reads_display_dimensions_capture_time_and_xmp_location() {
+fn reads_display_dimensions_capture_time_and_xmp_location() -> TestResult {
let properties = r#"tiff:Orientation="6" exif:DateTimeOriginal="2024-01-01T12:00:00.123456-00:30"
exif:GPSLatitude="40,30N" exif:GPSLongitude="74,15W""#;
- let metadata = read(properties);
+ let metadata = read(properties)?;
assert_eq!(
metadata.dimensions,
Some(Dimensions {
@@ -15,10 +17,18 @@ fn reads_display_dimensions_capture_time_and_xmp_location() {
height: 64
})
);
- let date = metadata.capture_date_time.unwrap();
- assert_eq!(date.date_time, "2024-01-01T12:00:00.123456000");
- assert_eq!(date.offset_time.as_deref(), Some("-00:30"));
- assert_eq!(date.timestamp_micros, Some(1_704_112_200_123_456));
+ assert_eq!(
+ metadata.capture_date_time.as_ref().map(|date| (
+ date.date_time.as_str(),
+ date.offset_time.as_deref(),
+ date.timestamp_micros,
+ )),
+ Some((
+ "2024-01-01T12:00:00.123456000",
+ Some("-00:30"),
+ Some(1_704_112_200_123_456),
+ ))
+ );
assert_eq!(
metadata.location,
Some(Location {
@@ -26,10 +36,11 @@ fn reads_display_dimensions_capture_time_and_xmp_location() {
longitude: -74.25
})
);
+ Ok(())
}
#[test]
-fn skips_partial_and_sentinel_capture_dates_and_continues_to_fallbacks() {
+fn skips_partial_and_sentinel_capture_dates_and_continues_to_fallbacks() -> TestResult {
for (original, rejected) in [
("2004", true),
("2004-06", true),
@@ -49,35 +60,36 @@ fn skips_partial_and_sentinel_capture_dates_and_continues_to_fallbacks() {
] {
let metadata = read(&format!(
r#"exif:DateTimeOriginal="{original}" xmp:CreateDate="2024-01-02T12:00:00Z""#
- ));
+ ))?;
let expected = if rejected {
DateTimeSource::Xmp(namespace::XMP, "CreateDate")
} else {
DateTimeSource::Xmp(namespace::EXIF, "DateTimeOriginal")
};
assert_eq!(
- metadata.capture_date_time.unwrap().source,
- expected,
+ metadata.capture_date_time.as_ref().map(|d| d.source),
+ Some(expected),
"{original}"
);
}
assert!(
- read(r#"exif:DateTimeOriginal="2004" xmp:CreateDate="2004-06-15""#)
+ read(r#"exif:DateTimeOriginal="2004" xmp:CreateDate="2004-06-15""#)?
.capture_date_time
.is_none()
);
assert!(
read(
r#"exif:DateTimeOriginal="4501-01-01T00:00:00Z" xmp:CreateDate="1970-01-01T00:00:00Z""#
- )
+ )?
.capture_date_time
.is_none()
);
+ Ok(())
}
#[test]
-fn reads_panorama_and_motion_video() {
- let plain = read("");
+fn reads_panorama_and_motion_video() -> TestResult {
+ let plain = read("")?;
assert!(!plain.is_panorama);
assert_eq!(plain.motion_video, None);
let video = b"\0\0\0\x10ftypisom\0\0\0\0\0\0\0\x08moov\0\0\0\x08mdat";
@@ -87,30 +99,31 @@ fn reads_panorama_and_motion_video() {
xmlns:GCamera="http://ns.google.com/photos/1.0/camera/"
GCamera:MicroVideoOffset="32""#,
video,
- );
+ )?;
assert!(metadata.is_panorama);
- let range = metadata.motion_video.unwrap();
- assert!(range.start > 0);
- assert_eq!(range.end - range.start, video.len() as u64);
+ assert!(
+ metadata.motion_video.as_ref().is_some_and(|range| {
+ range.start > 0 && range.end - range.start == video.len() as u64
+ })
+ );
+ Ok(())
}
-fn read(properties: &str) -> PhotoMetadata {
+fn read(properties: &str) -> TestResult<PhotoMetadata> {
read_with_tail(properties, &[])
}
-fn read_with_tail(properties: &str, tail: &[u8]) -> PhotoMetadata {
+fn read_with_tail(properties: &str, tail: &[u8]) -> TestResult<PhotoMetadata> {
let xmp = format!(
"http://ns.adobe.com/xap/1.0/\0<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><rdf:Description xmlns:exif=\"http://ns.adobe.com/exif/1.0/\" xmlns:tiff=\"http://ns.adobe.com/tiff/1.0/\" xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\" {properties}/></rdf:RDF>"
);
- let mut file = tempfile::NamedTempFile::new().unwrap();
- file.write_all(&[0xff, 0xd8, 0xff, 0xe1]).unwrap();
- file.write_all(&u16::try_from(xmp.len() + 2).unwrap().to_be_bytes())
- .unwrap();
- file.write_all(xmp.as_bytes()).unwrap();
+ let mut file = tempfile::NamedTempFile::new()?;
+ file.write_all(&[0xff, 0xd8, 0xff, 0xe1])?;
+ file.write_all(&u16::try_from(xmp.len() + 2)?.to_be_bytes())?;
+ file.write_all(xmp.as_bytes())?;
file.write_all(&[
0xff, 0xc0, 0, 11, 8, 0, 48, 0, 64, 1, 1, 0x11, 0, 0xff, 0xd9,
- ])
- .unwrap();
- file.write_all(tail).unwrap();
- read_photo_metadata(file.path()).unwrap()
+ ])?;
+ file.write_all(tail)?;
+ Ok(read_photo_metadata(file.path())?)
}