diff --git a/plotly/src/plot.rs b/plotly/src/plot.rs index 6b5ab6b8..636b3534 100644 --- a/plotly/src/plot.rs +++ b/plotly/src/plot.rs @@ -485,9 +485,9 @@ impl PartialEq for Plot { #[cfg(test)] mod tests { - use std::path::PathBuf; - use serde_json::{json, to_value}; + use std::path::PathBuf; + use std::thread; use super::*; use crate::Scatter; @@ -499,6 +499,14 @@ mod tests { plot } + fn delay_file_check() { + #[cfg(target_os = "linux")] + let delay = std::time::Duration::from_millis(0); + #[cfg(not(target_os = "linux"))] + let delay = std::time::Duration::from_millis(100); + thread::sleep(delay); + } + #[test] fn test_inline_plot() { let plot = create_test_plot(); @@ -686,26 +694,28 @@ mod tests { assert!(!dst.exists()); } - #[cfg(not(target_os = "windows"))] + // #[cfg(not(target_os = "windows"))] #[test] - #[ignore] // This seems to fail unpredictably on MacOs. + // #[ignore] // This seems to fail unpredictably on MacOs. #[cfg(feature = "kaleido")] fn test_save_to_eps() { let plot = create_test_plot(); let dst = PathBuf::from("example.eps"); plot.write_image(&dst, ImageFormat::EPS, 1024, 680, 1.0); + delay_file_check(); assert!(dst.exists()); assert!(std::fs::remove_file(&dst).is_ok()); assert!(!dst.exists()); } - #[cfg(not(target_os = "windows"))] + // #[cfg(not(target_os = "windows"))] #[test] #[cfg(feature = "kaleido")] fn test_save_to_pdf() { let plot = create_test_plot(); let dst = PathBuf::from("example.pdf"); plot.write_image(&dst, ImageFormat::PDF, 1024, 680, 1.0); + delay_file_check(); assert!(dst.exists()); assert!(std::fs::remove_file(&dst).is_ok()); assert!(!dst.exists()); diff --git a/plotly_kaleido/src/lib.rs b/plotly_kaleido/src/lib.rs index f4df4358..98605d87 100644 --- a/plotly_kaleido/src/lib.rs +++ b/plotly_kaleido/src/lib.rs @@ -183,9 +183,9 @@ impl Kaleido { #[cfg(test)] mod tests { - use std::path::PathBuf; - use serde_json::{json, to_value}; + use std::path::PathBuf; + use std::thread; use super::*; @@ -218,6 +218,14 @@ mod tests { .unwrap() } + fn delay_file_check() { + #[cfg(target_os = "linux")] + let delay = std::time::Duration::from_millis(0); + #[cfg(not(target_os = "linux"))] + let delay = std::time::Duration::from_millis(100); + thread::sleep(delay); + } + #[test] fn test_can_find_kaleido_executable() { let _k = Kaleido::new(); @@ -238,7 +246,7 @@ mod tests { assert_eq!(to_value(kaleido_data).unwrap(), expected); } - #[cfg(not(target_os = "windows"))] + // #[cfg(not(target_os = "windows"))] #[test] fn test_save_png() { let test_plot = create_test_plot(); @@ -246,10 +254,11 @@ mod tests { let dst = PathBuf::from("example.png"); let r = k.save(dst.as_path(), &test_plot, "png", 1200, 900, 4.5); assert!(r.is_ok()); + delay_file_check(); assert!(std::fs::remove_file(dst.as_path()).is_ok()); } - #[cfg(not(target_os = "windows"))] + // #[cfg(not(target_os = "windows"))] #[test] fn test_save_jpeg() { let test_plot = create_test_plot(); @@ -257,10 +266,11 @@ mod tests { let dst = PathBuf::from("example.jpeg"); let r = k.save(dst.as_path(), &test_plot, "jpeg", 1200, 900, 4.5); assert!(r.is_ok()); + delay_file_check(); assert!(std::fs::remove_file(dst.as_path()).is_ok()); } - #[cfg(not(target_os = "windows"))] + // #[cfg(not(target_os = "windows"))] #[test] fn test_save_webp() { let test_plot = create_test_plot(); @@ -268,10 +278,11 @@ mod tests { let dst = PathBuf::from("example.webp"); let r = k.save(dst.as_path(), &test_plot, "webp", 1200, 900, 4.5); assert!(r.is_ok()); + delay_file_check(); assert!(std::fs::remove_file(dst.as_path()).is_ok()); } - #[cfg(not(target_os = "windows"))] + // #[cfg(not(target_os = "windows"))] #[test] fn test_save_svg() { let test_plot = create_test_plot(); @@ -279,10 +290,11 @@ mod tests { let dst = PathBuf::from("example.svg"); let r = k.save(dst.as_path(), &test_plot, "svg", 1200, 900, 4.5); assert!(r.is_ok()); + delay_file_check(); assert!(std::fs::remove_file(dst.as_path()).is_ok()); } - #[cfg(not(target_os = "windows"))] + // #[cfg(not(target_os = "windows"))] #[test] fn test_save_pdf() { let test_plot = create_test_plot(); @@ -290,10 +302,11 @@ mod tests { let dst = PathBuf::from("example.pdf"); let r = k.save(dst.as_path(), &test_plot, "pdf", 1200, 900, 4.5); assert!(r.is_ok()); + delay_file_check(); assert!(std::fs::remove_file(dst.as_path()).is_ok()); } - #[cfg(not(target_os = "windows"))] + // #[cfg(not(target_os = "windows"))] #[test] #[ignore] fn test_save_eps() { @@ -302,6 +315,7 @@ mod tests { let dst = PathBuf::from("example.eps"); let r = k.save(dst.as_path(), &test_plot, "eps", 1200, 900, 4.5); assert!(r.is_ok()); + delay_file_check(); assert!(std::fs::remove_file(dst.as_path()).is_ok()); } }