Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests on inheritance and class methods excecution #4

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/test_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,28 @@ class Location(BaseModel, metaclass=ExtendableModelMeta):

schema = Location.schema()
assert schema is not None


def test_inheritance_class_method(test_registry):
class Base(BaseModel, metaclass=ExtendableModelMeta):
@classmethod
def test(cls):
return "base"

class Intermediate(Base):
...

class Derived(Intermediate, extends=Intermediate):
@classmethod
def test(cls):
value = super().test()
return f"{value} derived"

test_registry.init_registry()
assert Intermediate.test() == "base derived"
assert Derived.test() == "base derived"

ClsIntermediate = test_registry[Intermediate.__xreg_name__]
assert ClsIntermediate.test() == "base derived"
ClsDerived = test_registry[Derived.__xreg_name__]
assert ClsDerived.test() == "base derived"