Exemple #1
0
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())
Exemple #3
0
 def provide(self, dependency: float, container: Container
             ) -> Optional[DependencyValue]:
     return DependencyValue(dependency ** 2)
Exemple #4
0
 def provide(self, container: Container) -> DependencyValue:
     return DependencyValue(container.get(self.value), scope=self.scope)
Exemple #5
0
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)
Exemple #6
0
 def provide(self, dependency, container):
     return DependencyValue(
         self.data[dependency](container),
         scope=Scope.singleton() if self.singleton else None)
Exemple #7
0
 def f4(dependency: Hashable) -> Optional[DependencyValue]:
     if dependency == 'test':
         return DependencyValue(object(), scope=Scope.singleton())
Exemple #8
0
 def provide(dependency):
     if dependency == 2:
         return DependencyValue(object(), scope=dummy_scope)
Exemple #9
0
 def f3(dependency: Hashable) -> Optional[DependencyValue]:
     if dependency == 'test':
         return DependencyValue(object())
Exemple #10
0
 def f2(dependency: Hashable) -> Optional[DependencyValue]:
     if dependency == 'test':
         return DependencyValue('a')
Exemple #11
0
 def provide(self, dependency: Hashable,
             container: Container) -> DependencyValue:
     return DependencyValue(self.registered[dependency])
Exemple #12
0
 def provide(self, dependency: Hashable,
             container: Container) -> DependencyValue:
     ThreadSafetyTest.check_locked(failures)
     return DependencyValue('b')
Exemple #13
0
 def provide(self, dependency: Hashable,
             container: Container) -> DependencyValue:
     assert dependency is x
     return DependencyValue(None)