def test_has_abstract_methods(self) -> None: """ Test that False is returned when the test type *is* a sub-class, but does not implement all abstract methods. """ class InterfaceType(metaclass=abc.ABCMeta): @abc.abstractmethod def abs_method(self) -> None: """ An abstract method. """ @property @abc.abstractmethod def abs_prop(self) -> int: """ An abstract property. """ # noinspection PyAbstractClass class ImplementsMethodOnly(InterfaceType): # Lingering abstract property def abs_method(self) -> None: pass # noinspection PyAbstractClass class ImplementsPropOnly(InterfaceType): # Lingering abstract method @property def abs_prop(self) -> int: return 0 assert not is_valid_plugin(ImplementsMethodOnly, InterfaceType) assert not is_valid_plugin(ImplementsPropOnly, InterfaceType)
def test_not_different_type(self) -> None: """ Test that a type is NOT considered a plugin when it's literally the interface type. """ class InterfaceType: ... assert not is_valid_plugin(InterfaceType, InterfaceType)
def test_not_subclass(self) -> None: """ Test that the return is False when the type is not a direct subclass. """ class InterfaceType: ... class TestType: ... assert not is_valid_plugin(TestType, InterfaceType)
def test_pluggable_usable(self) -> None: """ Test that if input type descends from Pluggable that the is_usable() function returning false invalidates it's plugin validity. """ class InterfaceType(Pluggable): ... class ImplementingTypeFalse(InterfaceType): @classmethod def is_usable(cls) -> bool: return False assert not is_valid_plugin(ImplementingTypeFalse, InterfaceType) class ImplementingTypeTrue(InterfaceType): @classmethod def is_usable(cls) -> bool: return True assert is_valid_plugin(ImplementingTypeTrue, InterfaceType)
def test_success(self) -> None: """ Test successfully validating a subclass type relative to a parent "interface" type. """ class InterfaceType(metaclass=abc.ABCMeta): @abc.abstractmethod def feature(self) -> int: ... class ImplementingType(InterfaceType): # is_usable default is True def feature(self) -> int: return 0 assert is_valid_plugin(ImplementingType, InterfaceType)