Esempio n. 1
0
async def test_concurrent_init():
    async def create_instance():
        return object()

    provider = providers.DelegatedThreadLocalSingleton(create_instance)

    future_instance1 = provider()
    future_instance2 = provider()

    instance1, instance2 = await asyncio.gather(future_instance1,
                                                future_instance2)

    assert instance1 is instance2
Esempio n. 2
0
    def test_async_mode(self):
        instance = object()

        async def create_instance():
            return instance

        provider = providers.DelegatedThreadLocalSingleton(create_instance)

        instance1 = self._run(provider())
        instance2 = self._run(provider())

        self.assertIs(instance1, instance2)
        self.assertIs(instance, instance)
Esempio n. 3
0
async def test_async_mode():
    instance = object()

    async def create_instance():
        return instance

    provider = providers.DelegatedThreadLocalSingleton(create_instance)

    instance1 = await provider()
    instance2 = await provider()

    assert instance1 is instance2
    assert instance1 is instance
    assert instance2 is instance
Esempio n. 4
0
method_caller5: providers.MethodCaller = provider5.provided.method.call(
    123, arg=324)

# Test 6: to check the DelegatedSingleton
provider6 = providers.DelegatedSingleton(Cat)
animal6: Animal = provider6(1, 2, 3, b='1', c=2, e=0.0)

# Test 7: to check the ThreadSafeSingleton
provider7: providers.BaseSingleton[Animal] = providers.ThreadSafeSingleton(Cat)
animal7: Animal = provider7()

# Test 8: to check the DelegatedThreadSafeSingleton
provider8 = providers.DelegatedThreadSafeSingleton(Cat)
animal8: Animal = provider8(1, 2, 3, b='1', c=2, e=0.0)

# Test 9: to check the ThreadLocalSingleton
provider9 = providers.ThreadLocalSingleton(Cat)
animal9: Animal = provider9(1, 2, 3, b='1', c=2, e=0.0)

# Test 10: to check the DelegatedThreadLocalSingleton
provider10 = providers.DelegatedThreadLocalSingleton(Cat)
animal10: Animal = provider10(1, 2, 3, b='1', c=2, e=0.0)

# Test 11: to check the AbstractSingleton
provider11 = providers.AbstractSingleton(Animal)
provider11.override(providers.Singleton(Cat))
animal11: Animal = provider11(1, 2, 3, b='1', c=2, e=0.0)

# Test 12: to check the SingletonDelegate __init__
provider12 = providers.SingletonDelegate(providers.Singleton(object))
Esempio n. 5
0
 def test_is_delegated_provider(self):
     """Test is_delegated_provider."""
     provider = providers.DelegatedThreadLocalSingleton(object)
     self.assertIs(provider.provide_injection(), provider)
Esempio n. 6
0
 def test_is_provider(self):
     """Test is_provider."""
     self.assertTrue(
         utils.is_provider(providers.DelegatedThreadLocalSingleton(object)))
Esempio n. 7
0
 def test_inheritance(self):
     """Test inheritance."""
     self.assertIsInstance(providers.DelegatedThreadLocalSingleton(object),
                           providers.ThreadLocalSingleton)