mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
15850a43c5
* moving to black * put back flake8 * remove isort option * putting back isort * uprev pycodestyle * remove black from docs/examples * tweak parse.py
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import abc
|
|
|
|
import pytest
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
def test_model_subclassing_abstract_base_classes():
|
|
class Model(BaseModel, abc.ABC):
|
|
some_field: str
|
|
|
|
|
|
def test_model_subclassing_abstract_base_classes_without_implementation_raises_exception():
|
|
class Model(BaseModel, abc.ABC):
|
|
some_field: str
|
|
|
|
@abc.abstractmethod
|
|
def my_abstract_method(self):
|
|
pass
|
|
|
|
@classmethod
|
|
@abc.abstractmethod
|
|
def my_abstract_classmethod(cls):
|
|
pass
|
|
|
|
@staticmethod
|
|
@abc.abstractmethod
|
|
def my_abstract_staticmethod():
|
|
pass
|
|
|
|
@property
|
|
@abc.abstractmethod
|
|
def my_abstract_property(self):
|
|
pass
|
|
|
|
@my_abstract_property.setter
|
|
@abc.abstractmethod
|
|
def my_abstract_property(self, val):
|
|
pass
|
|
|
|
with pytest.raises(TypeError) as excinfo:
|
|
Model(some_field='some_value')
|
|
assert (
|
|
str(excinfo.value) == "Can't instantiate abstract class Model with abstract methods"
|
|
" my_abstract_classmethod, my_abstract_method, my_abstract_property, my_abstract_staticmethod"
|
|
)
|