Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add compat for pydantic v2 #169

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions menuinst/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
from pprint import pprint
from typing import Dict, List, Literal, Optional, Union

from pydantic import BaseModel as _BaseModel
from pydantic import Field, conlist, constr
try:
from pydantic.v1 import BaseModel as _BaseModel
from pydantic.v1 import Field, conlist, constr
except ImportError:
# pydantic v1
from pydantic import BaseModel as _BaseModel
from pydantic import Field, conlist, constr


log = getLogger(__name__)

Expand Down
19 changes: 19 additions & 0 deletions news/169-pydantic
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* Add support for `pydantic` v2 in `menuinst._schema`. (#166 via #169)
2 changes: 1 addition & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test:
- conda
- pytest
- pytest-cov
- pydantic <2.0a0
- pydantic
- hypothesis
- hypothesis-jsonschema
source_files:
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
python
pip
conda
pydantic<2.0a0
pydantic
pytest
pytest-cov
hypothesis
Expand Down
9 changes: 6 additions & 3 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

# from hypothesis import given, settings, HealthCheck
# from hypothesis_jsonschema import from_schema
from pydantic import ValidationError
from pydantic import ValidationError as ValidationErrorV2
from pydantic.v1 import ValidationError as ValidationErrorV1

from menuinst._schema import BasePlatformSpecific, MenuItem, validate

Expand All @@ -14,10 +15,12 @@
# assert value


@pytest.mark.parametrize("path", (DATA / "jsons").glob("*.json"))
@pytest.mark.parametrize(
"path", [pytest.param(path, id=path.name) for path in sorted((DATA / "jsons").glob("*.json"))]
)
def test_examples(path):
if "invalid" in path.name:
with pytest.raises(ValidationError):
with pytest.raises((ValidationErrorV1, ValidationErrorV2)):
assert validate(path)
else:
assert validate(path)
Expand Down
Loading