Skip to content

Commit

Permalink
Renamed, added another test.
Browse files Browse the repository at this point in the history
  • Loading branch information
NowanIlfideme committed Jun 16, 2023
1 parent faa93b7 commit b3bc1d0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/test/test_settings.py → src/test/test_strict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test issue with settings."""
"""Test strict models and BaseSettings subclasses."""

import pytest
from pydantic import BaseModel, BaseSettings
Expand All @@ -20,10 +20,30 @@ class ExModel(BaseModel):
settings: ExSettings


class StrictModel(BaseModel):
"""Strict no-extras values."""

val: str

class Config:
"""Pydantic model configuration."""

extra = "forbid"


@pytest.mark.parametrize("format", ["auto", "zip", "folder", "yaml", "json"])
def test_rt_settings(tmpdir: str, format: Literal["auto", "zip", "folder", "yaml", "json"]):
"""Test settings round-trip."""
obj = ExModel(settings=ExSettings(val="val"))
save_model(obj, f"{tmpdir}/obj", format=format)
obj2 = load_model(f"{tmpdir}/obj", ExModel)
assert obj.settings == obj2.settings


@pytest.mark.parametrize("format", ["auto", "zip", "folder", "yaml", "json"])
def test_rt_strict_model(tmpdir: str, format: Literal["auto", "zip", "folder", "yaml", "json"]):
"""Test strict_model round-trip."""
obj = StrictModel(val="val")
save_model(obj, f"{tmpdir}/obj", format=format)
obj2 = load_model(f"{tmpdir}/obj", StrictModel)
assert obj.val == obj2.val

0 comments on commit b3bc1d0

Please sign in to comment.