@@ -185,20 +185,8 @@ impl Kaleido {
185185 ) -> Result < String , Box < dyn std:: error:: Error > > {
186186 let p = self . cmd_path . to_str ( ) . unwrap ( ) ;
187187
188- #[ cfg( not( target_os = "macos" ) ) ]
189- let cmd_args = vec ! [
190- "plotly" ,
191- "--disable-gpu" ,
192- "--allow-file-access-from-files" ,
193- "--disable-breakpad" ,
194- "--disable-dev-shm-usage" ,
195- "--disable-software-rasterizer" ,
196- "--single-process" ,
197- "--no-sandbox" ,
198- ] ;
199-
200- // Add Kaleido issue #323
201- #[ cfg( target_os = "macos" ) ]
188+ // Removed flag 'disable-gpu' as it causes issues on MacOS and other platforms
189+ // see Kaleido issue #323
202190 let cmd_args = vec ! [
203191 "plotly" ,
204192 "--allow-file-access-from-files" ,
@@ -272,36 +260,6 @@ mod tests {
272260 use super :: * ;
273261
274262 fn create_test_plot ( ) -> Value {
275- to_value ( json ! ( {
276- "data" : [
277- {
278- "type" : "scatter" ,
279- "x" : [ 1 , 2 , 3 , 4 ] ,
280- "y" : [ 10 , 15 , 13 , 17 ] ,
281- "name" : "trace1" ,
282- "mode" : "markers"
283- } ,
284- {
285- "type" : "scatter" ,
286- "x" : [ 2 , 3 , 4 , 5 ] ,
287- "y" : [ 16 , 5 , 11 , 9 ] ,
288- "name" : "trace2" ,
289- "mode" : "lines"
290- } ,
291- {
292- "type" : "scatter" ,
293- "x" : [ 1 , 2 , 3 , 4 ] ,
294- "y" : [ 12 , 9 , 15 , 12 ] ,
295- "name" : "trace3" ,
296- }
297- ] ,
298- "layout" : { }
299- } ) )
300- . unwrap ( )
301- }
302-
303- #[ cfg( target_os = "macos" ) ]
304- fn create_test_surface ( ) -> Value {
305263 to_value ( json ! ( {
306264 "data" : [
307265 {
@@ -361,67 +319,78 @@ mod tests {
361319 assert_eq ! ( to_value( kaleido_data) . unwrap( ) , expected) ;
362320 }
363321
364- // This seems to fail unpredictably on MacOs.
365- #[ cfg( not( target_os = "macos" ) ) ]
322+ // For MacOS failures, see issue #241 and upstream https://github.com/plotly/Kaleido/issues/323 is resolved
366323 #[ test]
367324 fn save_png ( ) {
368325 let test_plot = create_test_plot ( ) ;
369326 let k = Kaleido :: new ( ) ;
370327 let dst = PathBuf :: from ( "example.png" ) ;
371328 let r = k. save ( dst. as_path ( ) , & test_plot, "png" , 1200 , 900 , 4.5 ) ;
372329 assert ! ( r. is_ok( ) ) ;
330+ assert ! ( dst. exists( ) ) ;
331+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
332+ let file_size = metadata. len ( ) ;
333+ assert ! ( file_size > 0 , ) ;
373334 assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
374335 }
375336
376- // This seems to fail unpredictably on MacOs.
377- #[ cfg( not( target_os = "macos" ) ) ]
378337 #[ test]
379338 fn save_jpeg ( ) {
380339 let test_plot = create_test_plot ( ) ;
381340 let k = Kaleido :: new ( ) ;
382341 let dst = PathBuf :: from ( "example.jpeg" ) ;
383342 let r = k. save ( dst. as_path ( ) , & test_plot, "jpeg" , 1200 , 900 , 4.5 ) ;
384343 assert ! ( r. is_ok( ) ) ;
344+ assert ! ( dst. exists( ) ) ;
345+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
346+ let file_size = metadata. len ( ) ;
347+ assert ! ( file_size > 0 , ) ;
385348 assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
386349 }
387350
388- // This seems to fail unpredictably on MacOs.
389- #[ cfg( not( target_os = "macos" ) ) ]
390351 #[ test]
391352 fn save_webp ( ) {
392353 let test_plot = create_test_plot ( ) ;
393354 let k = Kaleido :: new ( ) ;
394355 let dst = PathBuf :: from ( "example.webp" ) ;
395356 let r = k. save ( dst. as_path ( ) , & test_plot, "webp" , 1200 , 900 , 4.5 ) ;
396357 assert ! ( r. is_ok( ) ) ;
358+ assert ! ( dst. exists( ) ) ;
359+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
360+ let file_size = metadata. len ( ) ;
361+ assert ! ( file_size > 0 , ) ;
397362 assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
398363 }
399364
400- // This seems to fail unpredictably on MacOs.
401- #[ cfg( not( target_os = "macos" ) ) ]
402365 #[ test]
403366 fn save_svg ( ) {
404367 let test_plot = create_test_plot ( ) ;
405368 let k = Kaleido :: new ( ) ;
406369 let dst = PathBuf :: from ( "example.svg" ) ;
407370 let r = k. save ( dst. as_path ( ) , & test_plot, "svg" , 1200 , 900 , 4.5 ) ;
408371 assert ! ( r. is_ok( ) ) ;
372+ assert ! ( dst. exists( ) ) ;
373+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
374+ let file_size = metadata. len ( ) ;
375+ assert ! ( file_size > 0 , ) ;
409376 assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
410377 }
411378
412- // This seems to fail unpredictably on MacOs.
413- #[ cfg( not( target_os = "macos" ) ) ]
414379 #[ test]
415380 fn save_pdf ( ) {
416381 let test_plot = create_test_plot ( ) ;
417382 let k = Kaleido :: new ( ) ;
418383 let dst = PathBuf :: from ( "example.pdf" ) ;
419384 let r = k. save ( dst. as_path ( ) , & test_plot, "pdf" , 1200 , 900 , 4.5 ) ;
420385 assert ! ( r. is_ok( ) ) ;
386+ assert ! ( dst. exists( ) ) ;
387+ let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
388+ let file_size = metadata. len ( ) ;
389+ assert ! ( file_size > 0 , ) ;
421390 assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
422391 }
423392
424- // This generates empty eps files for some reason
393+ // Kaleido generates empty eps files
425394 #[ test]
426395 #[ ignore]
427396 fn save_eps ( ) {
@@ -432,76 +401,4 @@ mod tests {
432401 assert ! ( r. is_ok( ) ) ;
433402 assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
434403 }
435-
436- // Issue #241 workaround until https://github.com/plotly/Kaleido/issues/323 is resolved
437- #[ cfg( target_os = "macos" ) ]
438- #[ test]
439- fn save_surface_png ( ) {
440- let test_plot = create_test_surface ( ) ;
441- let k = Kaleido :: new ( ) ;
442- let dst = PathBuf :: from ( "example.png" ) ;
443- let r = k. save ( dst. as_path ( ) , & test_plot, "png" , 1200 , 900 , 4.5 ) ;
444- assert ! ( r. is_ok( ) ) ;
445- assert ! ( dst. exists( ) ) ;
446- let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
447- let file_size = metadata. len ( ) ;
448- assert ! ( file_size > 0 , ) ;
449- assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
450- }
451- #[ cfg( target_os = "macos" ) ]
452- #[ test]
453- fn save_surface_jpeg ( ) {
454- let test_plot = create_test_surface ( ) ;
455- let k = Kaleido :: new ( ) ;
456- let dst = PathBuf :: from ( "example.jpeg" ) ;
457- let r = k. save ( dst. as_path ( ) , & test_plot, "jpeg" , 1200 , 900 , 4.5 ) ;
458- assert ! ( r. is_ok( ) ) ;
459- assert ! ( dst. exists( ) ) ;
460- let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
461- let file_size = metadata. len ( ) ;
462- assert ! ( file_size > 0 , ) ;
463- assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
464- }
465- #[ cfg( target_os = "macos" ) ]
466- #[ test]
467- fn save_surface_webp ( ) {
468- let test_plot = create_test_surface ( ) ;
469- let k = Kaleido :: new ( ) ;
470- let dst = PathBuf :: from ( "example.webp" ) ;
471- let r = k. save ( dst. as_path ( ) , & test_plot, "webp" , 1200 , 900 , 4.5 ) ;
472- assert ! ( r. is_ok( ) ) ;
473- assert ! ( dst. exists( ) ) ;
474- let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
475- let file_size = metadata. len ( ) ;
476- assert ! ( file_size > 0 , ) ;
477- assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
478- }
479- #[ cfg( target_os = "macos" ) ]
480- #[ test]
481- fn save_surface_svg ( ) {
482- let test_plot = create_test_surface ( ) ;
483- let k = Kaleido :: new ( ) ;
484- let dst = PathBuf :: from ( "example.svg" ) ;
485- let r = k. save ( dst. as_path ( ) , & test_plot, "svg" , 1200 , 900 , 4.5 ) ;
486- assert ! ( r. is_ok( ) ) ;
487- assert ! ( dst. exists( ) ) ;
488- let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
489- let file_size = metadata. len ( ) ;
490- assert ! ( file_size > 0 , ) ;
491- assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
492- }
493- #[ cfg( target_os = "macos" ) ]
494- #[ test]
495- fn save_surface_pdf ( ) {
496- let test_plot = create_test_surface ( ) ;
497- let k = Kaleido :: new ( ) ;
498- let dst = PathBuf :: from ( "example.pdf" ) ;
499- let r = k. save ( dst. as_path ( ) , & test_plot, "pdf" , 1200 , 900 , 4.5 ) ;
500- assert ! ( r. is_ok( ) ) ;
501- assert ! ( dst. exists( ) ) ;
502- let metadata = std:: fs:: metadata ( & dst) . expect ( "Could not retrieve file metadata" ) ;
503- let file_size = metadata. len ( ) ;
504- assert ! ( file_size > 0 , ) ;
505- assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
506- }
507404}
0 commit comments