Skip to content

Commit

Permalink
wip: test kaleido for macos
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Gherghescu <[email protected]>
  • Loading branch information
andrei-ng committed Dec 6, 2024
1 parent 891cac4 commit 8b19019
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
44 changes: 27 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: CI
on:
workflow_dispatch:
pull_request:
branches: [ main ]
branches: [main]
push:
branches: [ main ]
branches: [main]

# Cancel any in-flight jobs for the same PR/branch so there's only one active
# at a time
Expand Down Expand Up @@ -65,9 +65,19 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os:
[
ubuntu-latest,
windows-latest,
macos-12,
macos-13,
macos-14,
macos-15,
macos-latest,
]
runs-on: ${{ matrix.os }}
steps:
- run: sysctl -n machdep.cpu.brand_string
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --features plotly_ndarray,plotly_image,kaleido
Expand All @@ -92,19 +102,20 @@ jobs:
strategy:
fail-fast: false
matrix:
example: [ # missing jupyter
3d_charts,
basic_charts,
custom_controls,
financial_charts,
images,
kaleido,
maps,
ndarray,
scientific_charts,
shapes,
subplots
]
example: # missing jupyter
[
3d_charts,
basic_charts,
custom_controls,
financial_charts,
images,
kaleido,
maps,
ndarray,
scientific_charts,
shapes,
subplots,
]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -124,4 +135,3 @@ jobs:
with:
targets: wasm32-unknown-unknown
- run: cd ${{ github.workspace }}/examples/${{ matrix.example }} && cargo build --target wasm32-unknown-unknown

