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