def test_custom_scope(): @haps.scope('custom') class CustomScopedCls: pass class CustomScope(InstanceScope): get_object_called = False def get_object(self, type_): CustomScope.get_object_called = True return super(CustomScope, self).get_object(type_) haps.Container.configure( [haps.Egg(CustomScopedCls, CustomScopedCls, None, CustomScopedCls)]) haps.Container().register_scope('custom', CustomScope) class AnotherClass: @haps.inject def __init__(self, csc: CustomScopedCls): self.csc = csc some_instance = AnotherClass() assert isinstance(some_instance.csc, CustomScopedCls) assert CustomScope.get_object_called
def test_configure_class_and_get_object(some_class): haps.Container.configure( [haps.Egg(some_class, some_class, None, some_class)]) some_instance = haps.Container().get_object(some_class) assert isinstance(some_instance, some_class)
def test_configure(): haps.Container.configure([]) assert haps.Container()
def test_not_configured(): with pytest.raises(exceptions.NotConfigured): haps.Container()