def test_is_implemented_by(): from giblets import Component, ComponentManager, ExtensionPoint from giblets import ExtensionInterface, implements, is_implemented_by class IFoo(ExtensionInterface): pass class IBar(ExtensionInterface): pass class Foo(Component): implements(IFoo) class Bar(Component): implements(IBar) mgr = ComponentManager() foo = Foo(mgr) bar = Bar(mgr) assert is_implemented_by(Foo, IFoo) assert is_implemented_by(foo, IFoo) assert not is_implemented_by(Foo, IBar) assert not is_implemented_by(foo, IBar) assert is_implemented_by(Bar, IBar) assert is_implemented_by(bar, IBar) assert not is_implemented_by(Bar, IFoo) assert not is_implemented_by(bar, IFoo)
def test_is_implemented_by_implements_only(): from giblets import Component, ComponentManager, ExtensionPoint from giblets import ExtensionInterface, implements, is_implemented_by from giblets import implements_only class IVehicle(ExtensionInterface): pass class IFloat(ExtensionInterface): pass class IBoat(IVehicle): pass class Sailboat(Component): implements(IBoat, IFloat) mgr = ComponentManager() sailboat = Sailboat(mgr) assert is_implemented_by(Sailboat, IBoat) assert is_implemented_by(sailboat, IBoat) assert is_implemented_by(Sailboat, IFloat) assert is_implemented_by(sailboat, IFloat) assert is_implemented_by(Sailboat, IVehicle) assert is_implemented_by(sailboat, IVehicle) class Sloop(Sailboat): pass sloop = Sloop(mgr) assert is_implemented_by(Sloop, IBoat) assert is_implemented_by(sloop, IBoat) assert is_implemented_by(Sloop, IFloat) assert is_implemented_by(sloop, IFloat) assert is_implemented_by(Sloop, IVehicle) assert is_implemented_by(sloop, IVehicle) class BoatWithAHole(Sailboat): implements_only(IBoat) bwah = BoatWithAHole assert is_implemented_by(BoatWithAHole, IBoat) assert is_implemented_by(bwah, IBoat) assert not is_implemented_by(BoatWithAHole, IFloat) assert not is_implemented_by(bwah, IFloat) assert is_implemented_by(BoatWithAHole, IVehicle) assert is_implemented_by(bwah, IVehicle)