Skip to content

Commit

Permalink
✨ deprecate semver in favor of semantic_version (#209)
Browse files Browse the repository at this point in the history
* fold test from semver to semantic_version so it can just be deleted
* extend test cases

Co-authored-by: 07pepa <pepe@wont_share.com>
  • Loading branch information
07pepa and 07pepa authored Sep 2, 2024
1 parent d409bfa commit 12f3f61
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pydantic_extra_types/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions tests/test_semantic_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 12f3f61

Please sign in to comment.