From 12f3f6184bad65fcc5740fe71e7a8c55f67ee37e Mon Sep 17 00:00:00 2001 From: Pepa <9963200+07pepa@users.noreply.github.com> Date: Tue, 3 Sep 2024 00:31:27 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20deprecate=20`semver`=20in=20favor?= =?UTF-8?q?=20of=20`semantic=5Fversion`=20(#209)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fold test from semver to semantic_version so it can just be deleted * extend test cases Co-authored-by: 07pepa --- pydantic_extra_types/semver.py | 6 ++++++ pyproject.toml | 5 +++-- tests/test_semantic_version.py | 12 +++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pydantic_extra_types/semver.py b/pydantic_extra_types/semver.py index 46e68993..3418ec93 100644 --- a/pydantic_extra_types/semver.py +++ b/pydantic_extra_types/semver.py @@ -12,11 +12,17 @@ else: from typing import Annotated # pragma: no cover +import warnings + from pydantic import GetJsonSchemaHandler from pydantic.json_schema import JsonSchemaValue from pydantic_core import core_schema from semver import Version +warnings.warn( + 'Use from pydantic_extra_types.semver import SemanticVersion instead. Will be removed in 3.0.0.', DeprecationWarning +) + class _VersionPydanticAnnotation(Version): """ diff --git a/pyproject.toml b/pyproject.toml index 899b9b56..89d416d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ classifiers = [ 'Topic :: Internet', ] requires-python = '>=3.8' -dependencies = ['pydantic>=2.5.2'] +dependencies = ['pydantic>=2.5.2','typing-extensions'] dynamic = ['version'] [project.optional-dependencies] @@ -123,7 +123,8 @@ filterwarnings = [ # This ignore will be removed when pycountry will drop py36 & support py311 'ignore:::pkg_resources', # This ignore will be removed when pendulum fixes https://github.com/sdispater/pendulum/issues/834 - 'ignore:datetime.datetime.utcfromtimestamp.*:DeprecationWarning' + 'ignore:datetime.datetime.utcfromtimestamp.*:DeprecationWarning', + ' ignore:Use from pydantic_extra_types.semver import SemanticVersion instead. Will be removed in 3.0.0.:DeprecationWarning' ] # configuring https://github.com/pydantic/hooky diff --git a/tests/test_semantic_version.py b/tests/test_semantic_version.py index dc79bef1..4df76a35 100644 --- a/tests/test_semantic_version.py +++ b/tests/test_semantic_version.py @@ -12,12 +12,14 @@ class Application(BaseModel): return Application -def test_valid_semantic_version(SemanticVersionObject): - application = SemanticVersionObject(version='1.0.0') +@pytest.mark.parametrize('version', ['1.0.0', '1.0.0-alpha.1', '1.0.0-alpha.1+build.1', '1.2.3']) +def test_valid_semantic_version(SemanticVersionObject, version): + application = SemanticVersionObject(version=version) assert application.version - assert application.model_dump() == {'version': '1.0.0'} + assert application.model_dump() == {'version': version} -def test_invalid_semantic_version(SemanticVersionObject): +@pytest.mark.parametrize('invalid_version', ['no dots string', 'with.dots.string', '']) +def test_invalid_semantic_version(SemanticVersionObject, invalid_version): with pytest.raises(ValidationError): - SemanticVersionObject(version='Peter Maffay') + SemanticVersionObject(version=invalid_version)