@@ -183,9 +183,9 @@ impl Kaleido {
183
183
184
184
#[ cfg( test) ]
185
185
mod tests {
186
- use std:: path:: PathBuf ;
187
-
188
186
use serde_json:: { json, to_value} ;
187
+ use std:: path:: PathBuf ;
188
+ use std:: thread;
189
189
190
190
use super :: * ;
191
191
@@ -218,6 +218,14 @@ mod tests {
218
218
. unwrap ( )
219
219
}
220
220
221
+ fn delay_file_check ( ) {
222
+ #[ cfg( target_os = "linux" ) ]
223
+ let delay = std:: time:: Duration :: from_millis ( 0 ) ;
224
+ #[ cfg( not( target_os = "linux" ) ) ]
225
+ let delay = std:: time:: Duration :: from_millis ( 100 ) ;
226
+ thread:: sleep ( delay) ;
227
+ }
228
+
221
229
#[ test]
222
230
fn test_can_find_kaleido_executable ( ) {
223
231
let _k = Kaleido :: new ( ) ;
@@ -238,62 +246,67 @@ mod tests {
238
246
assert_eq ! ( to_value( kaleido_data) . unwrap( ) , expected) ;
239
247
}
240
248
241
- #[ cfg( not( target_os = "windows" ) ) ]
249
+ // #[cfg(not(target_os = "windows"))]
242
250
#[ test]
243
251
fn test_save_png ( ) {
244
252
let test_plot = create_test_plot ( ) ;
245
253
let k = Kaleido :: new ( ) ;
246
254
let dst = PathBuf :: from ( "example.png" ) ;
247
255
let r = k. save ( dst. as_path ( ) , & test_plot, "png" , 1200 , 900 , 4.5 ) ;
248
256
assert ! ( r. is_ok( ) ) ;
257
+ delay_file_check ( ) ;
249
258
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
250
259
}
251
260
252
- #[ cfg( not( target_os = "windows" ) ) ]
261
+ // #[cfg(not(target_os = "windows"))]
253
262
#[ test]
254
263
fn test_save_jpeg ( ) {
255
264
let test_plot = create_test_plot ( ) ;
256
265
let k = Kaleido :: new ( ) ;
257
266
let dst = PathBuf :: from ( "example.jpeg" ) ;
258
267
let r = k. save ( dst. as_path ( ) , & test_plot, "jpeg" , 1200 , 900 , 4.5 ) ;
259
268
assert ! ( r. is_ok( ) ) ;
269
+ delay_file_check ( ) ;
260
270
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
261
271
}
262
272
263
- #[ cfg( not( target_os = "windows" ) ) ]
273
+ // #[cfg(not(target_os = "windows"))]
264
274
#[ test]
265
275
fn test_save_webp ( ) {
266
276
let test_plot = create_test_plot ( ) ;
267
277
let k = Kaleido :: new ( ) ;
268
278
let dst = PathBuf :: from ( "example.webp" ) ;
269
279
let r = k. save ( dst. as_path ( ) , & test_plot, "webp" , 1200 , 900 , 4.5 ) ;
270
280
assert ! ( r. is_ok( ) ) ;
281
+ delay_file_check ( ) ;
271
282
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
272
283
}
273
284
274
- #[ cfg( not( target_os = "windows" ) ) ]
285
+ // #[cfg(not(target_os = "windows"))]
275
286
#[ test]
276
287
fn test_save_svg ( ) {
277
288
let test_plot = create_test_plot ( ) ;
278
289
let k = Kaleido :: new ( ) ;
279
290
let dst = PathBuf :: from ( "example.svg" ) ;
280
291
let r = k. save ( dst. as_path ( ) , & test_plot, "svg" , 1200 , 900 , 4.5 ) ;
281
292
assert ! ( r. is_ok( ) ) ;
293
+ delay_file_check ( ) ;
282
294
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
283
295
}
284
296
285
- #[ cfg( not( target_os = "windows" ) ) ]
297
+ // #[cfg(not(target_os = "windows"))]
286
298
#[ test]
287
299
fn test_save_pdf ( ) {
288
300
let test_plot = create_test_plot ( ) ;
289
301
let k = Kaleido :: new ( ) ;
290
302
let dst = PathBuf :: from ( "example.pdf" ) ;
291
303
let r = k. save ( dst. as_path ( ) , & test_plot, "pdf" , 1200 , 900 , 4.5 ) ;
292
304
assert ! ( r. is_ok( ) ) ;
305
+ delay_file_check ( ) ;
293
306
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
294
307
}
295
308
296
- #[ cfg( not( target_os = "windows" ) ) ]
309
+ // #[cfg(not(target_os = "windows"))]
297
310
#[ test]
298
311
#[ ignore]
299
312
fn test_save_eps ( ) {
@@ -302,6 +315,7 @@ mod tests {
302
315
let dst = PathBuf :: from ( "example.eps" ) ;
303
316
let r = k. save ( dst. as_path ( ) , & test_plot, "eps" , 1200 , 900 , 4.5 ) ;
304
317
assert ! ( r. is_ok( ) ) ;
318
+ delay_file_check ( ) ;
305
319
assert ! ( std:: fs:: remove_file( dst. as_path( ) ) . is_ok( ) ) ;
306
320
}
307
321
}
0 commit comments