From c77860d9d411c0c3742de2c78a5ed4d4f2e706b6 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Sun, 10 Dec 2023 14:32:04 +0100 Subject: [PATCH 1/3] add compat for pydantic v2 --- menuinst/_schema.py | 10 ++++++++-- recipe/meta.yaml | 2 +- tests/requirements.txt | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) 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/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 From 979291f63792b9eb53650a7b04499866aec4dee6 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Sun, 10 Dec 2023 14:34:01 +0100 Subject: [PATCH 2/3] add news --- news/169-pydantic | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/169-pydantic 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) From 6791ad95f451d24b9bd6ea0aa828635c429b329f Mon Sep 17 00:00:00 2001 From: jaimergp Date: Mon, 11 Dec 2023 12:08:11 +0100 Subject: [PATCH 3/3] fix test --- tests/test_schema.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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)