@@ -185,20 +185,8 @@ impl Kaleido {
185
185
) -> Result < String , Box < dyn std:: error:: Error > > {
186
186
let p = self . cmd_path . to_str ( ) . unwrap ( ) ;
187
187
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
202
190
let cmd_args = vec ! [
203
191
"plotly" ,
204
192
"--allow-file-access-from-files" ,
@@ -272,36 +260,6 @@ mod tests {
272
260
use super :: * ;
273
261
274
262
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 {
305
263
to_value ( json ! ( {
306
264
"data" : [
307
265
{
@@ -361,67 +319,78 @@ mod tests {
361
319
assert_eq ! ( to_value( kaleido_data) . unwrap( ) , expected) ;
362
320
}
363
321
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
366
323
#[ test]
367
324
fn save_png ( ) {
368
325
let test_plot = create_test_plot ( ) ;
369
326
let k = Kaleido :: new ( ) ;
370
327
let dst = PathBuf :: from ( "example.png" ) ;
371
328
let r = k. save ( dst. as_path ( ) , & test_plot, "png" , 1200 , 900 , 4.5 ) ;
372
329
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 , ) ;
373
334
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
374
335
}
375
336
376
- // This seems to fail unpredictably on MacOs.
377
- #[ cfg( not( target_os = "macos" ) ) ]
378
337
#[ test]
379
338
fn save_jpeg ( ) {
380
339
let test_plot = create_test_plot ( ) ;
381
340
let k = Kaleido :: new ( ) ;
382
341
let dst = PathBuf :: from ( "example.jpeg" ) ;
383
342
let r = k. save ( dst. as_path ( ) , & test_plot, "jpeg" , 1200 , 900 , 4.5 ) ;
384
343
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 , ) ;
385
348
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
386
349
}
387
350
388
- // This seems to fail unpredictably on MacOs.
389
- #[ cfg( not( target_os = "macos" ) ) ]
390
351
#[ test]
391
352
fn save_webp ( ) {
392
353
let test_plot = create_test_plot ( ) ;
393
354
let k = Kaleido :: new ( ) ;
394
355
let dst = PathBuf :: from ( "example.webp" ) ;
395
356
let r = k. save ( dst. as_path ( ) , & test_plot, "webp" , 1200 , 900 , 4.5 ) ;
396
357
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 , ) ;
397
362
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
398
363
}
399
364
400
- // This seems to fail unpredictably on MacOs.
401
- #[ cfg( not( target_os = "macos" ) ) ]
402
365
#[ test]
403
366
fn save_svg ( ) {
404
367
let test_plot = create_test_plot ( ) ;
405
368
let k = Kaleido :: new ( ) ;
406
369
let dst = PathBuf :: from ( "example.svg" ) ;
407
370
let r = k. save ( dst. as_path ( ) , & test_plot, "svg" , 1200 , 900 , 4.5 ) ;
408
371
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 , ) ;
409
376
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
410
377
}
411
378
412
- // This seems to fail unpredictably on MacOs.
413
- #[ cfg( not( target_os = "macos" ) ) ]
414
379
#[ test]
415
380
fn save_pdf ( ) {
416
381
let test_plot = create_test_plot ( ) ;
417
382
let k = Kaleido :: new ( ) ;
418
383
let dst = PathBuf :: from ( "example.pdf" ) ;
419
384
let r = k. save ( dst. as_path ( ) , & test_plot, "pdf" , 1200 , 900 , 4.5 ) ;
420
385
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 , ) ;
421
390
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
422
391
}
423
392
424
- // This generates empty eps files for some reason
393
+ // Kaleido generates empty eps files
425
394
#[ test]
426
395
#[ ignore]
427
396
fn save_eps ( ) {
@@ -432,76 +401,4 @@ mod tests {
432
401
assert ! ( r. is_ok( ) ) ;
433
402
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
434
403
}
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
- }
507
404
}
0 commit comments