def test_freeze(indirect: IndirectProvider, permanent): world.freeze() with pytest.raises(FrozenWorldError): indirect.register_implementation(Interface, lambda: A, permanent=False) with pytest.raises(FrozenWorldError): indirect.register_implementation(Interface, lambda: A, permanent=True) with pytest.raises(DependencyNotFoundError): world.get(Interface)
def test_freeze(): world.provider(ServiceProvider) provider = world.get[ServiceProvider]() class Service: pass world.freeze() with pytest.raises(FrozenWorldError): world.test.singleton("test", "x") with pytest.raises(FrozenWorldError): provider.register(Service, scope=None)
def test_freeze_world(): class DummyProvider(Provider): def provide(self, dependency: Hashable, container: Container) -> Optional[DependencyValue]: return None def clone(self, keep_singletons_cache: bool) -> 'DummyProvider': return self def register(self): return "register" @does_not_freeze def method(self): return "method" @staticmethod def static(): return "static" @classmethod def klass(cls): return "klass" provider = DummyProvider() assert provider.register() == "register" assert provider.method() == "method" assert provider.static() == "static" assert provider.klass() == "klass" with world.test.empty(): world.provider(DummyProvider) provider = world.get[DummyProvider]() assert provider.register() == "register" assert provider.method() == "method" assert provider.static() == "static" assert provider.klass() == "klass" world.freeze() assert provider.method() == "method" assert provider.static() == "static" assert provider.klass() == "klass" provider.clone(False) provider.provide(None, None) with pytest.raises(FrozenWorldError): provider.register()
def test_freeze(provider: ServiceProvider, scope: Scope): world.freeze() with pytest.raises(FrozenWorldError): provider.register(A, scope=scope)
def test_freeze(provider: FactoryProvider, scope: Scope): world.freeze() with pytest.raises(FrozenWorldError): provider.register(A, factory=build, scope=scope)