From e45b9987676da212f87b15fd292425d13ddfb440 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Fri, 23 Jun 2023 17:37:00 +0200 Subject: [PATCH] Add tests on inheritance and class methods excecution --- tests/test_inheritance.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py index 1326e68..ed90ea0 100644 --- a/tests/test_inheritance.py +++ b/tests/test_inheritance.py @@ -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"