Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatal1ty committed Nov 23, 2024
1 parent 24403f7 commit fcfe2d3
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/test_jsonschema/test_jsonschema_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"),
(
Expand Down

0 comments on commit fcfe2d3

Please sign in to comment.