Skip to content

Commit 0ea64ff

Browse files
committed
add a few simple unittests and disable failing tests on MacOs
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent d259c8b commit 0ea64ff

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

plotly/src/common/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,15 @@ mod tests {
22102210
assert_eq!(to_value(Reference::Paper).unwrap(), json!("paper"));
22112211
}
22122212

2213+
#[test]
2214+
#[rustfmt::skip]
2215+
fn test_serialize_legend_group_title() {
2216+
assert_eq!(to_value(LegendGroupTitle::new()).unwrap(), json!({}));
2217+
assert_eq!(to_value(LegendGroupTitle::with_text("title_str").font(Font::default())).unwrap(), json!({"font": {}, "text": "title_str"}));
2218+
assert_eq!(to_value(LegendGroupTitle::from(String::from("title_string"))).unwrap(), json!({"text" : "title_string"}));
2219+
assert_eq!(to_value(LegendGroupTitle::from(&String::from("title_string"))).unwrap(), json!({"text" : "title_string"}));
2220+
}
2221+
22132222
#[test]
22142223
fn test_serialize_pad() {
22152224
let pad = Pad::new(1, 2, 3);

plotly/src/layout/themes.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,31 @@ mod tests {
165165
use super::*;
166166
use crate::*;
167167

168+
#[test]
169+
fn test_plotly_default() {
170+
let template = &*DEFAULT;
171+
let layout = Layout::new().template(template);
172+
let mut plot = Plot::new();
173+
plot.set_layout(layout);
174+
plot.add_trace(Bar::new(vec![0], vec![1]));
175+
176+
let expected = r##"{"template":{"layout":{}}}"##; // etc...
177+
assert!(plot.to_json().contains(expected));
178+
}
179+
180+
#[test]
181+
fn test_plotly_white() {
182+
let template = &*PLOTLY_WHITE;
183+
let layout = Layout::new().template(template);
184+
let mut plot = Plot::new();
185+
plot.set_layout(layout);
186+
plot.add_trace(Bar::new(vec![0], vec![1]));
187+
dbg!(plot.to_json());
188+
189+
let expected = r##"{"template":{"layout":{"title":{"x":0.05},"font":{"color":"#2a3f5f"}"##; // etc...
190+
assert!(plot.to_json().contains(expected));
191+
}
192+
168193
#[test]
169194
fn test_plotly_dark() {
170195
let template = &*PLOTLY_DARK;

plotly/src/plot.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,9 @@ mod tests {
651651
assert!(!dst.exists());
652652
}
653653

654-
#[cfg(not(target_os = "windows"))]
654+
// This seems to fail unpredictably on MacOs.
655655
#[test]
656+
#[cfg(not(all(target_os = "windows", target_os = "macos")))]
656657
#[cfg(feature = "kaleido")]
657658
fn test_save_to_png() {
658659
let plot = create_test_plot();
@@ -663,8 +664,9 @@ mod tests {
663664
assert!(!dst.exists());
664665
}
665666

666-
#[cfg(not(target_os = "windows"))]
667+
// This seems to fail unpredictably on MacOs.
667668
#[test]
669+
#[cfg(not(all(target_os = "windows", target_os = "macos")))]
668670
#[cfg(feature = "kaleido")]
669671
fn test_save_to_jpeg() {
670672
let plot = create_test_plot();
@@ -675,8 +677,9 @@ mod tests {
675677
assert!(!dst.exists());
676678
}
677679

678-
#[cfg(not(target_os = "windows"))]
680+
// This seems to fail unpredictably on MacOs.
679681
#[test]
682+
#[cfg(not(all(target_os = "windows", target_os = "macos")))]
680683
#[cfg(feature = "kaleido")]
681684
fn test_save_to_svg() {
682685
let plot = create_test_plot();
@@ -687,8 +690,9 @@ mod tests {
687690
assert!(!dst.exists());
688691
}
689692

693+
// This seems to fail unpredictably on MacOs.
690694
#[test]
691-
#[ignore] // This seems to fail unpredictably on MacOs.
695+
#[ignore]
692696
#[cfg(feature = "kaleido")]
693697
fn test_save_to_eps() {
694698
let plot = create_test_plot();
@@ -699,8 +703,9 @@ mod tests {
699703
assert!(!dst.exists());
700704
}
701705

702-
#[cfg(not(target_os = "windows"))]
706+
// This seems to fail unpredictably on MacOs.
703707
#[test]
708+
#[cfg(not(all(target_os = "windows", target_os = "macos")))]
704709
#[cfg(feature = "kaleido")]
705710
fn test_save_to_pdf() {
706711
let plot = create_test_plot();
@@ -711,8 +716,9 @@ mod tests {
711716
assert!(!dst.exists());
712717
}
713718

714-
#[cfg(not(target_os = "windows"))]
719+
// This seems to fail unpredictably on MacOs.
715720
#[test]
721+
#[cfg(not(all(target_os = "windows", target_os = "macos")))]
716722
#[cfg(feature = "kaleido")]
717723
fn test_save_to_webp() {
718724
let plot = create_test_plot();

0 commit comments

Comments
 (0)