From 3a8ca951db1d4f6850ebd7ee4c376a9a32ba75b6 Mon Sep 17 00:00:00 2001 From: Vitor Hideyoshi Date: Mon, 24 Nov 2025 19:52:54 -0300 Subject: [PATCH] feat: adds tests for isolation method in ref_cache --- tests/test_schema_converter.py | 41 ++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/tests/test_schema_converter.py b/tests/test_schema_converter.py index a5cd948..ce799cb 100644 --- a/tests/test_schema_converter.py +++ b/tests/test_schema_converter.py @@ -16,8 +16,7 @@ def is_pydantic_model(cls): class TestSchemaConverter(TestCase): def setUp(self): - self.ref_cache = {} - self.converter = SchemaConverter(ref_cache=self.ref_cache) + self.converter = SchemaConverter() def tearDown(self): self.converter.clear_ref_cache() @@ -881,6 +880,44 @@ class TestSchemaConverter(TestCase): self.assertIs(converter1._ref_cache, converter2._ref_cache) self.assertIs(model1, model2) + def test_instance_level_ref_cache_isolation_via_without_cache_param(self): + schema = { + "title": "Person", + "type": "object", + "properties": { + "name": {"type": "string"}, + "age": {"type": "integer"}, + "emergency_contact": { + "$ref": "#", + }, + }, + "required": ["name", "age"], + } + + model1 = self.converter.build_with_instance(schema, without_cache=True) + model2 = self.converter.build_with_instance(schema, without_cache=True) + + self.assertIsNot(model1, model2) + + def test_instance_level_ref_cache_isolation_via_provided_cache(self): + schema = { + "title": "Person", + "type": "object", + "properties": { + "name": {"type": "string"}, + "age": {"type": "integer"}, + "emergency_contact": { + "$ref": "#", + }, + }, + "required": ["name", "age"], + } + + model1 = self.converter.build_with_instance(schema, ref_cache={}) + model2 = self.converter.build_with_instance(schema, ref_cache={}) + + self.assertIsNot(model1, model2) + def test_get_type_from_cache(self): schema = { "title": "Person",