diff --git a/menuinst/_schema.py b/menuinst/_schema.py index 522c6ef6..41e13799 100644 --- a/menuinst/_schema.py +++ b/menuinst/_schema.py @@ -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__) diff --git a/news/169-pydantic b/news/169-pydantic new file mode 100644 index 00000000..1f55ae5c --- /dev/null +++ b/news/169-pydantic @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* Add support for `pydantic` v2 in `menuinst._schema`. (#166 via #169) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index d36db425..e2c8b621 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -38,7 +38,7 @@ test: - conda - pytest - pytest-cov - - pydantic <2.0a0 + - pydantic - hypothesis - hypothesis-jsonschema source_files: diff --git a/tests/requirements.txt b/tests/requirements.txt index 5b82fa09..069186a1 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,7 +1,7 @@ python pip conda -pydantic<2.0a0 +pydantic pytest pytest-cov hypothesis diff --git a/tests/test_schema.py b/tests/test_schema.py index 6819c1b7..32e86e2c 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -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 @@ -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)