From 4a8cffe7e03126bb1483b73b0a9b55a4167ed312 Mon Sep 17 00:00:00 2001 From: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:13:52 +0100 Subject: [PATCH] try macos kaleido Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> --- plotly/src/plot.rs | 12 ++++----- plotly_kaleido/src/lib.rs | 56 +++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/plotly/src/plot.rs b/plotly/src/plot.rs index fd0b1cd..465a510 100644 --- a/plotly/src/plot.rs +++ b/plotly/src/plot.rs @@ -748,7 +748,7 @@ mod tests { assert!(!dst.exists()); } - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] #[cfg(feature = "kaleido")] fn test_save_to_png() { @@ -760,7 +760,7 @@ mod tests { assert!(!dst.exists()); } - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] #[cfg(feature = "kaleido")] fn test_save_to_jpeg() { @@ -772,7 +772,7 @@ mod tests { assert!(!dst.exists()); } - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] #[cfg(feature = "kaleido")] fn test_save_to_svg() { @@ -796,7 +796,7 @@ mod tests { assert!(!dst.exists()); } - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] #[cfg(feature = "kaleido")] fn test_save_to_pdf() { @@ -820,7 +820,7 @@ mod tests { assert!(!dst.exists()); } - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] #[cfg(feature = "kaleido")] fn test_image_to_base64() { @@ -850,7 +850,7 @@ mod tests { assert!(image_base64.is_empty()); } - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] #[cfg(feature = "kaleido")] fn test_image_to_svg_string() { diff --git a/plotly_kaleido/src/lib.rs b/plotly_kaleido/src/lib.rs index cb0c17f..70d9b57 100644 --- a/plotly_kaleido/src/lib.rs +++ b/plotly_kaleido/src/lib.rs @@ -297,7 +297,7 @@ mod tests { } // This seems to fail unpredictably on MacOs. - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] fn test_save_png() { let test_plot = create_test_plot(); @@ -309,7 +309,7 @@ mod tests { } // This seems to fail unpredictably on MacOs. - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] fn test_save_jpeg() { let test_plot = create_test_plot(); @@ -321,7 +321,7 @@ mod tests { } // This seems to fail unpredictably on MacOs. - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] fn test_save_webp() { let test_plot = create_test_plot(); @@ -333,7 +333,7 @@ mod tests { } // This seems to fail unpredictably on MacOs. - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] fn test_save_svg() { let test_plot = create_test_plot(); @@ -345,7 +345,7 @@ mod tests { } // This seems to fail unpredictably on MacOs. - #[cfg(target_os = "linux")] + // #[cfg(target_os = "linux")] #[test] fn test_save_pdf() { let test_plot = create_test_plot(); @@ -367,4 +367,50 @@ mod tests { assert!(r.is_ok()); assert!(std::fs::remove_file(dst.as_path()).is_ok()); } + + // #[cfg(target_os = "linux")] + #[test] + // #[cfg(feature = "kaleido")] + fn test_image_to_base64() { + use base64::engine::general_purpose; + use base64::Engine; + let plot = create_test_plot(); + + let image_base64 = plot.to_base64(ImageFormat::PNG, 200, 150, 1.0); + + assert!(!image_base64.is_empty()); + + let result_decoded = general_purpose::STANDARD.decode(image_base64).unwrap(); + let expected = "iVBORw0KGgoAAAANSUhEUgAAAMgAAACWCAYAAACb3McZAAAH0klEQVR4Xu2bSWhVZxiGv2gC7SKJWrRWxaGoULsW7L7gXlAMKApiN7pxI46ggnNQcDbOoAZUcCG4CCiIQ4MSkWKFLNSCihTR2ESTCNVb/lMTEmvu8OYuTN/nQBHb895zv+f9H+6ZWpHL5XLBBgEIfJZABYKwMiAwMAEEYXVAIA8BBGF5QABBWAMQ0AjwC6JxI2VCAEFMimZMjQCCaNxImRBAEJOiGVMjg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xKZoxNQIIonEjZUIAQUyKZkyNAIJo3EiZEEAQk6IZUyOAIBo3UiYEEMSkaMbUCCCIxo2UCQEEMSmaMTUCCKJxI2VCAEFMimZMjQCCaNxImRBAEJOiGVMjgCAaN1ImBBDEpGjG1AggiMaNlAkBBDEpmjE1AgiicSNlQgBBTIpmTI0AgmjcSJkQQBCTohlTI4AgGjdSJgQQxKRoxtQIIIjGjZQJAQQxKZoxNQIIonEjZUIAQUyKZkyNAIJo3EiZEEAQk6IZUyOAIBo3UiYEEMSkaMbUCCCIxo2UCQEEMSmaMTUCCKJxI2VC4B+Ci/5sJeSfvgAAAABJRU5ErkJggg=="; + let expected_decoded = general_purpose::STANDARD.decode(expected).unwrap(); + + // Comparing the result seems to end up being a flaky test. + // Limit the comparison to the first characters; + // As image contents seem to be slightly inconsistent across platforms + assert_eq!(expected_decoded[..2], result_decoded[..2]); + } + + #[test] + // #[cfg(feature = "kaleido")] + fn test_image_to_base64_invalid_format() { + let plot = create_test_plot(); + let image_base64 = plot.to_base64(ImageFormat::EPS, 200, 150, 1.0); + assert!(image_base64.is_empty()); + } + + // #[cfg(target_os = "linux")] + #[test] + // #[cfg(feature = "kaleido")] + fn test_image_to_svg_string() { + let plot = create_test_plot(); + let image_svg = plot.to_svg(200, 150, 1.0); + + assert!(!image_svg.is_empty()); + + let expected = "012246810"; + // Limit the test to the first LEN characters as generated SVGs + // seem to contain uniquely generated IDs + const LEN: usize = 10; + assert_eq!(expected[..LEN], image_svg[..LEN]); + } }