From fcfe2d398b6462b9834fa4af3d80ff109b33152b Mon Sep 17 00:00:00 2001 From: Alexander Tikhonov Date: Sat, 23 Nov 2024 14:30:27 +0300 Subject: [PATCH] Add more tests --- .../test_jsonschema_plugins.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/test_jsonschema/test_jsonschema_plugins.py b/tests/test_jsonschema/test_jsonschema_plugins.py index 2a58bfb..2723b46 100644 --- a/tests/test_jsonschema/test_jsonschema_plugins.py +++ b/tests/test_jsonschema/test_jsonschema_plugins.py @@ -4,7 +4,11 @@ import pytest from mashumaro.jsonschema.builder import JSONSchemaBuilder, build_json_schema -from mashumaro.jsonschema.models import Context, JSONSchema +from mashumaro.jsonschema.models import ( + Context, + JSONSchema, + JSONSchemaInstanceType, +) from mashumaro.jsonschema.plugins import BasePlugin, DocstringDescriptionPlugin from mashumaro.jsonschema.schema import Instance @@ -25,6 +29,30 @@ class DataClassWithoutDocstring: x: int +def test_basic_plugin(): + assert build_json_schema(int, plugins=[BasePlugin()]) == JSONSchema( + type=JSONSchemaInstanceType.INTEGER + ) + + +def test_plugin_with_not_implemented_error(): + class NotImplementedErrorPlugin(BasePlugin): + def get_schema( + self, + instance: Instance, + ctx: Context, + schema: Optional[JSONSchema] = None, + ) -> Optional[JSONSchema]: + raise NotImplementedError + + assert build_json_schema( + int, plugins=[NotImplementedErrorPlugin()] + ) == JSONSchema(type=JSONSchemaInstanceType.INTEGER) + assert JSONSchemaBuilder(plugins=[NotImplementedErrorPlugin()]).build( + int + ) == JSONSchema(type=JSONSchemaInstanceType.INTEGER) + + @pytest.mark.parametrize( ("obj", "docstring"), (