mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 01:26:51 +03:00
Add few tests for injections
This commit is contained in:
parent
c78c9ddd86
commit
76d47df7fd
59
tests/test_injections.py
Normal file
59
tests/test_injections.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
"""Dependency injector container unit tests."""
|
||||
|
||||
import unittest2 as unittest
|
||||
|
||||
from dependency_injector import injections
|
||||
from dependency_injector import providers
|
||||
|
||||
|
||||
class PositionalInjectionTests(unittest.TestCase):
|
||||
|
||||
def test_init_with_kwargs(self):
|
||||
injections.PositionalInjection(value=1)
|
||||
|
||||
def test_isinstance(self):
|
||||
injection = injections.PositionalInjection(1)
|
||||
self.assertIsInstance(injection, injections.Injection)
|
||||
|
||||
def test_get_value_with_not_provider(self):
|
||||
injection = injections.PositionalInjection(123)
|
||||
self.assertEquals(injection.get_value(), 123)
|
||||
|
||||
def test_get_value_with_factory(self):
|
||||
injection = injections.PositionalInjection(providers.Factory(object))
|
||||
|
||||
obj1 = injection.get_value()
|
||||
obj2 = injection.get_value()
|
||||
|
||||
self.assertIs(type(obj1), object)
|
||||
self.assertIs(type(obj2), object)
|
||||
self.assertIsNot(obj1, obj2)
|
||||
|
||||
|
||||
class NamedInjectionTests(unittest.TestCase):
|
||||
|
||||
def test_init_with_kwargs(self):
|
||||
injections.NamedInjection(name='name', value=1)
|
||||
|
||||
def test_isinstance(self):
|
||||
injection = injections.NamedInjection('name', 1)
|
||||
self.assertIsInstance(injection, injections.Injection)
|
||||
|
||||
def test_get_name(self):
|
||||
injection = injections.NamedInjection('name', 123)
|
||||
self.assertEquals(injection.get_name(), 'name')
|
||||
|
||||
def test_get_value_with_not_provider(self):
|
||||
injection = injections.NamedInjection('name', 123)
|
||||
self.assertEquals(injection.get_value(), 123)
|
||||
|
||||
def test_get_value_with_factory(self):
|
||||
injection = injections.NamedInjection('name',
|
||||
providers.Factory(object))
|
||||
|
||||
obj1 = injection.get_value()
|
||||
obj2 = injection.get_value()
|
||||
|
||||
self.assertIs(type(obj1), object)
|
||||
self.assertIs(type(obj2), object)
|
||||
self.assertIsNot(obj1, obj2)
|
Loading…
Reference in New Issue
Block a user