Skip to content

Commit

Permalink
fix: Add example and support for compatibility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGotelli committed Aug 24, 2024
1 parent 2f5c2df commit 3f3fac6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 8 additions & 8 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
25 changes: 25 additions & 0 deletions src/tests/examples/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
is_instance,
is_list,
is_number,
is_pydantic,
is_strict_dict,
is_string,
is_uuid,
one_of,
same_value,
)
from src.tests.conftest import CustomEqual
from src.tests.pydantic.conftest import BaseModel


def test_deal_with_custom_equals():
Expand Down Expand Up @@ -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))
2 changes: 2 additions & 0 deletions vulture/whitelist.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -9,3 +10,4 @@

MoneyPersonV2.friends
MoneyPersonV2.debts
test_pydantic().Dog.breed

0 comments on commit 3f3fac6

Please sign in to comment.