FactoryAggregate copying issue fix (#220)

* Add test

* Implement deepcopy handler for FactoryAggregate provider

* Add more granularity for the test

* Update changelog

* Refactor test
This commit is contained in:
Roman Mogylatov 2019-05-09 14:58:04 -04:00 committed by GitHub
parent cae4d8cdf2
commit 215b45b442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1006 additions and 781 deletions

View File

@ -9,6 +9,7 @@ follows `Semantic versioning`_
Development version
-------------------
- Fix ``FactoryAggregate`` provider copying issue.
- Regenerate C sources using Cython 0.29.7.
3.14.5

File diff suppressed because it is too large Load Diff

View File

@ -1449,6 +1449,21 @@ cdef class FactoryAggregate(Provider):
self.__factories = factories
super(FactoryAggregate, self).__init__()
def __deepcopy__(self, memo):
"""Create and return full copy of provider."""
cdef FactoryAggregate copied
copied = memo.get(id(self))
if copied is not None:
return copied
copied = self.__class__()
copied.__factories = deepcopy(self.__factories, memo)
self._copy_overridings(copied, memo)
return copied
def __call__(self, factory_name, *args, **kwargs):
"""Create new object using factory with provided name.

View File

@ -498,6 +498,20 @@ class FactoryAggregateTests(unittest.TestCase):
dict(example_a=self.example_a_factory,
example_b=self.example_b_factory))
def test_deepcopy(self):
provider_copy = providers.deepcopy(self.factory_aggregate)
self.assertIsNot(self.factory_aggregate, provider_copy)
self.assertIsInstance(provider_copy, type(self.factory_aggregate))
self.assertIsNot(self.factory_aggregate.example_a, provider_copy.example_a)
self.assertIsInstance(self.factory_aggregate.example_a, type(provider_copy.example_a))
self.assertIs(self.factory_aggregate.example_a.cls, provider_copy.example_a.cls)
self.assertIsNot(self.factory_aggregate.example_b, provider_copy.example_b)
self.assertIsInstance(self.factory_aggregate.example_b, type(provider_copy.example_b))
self.assertIs(self.factory_aggregate.example_b.cls, provider_copy.example_b.cls)
def test_repr(self):
self.assertEqual(repr(self.factory_aggregate),
'<dependency_injector.providers.'