Skip to content

Commit

Permalink
Added test for v2-v1 compatibilty.
Browse files Browse the repository at this point in the history
  • Loading branch information
NowanIlfideme committed Mar 29, 2024
1 parent 167ccf9 commit 6efa641
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/test_v2_v1_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Tests for Pydantic v2-v1 compatibility."""

import pytest

from pydantic.version import VERSION as PYDANTIC_VERSION
from pydantic_yaml import to_yaml_str, parse_yaml_raw_as


@pytest.mark.skipif(PYDANTIC_VERSION < "2", reason="Only supported for Pydantic v2.")
def test_pydantic_v2_v1_compat() -> None:
"""Test v1-compatibility in pydantic v2."""
from pydantic.v1 import BaseModel

class MyModel(BaseModel):
"""Simple model for dumping."""

v: str = "vee"

yml = to_yaml_str(MyModel(v="tree")) # type: ignore
obj = parse_yaml_raw_as(MyModel, yml) # type: ignore
assert obj.v == "tree"

0 comments on commit 6efa641

Please sign in to comment.