mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Add tests for base providers
This commit is contained in:
parent
07b9a991b3
commit
82296d9fed
|
@ -179,8 +179,6 @@ cdef class Provider(object):
|
||||||
@cython.wraparound(False)
|
@cython.wraparound(False)
|
||||||
cpdef object _call_last_overriding(self, tuple args, dict kwargs):
|
cpdef object _call_last_overriding(self, tuple args, dict kwargs):
|
||||||
"""Call last overriding provider and return result."""
|
"""Call last overriding provider and return result."""
|
||||||
if self.__overridden_len == 0:
|
|
||||||
return None
|
|
||||||
return <object>self.__overridden[self.__overridden_len - 1](*args,
|
return <object>self.__overridden[self.__overridden_len - 1](*args,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,38 @@ class ProviderTests(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(self.provider.overridden, tuple())
|
self.assertEqual(self.provider.overridden, tuple())
|
||||||
|
|
||||||
|
def test_deepcopy(self):
|
||||||
|
provider = providers.Provider()
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(provider)
|
||||||
|
|
||||||
|
self.assertIsNot(provider, provider_copy)
|
||||||
|
self.assertIsInstance(provider, providers.Provider)
|
||||||
|
|
||||||
|
def test_deepcopy_from_memo(self):
|
||||||
|
provider = providers.Provider()
|
||||||
|
provider_copy_memo = providers.Provider()
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(
|
||||||
|
provider, memo={id(provider): provider_copy_memo})
|
||||||
|
|
||||||
|
self.assertIs(provider_copy, provider_copy_memo)
|
||||||
|
|
||||||
|
def test_deepcopy_overridden(self):
|
||||||
|
provider = providers.Provider()
|
||||||
|
overriding_provider = providers.Provider()
|
||||||
|
|
||||||
|
provider.override(overriding_provider)
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(provider)
|
||||||
|
overriding_provider_copy = provider_copy.overridden[0]
|
||||||
|
|
||||||
|
self.assertIsNot(provider, provider_copy)
|
||||||
|
self.assertIsInstance(provider, providers.Provider)
|
||||||
|
|
||||||
|
self.assertIsNot(overriding_provider, overriding_provider_copy)
|
||||||
|
self.assertIsInstance(overriding_provider_copy, providers.Provider)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
self.assertEqual(repr(self.provider),
|
self.assertEqual(repr(self.provider),
|
||||||
'<dependency_injector.providers.base.'
|
'<dependency_injector.providers.base.'
|
||||||
|
@ -102,6 +134,38 @@ class ObjectProviderTests(unittest.TestCase):
|
||||||
provider.override(providers.Object(obj2))
|
provider.override(providers.Object(obj2))
|
||||||
self.assertIs(provider(), obj2)
|
self.assertIs(provider(), obj2)
|
||||||
|
|
||||||
|
def test_deepcopy(self):
|
||||||
|
provider = providers.Object(1)
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(provider)
|
||||||
|
|
||||||
|
self.assertIsNot(provider, provider_copy)
|
||||||
|
self.assertIsInstance(provider, providers.Object)
|
||||||
|
|
||||||
|
def test_deepcopy_from_memo(self):
|
||||||
|
provider = providers.Object(1)
|
||||||
|
provider_copy_memo = providers.Provider()
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(
|
||||||
|
provider, memo={id(provider): provider_copy_memo})
|
||||||
|
|
||||||
|
self.assertIs(provider_copy, provider_copy_memo)
|
||||||
|
|
||||||
|
def test_deepcopy_overridden(self):
|
||||||
|
provider = providers.Object(1)
|
||||||
|
overriding_provider = providers.Provider()
|
||||||
|
|
||||||
|
provider.override(overriding_provider)
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(provider)
|
||||||
|
overriding_provider_copy = provider_copy.overridden[0]
|
||||||
|
|
||||||
|
self.assertIsNot(provider, provider_copy)
|
||||||
|
self.assertIsInstance(provider, providers.Object)
|
||||||
|
|
||||||
|
self.assertIsNot(overriding_provider, overriding_provider_copy)
|
||||||
|
self.assertIsInstance(overriding_provider_copy, providers.Provider)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
some_object = object()
|
some_object = object()
|
||||||
provider = providers.Object(some_object)
|
provider = providers.Object(some_object)
|
||||||
|
@ -161,6 +225,38 @@ class ExternalDependencyTests(unittest.TestCase):
|
||||||
def test_call_not_overridden(self):
|
def test_call_not_overridden(self):
|
||||||
self.assertRaises(errors.Error, self.provider)
|
self.assertRaises(errors.Error, self.provider)
|
||||||
|
|
||||||
|
def test_deepcopy(self):
|
||||||
|
provider = providers.ExternalDependency(int)
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(provider)
|
||||||
|
|
||||||
|
self.assertIsNot(provider, provider_copy)
|
||||||
|
self.assertIsInstance(provider, providers.ExternalDependency)
|
||||||
|
|
||||||
|
def test_deepcopy_from_memo(self):
|
||||||
|
provider = providers.ExternalDependency(int)
|
||||||
|
provider_copy_memo = providers.Provider()
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(
|
||||||
|
provider, memo={id(provider): provider_copy_memo})
|
||||||
|
|
||||||
|
self.assertIs(provider_copy, provider_copy_memo)
|
||||||
|
|
||||||
|
def test_deepcopy_overridden(self):
|
||||||
|
provider = providers.ExternalDependency(int)
|
||||||
|
overriding_provider = providers.Provider()
|
||||||
|
|
||||||
|
provider.override(overriding_provider)
|
||||||
|
|
||||||
|
provider_copy = providers.deepcopy(provider)
|
||||||
|
overriding_provider_copy = provider_copy.overridden[0]
|
||||||
|
|
||||||
|
self.assertIsNot(provider, provider_copy)
|
||||||
|
self.assertIsInstance(provider, providers.ExternalDependency)
|
||||||
|
|
||||||
|
self.assertIsNot(overriding_provider, overriding_provider_copy)
|
||||||
|
self.assertIsInstance(overriding_provider_copy, providers.Provider)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
self.assertEqual(repr(self.provider),
|
self.assertEqual(repr(self.provider),
|
||||||
'<dependency_injector.providers.base.'
|
'<dependency_injector.providers.base.'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user