def test_provide_from(): provider = DummyIntProvider() assert world.test.maybe_provide_from(provider, 10) == DependencyValue(20) assert world.test.maybe_provide_from(provider, "1") is None world.provider(DummyIntProvider) with pytest.raises(RuntimeError): world.test.maybe_provide_from(world.get(DummyIntProvider), 10)
def d(x): return DependencyValue(x, scope=Scope.singleton())
def provide(self, dependency: float, container: Container ) -> Optional[DependencyValue]: return DependencyValue(dependency ** 2)
def provide(self, container: Container) -> DependencyValue: return DependencyValue(container.get(self.value), scope=self.scope)
def test_dependency_value(): ref = DependencyValue("test", scope=Scope.singleton()) assert ref == DependencyValue("test", scope=Scope.singleton()) assert ref != DependencyValue("test2", scope=Scope.singleton()) assert ref != DependencyValue("test", scope=None)
def provide(self, dependency, container): return DependencyValue( self.data[dependency](container), scope=Scope.singleton() if self.singleton else None)
def f4(dependency: Hashable) -> Optional[DependencyValue]: if dependency == 'test': return DependencyValue(object(), scope=Scope.singleton())
def provide(dependency): if dependency == 2: return DependencyValue(object(), scope=dummy_scope)
def f3(dependency: Hashable) -> Optional[DependencyValue]: if dependency == 'test': return DependencyValue(object())
def f2(dependency: Hashable) -> Optional[DependencyValue]: if dependency == 'test': return DependencyValue('a')
def provide(self, dependency: Hashable, container: Container) -> DependencyValue: return DependencyValue(self.registered[dependency])
def provide(self, dependency: Hashable, container: Container) -> DependencyValue: ThreadSafetyTest.check_locked(failures) return DependencyValue('b')
def provide(self, dependency: Hashable, container: Container) -> DependencyValue: assert dependency is x return DependencyValue(None)