From 82296d9fed27c0a9cfb6e547d6fc6eef872dfd4a Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Fri, 11 Nov 2016 12:11:56 +0200 Subject: [PATCH] Add tests for base providers --- src/dependency_injector/providers/base.pyx | 2 - tests/unit/providers/test_base.py | 96 ++++++++++++++++++++++ 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/dependency_injector/providers/base.pyx b/src/dependency_injector/providers/base.pyx index a3e70854..1d072a5a 100644 --- a/src/dependency_injector/providers/base.pyx +++ b/src/dependency_injector/providers/base.pyx @@ -179,8 +179,6 @@ cdef class Provider(object): @cython.wraparound(False) cpdef object _call_last_overriding(self, tuple args, dict kwargs): """Call last overriding provider and return result.""" - if self.__overridden_len == 0: - return None return self.__overridden[self.__overridden_len - 1](*args, **kwargs) diff --git a/tests/unit/providers/test_base.py b/tests/unit/providers/test_base.py index e475ceb6..e7ca8167 100644 --- a/tests/unit/providers/test_base.py +++ b/tests/unit/providers/test_base.py @@ -80,6 +80,38 @@ class ProviderTests(unittest.TestCase): 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): self.assertEqual(repr(self.provider), '