Add parsing of nested containers to declarative container

This commit is contained in:
Roman Mogylatov 2017-11-21 11:47:55 +02:00
parent 236fe316e3
commit 7bd0997f85
3 changed files with 1189 additions and 662 deletions

File diff suppressed because it is too large Load Diff

View File

@ -144,6 +144,12 @@ class DeclarativeContainerMetaClass(type):
cdef tuple inherited_providers
cdef type cls
containers = tuple((name, container)
for name, container in six.iteritems(attributes)
if is_container(container))
attributes['containers'] = dict(containers)
cls_providers = tuple((name, provider)
for name, provider in six.iteritems(attributes)
if isinstance(provider, Provider))
@ -229,6 +235,12 @@ class DeclarativeContainer(object):
:type: type
"""
containers = dict()
"""Read-only dictionary of all nested containers.
:type: dict[str, :py:class:`DeclarativeContainer`]
"""
providers = dict()
"""Read-only dictionary of all providers.

View File

@ -250,3 +250,18 @@ class DeclarativeContainerTests(unittest.TestCase):
self.assertEqual(_Container1.p13(), 11)
self.assertEqual(_Container2.p13(), 22)
def test_containers_attribute(self):
class Container(containers.DeclarativeContainer):
class Container1(containers.DeclarativeContainer):
pass
class Container2(containers.DeclarativeContainer):
pass
Container3 = containers.DynamicContainer()
self.assertEqual(Container.containers,
dict(Container1=Container.Container1,
Container2=Container.Container2,
Container3=Container.Container3))