@@ -185,7 +185,7 @@ async def test_write_fig_from_object_bare_dictionary(
185
185
186
186
187
187
@pytest .fixture (scope = "function" )
188
- def test_kaleido ():
188
+ def test_kaleido (): # speed up hypothesis test using a function fixture
189
189
return Kaleido ()
190
190
191
191
@@ -268,6 +268,65 @@ async def test_write_fig_argument_passthrough( # noqa: PLR0913
268
268
assert generated_args ["topojson" ] == topojson , "Topojson should match"
269
269
270
270
271
+ @settings (
272
+ suppress_health_check = [HealthCheck .function_scoped_fixture ],
273
+ max_examples = 50 ,
274
+ )
275
+ @given (
276
+ width = st .integers (min_value = 100 , max_value = 2000 ),
277
+ height = st .integers (min_value = 100 , max_value = 2000 ),
278
+ format_type = st .sampled_from (["png" , "svg" , "pdf" , "html" ]),
279
+ topojson = st .one_of (st .none (), st .text (min_size = 1 , max_size = 20 )),
280
+ )
281
+ async def test_calc_fig_argument_passthrough (
282
+ test_kaleido ,
283
+ width ,
284
+ height ,
285
+ format_type ,
286
+ topojson ,
287
+ ):
288
+ opts = {"format" : format_type , "width" : width , "height" : height }
289
+ fig = {"data" : "test" }
290
+ # Mock write_fig_from_object to capture arguments
291
+ with patch .object (
292
+ Kaleido ,
293
+ "write_fig_from_object" ,
294
+ new = AsyncMock (return_value = []),
295
+ ) as mock_write_fig_from_object :
296
+ await test_kaleido .calc_fig (
297
+ fig ,
298
+ opts = opts ,
299
+ topojson = topojson ,
300
+ )
301
+ # Verify write_fig_from_object was called
302
+ mock_write_fig_from_object .assert_called_once ()
303
+
304
+ # Extract the generator that was passed as first argument
305
+ _ , kwargs = mock_write_fig_from_object .call_args # not sure.
306
+
307
+ generator = kwargs ["fig_dicts" ]
308
+ assert kwargs ["cancel_on_error" ] is True
309
+ assert kwargs ["_write" ] is False
310
+
311
+ # Convert generator to list to inspect its contents
312
+ generated_args_list = [v async for v in generator ]
313
+ assert len (generated_args_list ) == 1 , (
314
+ "Expected generator to yield exactly one item"
315
+ )
316
+
317
+ generated_args = generated_args_list [0 ]
318
+
319
+ # Validate that the generated arguments match what we passed to write_fig
320
+ assert "fig" in generated_args , "Generated args should contain 'fig'"
321
+ assert "opts" in generated_args , "Generated args should contain 'opts'"
322
+ assert "topojson" in generated_args , "Generated args should contain 'topojson'"
323
+
324
+ # Check that the values match
325
+ assert generated_args ["fig" ] == fig , "Figure should match"
326
+ assert generated_args ["opts" ] == opts , "Options should match"
327
+ assert generated_args ["topojson" ] == topojson , "Topojson should match"
328
+
329
+
271
330
async def test_kaleido_instantiate_no_hang ():
272
331
"""Test that instantiating Kaleido doesn't hang."""
273
332
_ = Kaleido ()
0 commit comments