@@ -386,92 +386,93 @@ async def input_iter(_: Any) -> AsyncIterator[BaseMessage]:
386
386
return input_iter
387
387
388
388
389
- def test_partial_json_output_parser () -> None :
390
- for use_tool_calls in [False , True ]:
391
- input_iter = _get_iter (use_tool_calls = use_tool_calls )
392
- chain = input_iter | JsonOutputToolsParser ()
393
-
394
- actual = list (chain .stream (None ))
395
- expected : list = [[]] + [
396
- [{"type" : "NameCollector" , "args" : chunk }]
397
- for chunk in EXPECTED_STREAMED_JSON
398
- ]
399
- assert actual == expected
389
+ @pytest .mark .parametrize ("use_tool_calls" , [False , True ])
390
+ def test_partial_json_output_parser (* , use_tool_calls : bool ) -> None :
391
+ input_iter = _get_iter (use_tool_calls = use_tool_calls )
392
+ chain = input_iter | JsonOutputToolsParser ()
393
+
394
+ actual = list (chain .stream (None ))
395
+ expected : list = [[]] + [
396
+ [{"type" : "NameCollector" , "args" : chunk }] for chunk in EXPECTED_STREAMED_JSON
397
+ ]
398
+ assert actual == expected
400
399
401
400
402
- async def test_partial_json_output_parser_async () -> None :
403
- for use_tool_calls in [ False , True ] :
404
- input_iter = _get_aiter (use_tool_calls = use_tool_calls )
405
- chain = input_iter | JsonOutputToolsParser ()
401
+ @ pytest . mark . parametrize ( "use_tool_calls" , [ False , True ])
402
+ async def test_partial_json_output_parser_async ( * , use_tool_calls : bool ) -> None :
403
+ input_iter = _get_aiter (use_tool_calls = use_tool_calls )
404
+ chain = input_iter | JsonOutputToolsParser ()
406
405
407
- actual = [p async for p in chain .astream (None )]
408
- expected : list = [[]] + [
409
- [{"type" : "NameCollector" , "args" : chunk }]
410
- for chunk in EXPECTED_STREAMED_JSON
411
- ]
412
- assert actual == expected
406
+ actual = [p async for p in chain .astream (None )]
407
+ expected : list = [[]] + [
408
+ [{"type" : "NameCollector" , "args" : chunk }] for chunk in EXPECTED_STREAMED_JSON
409
+ ]
410
+ assert actual == expected
413
411
414
412
415
- def test_partial_json_output_parser_return_id () -> None :
416
- for use_tool_calls in [ False , True ] :
417
- input_iter = _get_iter (use_tool_calls = use_tool_calls )
418
- chain = input_iter | JsonOutputToolsParser (return_id = True )
413
+ @ pytest . mark . parametrize ( "use_tool_calls" , [ False , True ])
414
+ def test_partial_json_output_parser_return_id ( * , use_tool_calls : bool ) -> None :
415
+ input_iter = _get_iter (use_tool_calls = use_tool_calls )
416
+ chain = input_iter | JsonOutputToolsParser (return_id = True )
419
417
420
- actual = list (chain .stream (None ))
421
- expected : list = [[]] + [
422
- [
423
- {
424
- "type" : "NameCollector" ,
425
- "args" : chunk ,
426
- "id" : "call_OwL7f5PEPJTYzw9sQlNJtCZl" ,
427
- }
428
- ]
429
- for chunk in EXPECTED_STREAMED_JSON
418
+ actual = list (chain .stream (None ))
419
+ expected : list = [[]] + [
420
+ [
421
+ {
422
+ "type" : "NameCollector" ,
423
+ "args" : chunk ,
424
+ "id" : "call_OwL7f5PEPJTYzw9sQlNJtCZl" ,
425
+ }
430
426
]
431
- assert actual == expected
427
+ for chunk in EXPECTED_STREAMED_JSON
428
+ ]
429
+ assert actual == expected
432
430
433
431
434
- def test_partial_json_output_key_parser () -> None :
435
- for use_tool_calls in [ False , True ] :
436
- input_iter = _get_iter (use_tool_calls = use_tool_calls )
437
- chain = input_iter | JsonOutputKeyToolsParser (key_name = "NameCollector" )
432
+ @ pytest . mark . parametrize ( "use_tool_calls" , [ False , True ])
433
+ def test_partial_json_output_key_parser ( * , use_tool_calls : bool ) -> None :
434
+ input_iter = _get_iter (use_tool_calls = use_tool_calls )
435
+ chain = input_iter | JsonOutputKeyToolsParser (key_name = "NameCollector" )
438
436
439
- actual = list (chain .stream (None ))
440
- expected : list = [[]] + [[chunk ] for chunk in EXPECTED_STREAMED_JSON ]
441
- assert actual == expected
437
+ actual = list (chain .stream (None ))
438
+ expected : list = [[]] + [[chunk ] for chunk in EXPECTED_STREAMED_JSON ]
439
+ assert actual == expected
442
440
443
441
444
- async def test_partial_json_output_parser_key_async () -> None :
445
- for use_tool_calls in [ False , True ] :
446
- input_iter = _get_aiter (use_tool_calls = use_tool_calls )
442
+ @ pytest . mark . parametrize ( "use_tool_calls" , [ False , True ])
443
+ async def test_partial_json_output_parser_key_async ( * , use_tool_calls : bool ) -> None :
444
+ input_iter = _get_aiter (use_tool_calls = use_tool_calls )
447
445
448
- chain = input_iter | JsonOutputKeyToolsParser (key_name = "NameCollector" )
446
+ chain = input_iter | JsonOutputKeyToolsParser (key_name = "NameCollector" )
449
447
450
- actual = [p async for p in chain .astream (None )]
451
- expected : list = [[]] + [[chunk ] for chunk in EXPECTED_STREAMED_JSON ]
452
- assert actual == expected
448
+ actual = [p async for p in chain .astream (None )]
449
+ expected : list = [[]] + [[chunk ] for chunk in EXPECTED_STREAMED_JSON ]
450
+ assert actual == expected
453
451
454
452
455
- def test_partial_json_output_key_parser_first_only () -> None :
456
- for use_tool_calls in [ False , True ] :
457
- input_iter = _get_iter (use_tool_calls = use_tool_calls )
453
+ @ pytest . mark . parametrize ( "use_tool_calls" , [ False , True ])
454
+ def test_partial_json_output_key_parser_first_only ( * , use_tool_calls : bool ) -> None :
455
+ input_iter = _get_iter (use_tool_calls = use_tool_calls )
458
456
459
- chain = input_iter | JsonOutputKeyToolsParser (
460
- key_name = "NameCollector" , first_tool_only = True
461
- )
457
+ chain = input_iter | JsonOutputKeyToolsParser (
458
+ key_name = "NameCollector" , first_tool_only = True
459
+ )
462
460
463
- assert list (chain .stream (None )) == EXPECTED_STREAMED_JSON
461
+ assert list (chain .stream (None )) == EXPECTED_STREAMED_JSON
464
462
465
463
466
- async def test_partial_json_output_parser_key_async_first_only () -> None :
467
- for use_tool_calls in [False , True ]:
468
- input_iter = _get_aiter (use_tool_calls = use_tool_calls )
464
+ @pytest .mark .parametrize ("use_tool_calls" , [False , True ])
465
+ async def test_partial_json_output_parser_key_async_first_only (
466
+ * ,
467
+ use_tool_calls : bool ,
468
+ ) -> None :
469
+ input_iter = _get_aiter (use_tool_calls = use_tool_calls )
469
470
470
- chain = input_iter | JsonOutputKeyToolsParser (
471
- key_name = "NameCollector" , first_tool_only = True
472
- )
471
+ chain = input_iter | JsonOutputKeyToolsParser (
472
+ key_name = "NameCollector" , first_tool_only = True
473
+ )
473
474
474
- assert [p async for p in chain .astream (None )] == EXPECTED_STREAMED_JSON
475
+ assert [p async for p in chain .astream (None )] == EXPECTED_STREAMED_JSON
475
476
476
477
477
478
class Person (BaseModel ):
0 commit comments