21 changes: 11 additions & 10 deletions plotly/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(target_os = "linux")]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_png() {
Expand All @@ -761,7 +761,7 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(target_os = "linux")]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_jpeg() {
Expand All @@ -773,7 +773,7 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(target_os = "linux")]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_svg() {
Expand All @@ -786,7 +786,7 @@ mod tests {
}

#[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();
Expand All @@ -797,7 +797,7 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(target_os = "linux")]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_pdf() {
Expand All @@ -809,7 +809,7 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(target_os = "linux")]
#[test]
#[cfg(feature = "kaleido")]
fn test_save_to_webp() {
Expand All @@ -821,7 +821,7 @@ mod tests {
assert!(!dst.exists());
}

#[cfg(target_os = "linux")]
// #[cfg(target_os = "linux")]
#[test]
#[cfg(feature = "kaleido")]
fn test_image_to_base64() {
Expand Down Expand Up @@ -849,7 +849,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() {
Expand All @@ -859,8 +859,9 @@ mod tests {
assert!(!image_svg.is_empty());

let expected = "<svg class=\"main-svg\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"150\" style=\"\" viewBox=\"0 0 200 150\"><rect x=\"0\" y=\"0\" width=\"200\" height=\"150\" style=\"fill: rgb(255, 255, 255); fill-opacity: 1;\"/><defs id=\"defs-2dc70a\"><g class=\"clips\"><clipPath id=\"clip2dc70axyplot\" class=\"plotclip\"><rect width=\"40\" height=\"2\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70ax\"><rect x=\"80\" y=\"0\" width=\"40\" height=\"150\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70ay\"><rect x=\"0\" y=\"82\" width=\"200\" height=\"2\"/></clipPath><clipPath class=\"axesclip\" id=\"clip2dc70axy\"><rect x=\"80\" y=\"82\" width=\"40\" height=\"2\"/></clipPath></g><g class=\"gradients\"/></defs><g class=\"bglayer\"/><g class=\"layer-below\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"cartesianlayer\"><g class=\"subplot xy\"><g class=\"layer-subplot\"><g class=\"shapelayer\"/><g class=\"imagelayer\"/></g><g class=\"gridlayer\"><g class=\"x\"><path class=\"xgrid crisp\" transform=\"translate(100,0)\" d=\"M0,82v2\" style=\"stroke: rgb(238, 238, 238); stroke-opacity: 1; stroke-width: 1px;\"/><path class=\"xgrid crisp\" transform=\"translate(114.25,0)\" d=\"M0,82v2\" style=\"stroke: rgb(238, 238, 238); stroke-opacity: 1; stroke-width: 1px;\"/></g><g class=\"y\"/></g><g class=\"zerolinelayer\"><path class=\"xzl zl crisp\" transform=\"translate(85.75,0)\" d=\"M0,82v2\" style=\"stroke: rgb(68, 68, 68); stroke-opacity: 1; stroke-width: 1px;\"/></g><path class=\"xlines-below\"/><path class=\"ylines-below\"/><g class=\"overlines-below\"/><g class=\"xaxislayer-below\"/><g class=\"yaxislayer-below\"/><g class=\"overaxes-below\"/><g class=\"plot\" transform=\"translate(80,82)\" clip-path=\"url('#clip2dc70axyplot')\"><g class=\"scatterlayer mlayer\"><g class=\"trace scatter trace86f735\" style=\"stroke-miterlimit: 2; opacity: 1;\"><g class=\"fills\"/><g class=\"errorbars\"/><g class=\"lines\"><path class=\"js-line\" d=\"M5.75,1L20,0L34.25,2\" style=\"vector-effect: non-scaling-stroke; fill: none; stroke: rgb(31, 119, 180); stroke-opacity: 1; stroke-width: 2px; opacity: 1;\"/></g><g class=\"points\"><path class=\"point\" transform=\"translate(5.75,1)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(20,0)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/><path class=\"point\" transform=\"translate(34.25,2)\" d=\"M3,0A3,3 0 1,1 0,-3A3,3 0 0,1 3,0Z\" style=\"opacity: 1; stroke-width: 0px; fill: rgb(31, 119, 180); fill-opacity: 1;\"/></g><g class=\"text\"/></g></g></g><g class=\"overplot\"/><path class=\"xlines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><path class=\"ylines-above crisp\" d=\"M0,0\" style=\"fill: none;\"/><g class=\"overlines-above\"/><g class=\"xaxislayer-above\"><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(85.75,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">0</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(100,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">1</text></g><g class=\"xtick\"><text text-anchor=\"middle\" x=\"0\" y=\"97\" transform=\"translate(114.25,0)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">2</text></g></g><g class=\"yaxislayer-above\"><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,84)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">2</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,83.5)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">4</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,83)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">6</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,82.5)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">8</text></g><g class=\"ytick\"><text text-anchor=\"end\" x=\"79\" y=\"4.199999999999999\" transform=\"translate(0,82)\" style=\"font-family: 'Open Sans', verdana, arial, sans-serif; font-size: 12px; fill: rgb(68, 68, 68); fill-opacity: 1; white-space: pre;\">10</text></g></g><g class=\"overaxes-above\"/></g></g><g class=\"polarlayer\"/><g class=\"ternarylayer\"/><g class=\"geolayer\"/><g class=\"funnelarealayer\"/><g class=\"pielayer\"/><g class=\"treemaplayer\"/><g class=\"sunburstlayer\"/><g class=\"glimages\"/><defs id=\"topdefs-2dc70a\"><g class=\"clips\"/></defs><g class=\"layer-above\"><g class=\"imagelayer\"/><g class=\"shapelayer\"/></g><g class=\"infolayer\"><g class=\"g-gtitle\"/><g class=\"g-xtitle\"/><g class=\"g-ytitle\"/></g></svg>";
// Limit the test to the first LEN characters
const LEN: usize = 100;
// 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]);
}
}
9 changes: 5 additions & 4 deletions plotly_kaleido/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ impl Kaleido {
let p = p.to_str().unwrap();
let p = String::from(p);

#[allow(clippy::zombie_processes)]
let mut process = Command::new(p.as_str())
.current_dir(self.cmd_path.parent().unwrap())
.args([
Expand Down Expand Up @@ -217,6 +216,8 @@ impl Kaleido {
}
}

process.wait().expect("failed to wait on kaleido process");

Ok(String::default())
}
}
Expand Down Expand Up @@ -279,7 +280,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();
Expand All @@ -291,7 +292,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();
Expand Down Expand Up @@ -340,7 +341,7 @@ mod tests {

// This doesn't work for some reason
#[test]
#[ignore]
// #[ignore]
fn test_save_eps() {
let test_plot = create_test_plot();
let k = Kaleido::new();
Expand Down

0 comments on commit 8b19019

Please sign in to comment.