-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
167ccf9
commit 6efa641
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |