From fe11945a2c74c5904df25f57ababb7ec75959f88 Mon Sep 17 00:00:00 2001 From: Akanksha Trehun Date: Thu, 10 Sep 2026 00:22:28 +0530 Subject: [PATCH] Add tests for two uncovered branches in create_pydantic_model_from_schema The invalid schema to ValueError wrapping path and the array type inside an anyOf variant branch had no test, despite the rest of the file being fairly thorough. Both already worked correctly, ran them before writing the assertions to confirm. Signed-off-by: Akanksha Trehun --- tests/ext/workflow/test_mcp_schema.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/ext/workflow/test_mcp_schema.py b/tests/ext/workflow/test_mcp_schema.py index 6f369b712..6bf7871e4 100644 --- a/tests/ext/workflow/test_mcp_schema.py +++ b/tests/ext/workflow/test_mcp_schema.py @@ -151,6 +151,25 @@ def test_oneof_nullable_integer(self): instance = Model(count=5) self.assertEqual(instance.count, 5) + def test_anyof_array_variant(self): + schema = { + 'type': 'object', + 'properties': { + 'tags': { + 'anyOf': [ + {'type': 'array', 'items': {'type': 'integer'}}, + {'type': 'null'}, + ] + } + }, + 'required': ['tags'], + } + Model = create_pydantic_model_from_schema(schema, 'ArrayVariantModel') + instance = Model(tags=[1, 2, 3]) + self.assertEqual(instance.tags, [1, 2, 3]) + instance2 = Model(tags=None) + self.assertIsNone(instance2.tags) + class TestKwargsUnwrapping(unittest.TestCase): """Tests for the kwargs wrapper unwrapping pattern.""" @@ -228,6 +247,12 @@ def test_returns_pydantic_model_subclass(self): Model = create_pydantic_model_from_schema(schema, 'SubclassCheck') self.assertTrue(issubclass(Model, BaseModel)) + def test_invalid_schema_raises_value_error(self): + schema = {'type': 'object', 'properties': {'x': 'not-a-dict'}} + with self.assertRaises(ValueError) as ctx: + create_pydantic_model_from_schema(schema, 'InvalidModel') + self.assertIn('Invalid schema', str(ctx.exception)) + def test_model_name_set(self): schema = { 'type': 'object',