From 7528d6ae10427c1304e356cf5b3c664e4fb2b1b1 Mon Sep 17 00:00:00 2001 From: aaronvg Date: Thu, 18 Jul 2024 10:25:51 -0700 Subject: [PATCH] Add test for dynamic list input (#798) --- integ-tests/python/tests/test_functions.py | 42 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/integ-tests/python/tests/test_functions.py b/integ-tests/python/tests/test_functions.py index 55aeceb39..4a0dfd567 100644 --- a/integ-tests/python/tests/test_functions.py +++ b/integ-tests/python/tests/test_functions.py @@ -107,16 +107,13 @@ async def test_should_work_with_image_url(): ) assert_that(res.lower()).matches(r"(green|yellow|shrek|ogre)") + @pytest.mark.asyncio async def test_should_work_with_vertex(): - res = await b.TestVertex( - "donkey kong" - - ) + res = await b.TestVertex("donkey kong") assert_that("donkey kong" in res.lower()) - @pytest.mark.asyncio async def test_should_work_with_image_base64(): res = await b.TestImageInput(img=baml_py.Image.from_base64("image/png", image_b64)) @@ -558,6 +555,41 @@ async def test_stream_dynamic_class_output(): assert final.hair_color == "black" +@pytest.mark.asyncio +async def test_dynamic_inputs_list(): + tb = TypeBuilder() + tb.DynInputOutput.add_property("new_key", tb.string().optional()) + custom_class = tb.add_class("MyBlah") + custom_class.add_property("nestedKey1", tb.string()) + tb.DynInputOutput.add_property("blah", custom_class.type()) + + res = await b.DynamicListInputOutput( + [ + { + "new_key": "hi", + "testKey": "myTest", + "blah": { + "nestedKey1": "nestedVal", + }, + }, + { + "new_key": "hi", + "testKey": "myTest", + "blah": { + "nestedKey1": "nestedVal", + }, + }, + ], + {"tb": tb}, + ) + assert res[0].new_key == "hi" + assert res[0].testKey == "myTest" + assert res[0].blah["nestedKey1"] == "nestedVal" + assert res[1].new_key == "hi" + assert res[1].testKey == "myTest" + assert res[1].blah["nestedKey1"] == "nestedVal" + + @pytest.mark.asyncio async def test_nested_class_streaming(): stream = b.stream.FnOutputClassNested(