diff --git a/Makefile b/Makefile index 13b24f6..7af2af2 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ install_hooks: install_shell_support: @scripts/install_shell_support.sh -quality: lint vulture spell black tests +quality: lint vulture spell black compat-coverage coverage format: black $(FOLDERS) @@ -42,6 +42,11 @@ black: coverage: coverage run && coverage report --skip-covered +compat-coverage: + pip install -r requirements_min.txt > /dev/null 2>&1 + -@make coverage + pip install -r requirements_dev.txt > /dev/null 2>&1 + coverage_html: coverage run && coverage html open htmlcov/index.html diff --git a/requirements.txt b/requirements.txt index f8294b5..dbb36df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,11 @@ -atomicwrites==1.4.1 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32" -attrs==24.2.0 ; python_version >= "3.10" and python_version < "4.0" +annotated-types==0.7.0 ; python_version >= "3.10" and python_version < "4.0" colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32" +exceptiongroup==1.2.2 ; python_version >= "3.10" and python_version < "3.11" iniconfig==2.0.0 ; python_version >= "3.10" and python_version < "4.0" packaging==24.1 ; python_version >= "3.10" and python_version < "4.0" pluggy==1.5.0 ; python_version >= "3.10" and python_version < "4.0" -py==1.11.0 ; python_version >= "3.10" and python_version < "4.0" -pydantic==1.0 ; python_version >= "3.10" and python_version < "4.0" -pytest==7.0.0 ; python_version >= "3.10" and python_version < "4.0" -tomli==2.0.1 ; python_version >= "3.10" and python_version < "4.0" +pydantic-core==2.20.1 ; python_version >= "3.10" and python_version < "4.0" +pydantic==2.8.2 ; python_version >= "3.10" and python_version < "4.0" +pytest==8.3.2 ; python_version >= "3.10" and python_version < "4.0" +tomli==2.0.1 ; python_version >= "3.10" and python_version < "3.11" +typing-extensions==4.12.2 ; python_version >= "3.10" and python_version < "4.0" diff --git a/requirements_dev.txt b/requirements_dev.txt index fde1f5a..9584c84 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,12 +1,12 @@ +annotated-types==0.7.0 ; python_version >= "3.10" and python_version < "4.0" astroid==3.2.4 ; python_version >= "3.10" and python_version < "4.0" -atomicwrites==1.4.1 ; python_version >= "3.10" and python_version < "4.0" and sys_platform == "win32" -attrs==24.2.0 ; python_version >= "3.10" and python_version < "4.0" black==24.8.0 ; python_version >= "3.10" and python_version < "4.0" click==8.1.7 ; python_version >= "3.10" and python_version < "4.0" codespell==2.3.0 ; python_version >= "3.10" and python_version < "4.0" colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows") coverage==7.6.1 ; python_version >= "3.10" and python_version < "4.0" dill==0.3.8 ; python_version >= "3.10" and python_version < "4.0" +exceptiongroup==1.2.2 ; python_version >= "3.10" and python_version < "3.11" iniconfig==2.0.0 ; python_version >= "3.10" and python_version < "4.0" isort==5.13.2 ; python_version >= "3.10" and python_version < "4.0" mccabe==0.7.0 ; python_version >= "3.10" and python_version < "4.0" @@ -15,11 +15,11 @@ packaging==24.1 ; python_version >= "3.10" and python_version < "4.0" pathspec==0.12.1 ; python_version >= "3.10" and python_version < "4.0" platformdirs==4.2.2 ; python_version >= "3.10" and python_version < "4.0" pluggy==1.5.0 ; python_version >= "3.10" and python_version < "4.0" -py==1.11.0 ; python_version >= "3.10" and python_version < "4.0" -pydantic==1.0 ; python_version >= "3.10" and python_version < "4.0" +pydantic-core==2.20.1 ; python_version >= "3.10" and python_version < "4.0" +pydantic==2.8.2 ; python_version >= "3.10" and python_version < "4.0" pylint==3.2.6 ; python_version >= "3.10" and python_version < "4.0" -pytest==7.0.0 ; python_version >= "3.10" and python_version < "4.0" -tomli==2.0.1 ; python_version >= "3.10" and python_version < "4.0" -tomlkit==0.13.0 ; python_version >= "3.10" and python_version < "4.0" -typing-extensions==4.12.2 ; python_version >= "3.10" and python_version < "3.11" +pytest==8.3.2 ; python_version >= "3.10" and python_version < "4.0" +tomli==2.0.1 ; python_version >= "3.10" and python_version < "3.11" +tomlkit==0.13.2 ; python_version >= "3.10" and python_version < "4.0" +typing-extensions==4.12.2 ; python_version >= "3.10" and python_version < "4.0" vulture==2.11 ; python_version >= "3.10" and python_version < "4.0" diff --git a/src/tests/examples/test_example.py b/src/tests/examples/test_example.py index 86894c3..31fafa4 100644 --- a/src/tests/examples/test_example.py +++ b/src/tests/examples/test_example.py @@ -19,6 +19,7 @@ is_instance, is_list, is_number, + is_pydantic, is_strict_dict, is_string, is_uuid, @@ -26,6 +27,7 @@ same_value, ) from src.tests.conftest import CustomEqual +from src.tests.pydantic.conftest import BaseModel def test_deal_with_custom_equals(): @@ -215,3 +217,26 @@ def test_uuids(): for uuid_value in (uuid3(NAMESPACE_DNS, "python.org"), uuid4()): assert uuid_value == is_uuid(version=one_of(3, 4)) assert uuid5(NAMESPACE_DNS, "python.org") != is_uuid(version=one_of(3, 4)) + + +def test_pydantic(): + class Animal(BaseModel): # pylint: disable=too-few-public-methods + age: int + name: str + + class Human(Animal): # pylint: disable=too-few-public-methods + money: float = 0 + + class Dog(Animal): # pylint: disable=too-few-public-methods + breed: str = "Mongrel" + + messi = Human(age=33, name="Messi") + lassie = Dog(age=3, name="Lassie", breed="Collie") + tweety = Animal(age=1, name="Tweety") + + assert_match(messi, is_pydantic()) + assert_match(lassie, is_pydantic()) + assert_match(messi, is_pydantic(Human)) + assert_match(lassie, is_pydantic(Dog, age=3, name="Lassie", breed="Collie")) + assert_match(tweety, is_pydantic(age=1)) + assert_match(messi, is_pydantic(Human, age=33, strict=False)) diff --git a/vulture/whitelist.py b/vulture/whitelist.py index 186b51c..1b6ebc2 100644 --- a/vulture/whitelist.py +++ b/vulture/whitelist.py @@ -1,5 +1,6 @@ from pytest_matchers.plugin import pytest_assertrepr_compare from src.tests.conftest import pytest_configure +from src.tests.examples.test_example import test_pydantic from src.tests.pydantic.conftest import MoneyPersonV2 from src.tests.test_plugin import _set_verbosity @@ -9,3 +10,4 @@ MoneyPersonV2.friends MoneyPersonV2.debts +test_pydantic().Dog.breed