mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
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:
parent
cae4d8cdf2
commit
215b45b442
|
@ -9,6 +9,7 @@ follows `Semantic versioning`_
|
||||||
|
|
||||||
Development version
|
Development version
|
||||||
-------------------
|
-------------------
|
||||||
|
- Fix ``FactoryAggregate`` provider copying issue.
|
||||||
- Regenerate C sources using Cython 0.29.7.
|
- Regenerate C sources using Cython 0.29.7.
|
||||||
|
|
||||||
3.14.5
|
3.14.5
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1449,6 +1449,21 @@ cdef class FactoryAggregate(Provider):
|
||||||
self.__factories = factories
|
self.__factories = factories
|
||||||
super(FactoryAggregate, self).__init__()
|
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):
|
def __call__(self, factory_name, *args, **kwargs):
|
||||||
"""Create new object using factory with provided name.
|
"""Create new object using factory with provided name.
|
||||||
|
|
||||||
|
|
|
@ -498,6 +498,20 @@ class FactoryAggregateTests(unittest.TestCase):
|
||||||
dict(example_a=self.example_a_factory,
|
dict(example_a=self.example_a_factory,
|
||||||
example_b=self.example_b_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):
|
def test_repr(self):
|
||||||
self.assertEqual(repr(self.factory_aggregate),
|
self.assertEqual(repr(self.factory_aggregate),
|
||||||
'<dependency_injector.providers.'
|
'<dependency_injector.providers.'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user