Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle committed Aug 13, 2024
1 parent 02c9af4 commit 128795c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/serializers/test_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dataclasses
import json
import platform
import warnings
from random import randint
from typing import Any, ClassVar, Dict

Expand Down Expand Up @@ -1080,3 +1081,23 @@ class Model:
m.__pydantic_extra__ = {'extra': 'extra'}

assert s.to_python(m) == {'extra': 'extra bam!'}


def test_no_warn_on_exclude() -> None:
warnings.simplefilter('error')

s = SchemaSerializer(
core_schema.model_schema(
BasicModel,
core_schema.model_fields_schema(
{
'a': core_schema.model_field(core_schema.int_schema()),
'b': core_schema.model_field(core_schema.int_schema()),
}
),
)
)

value = BasicModel(a=0, b=1)
assert s.to_python(value, exclude={'b'}) == {'a': 0}
assert s.to_python(value, mode='json', exclude={'b'}) == {'a': 0}

0 comments on commit 128795c

Please sign in to comment.