diff --git a/dependency_injector/catalogs.py b/dependency_injector/catalogs.py index 934c9f2c..42cf44c1 100644 --- a/dependency_injector/catalogs.py +++ b/dependency_injector/catalogs.py @@ -243,7 +243,8 @@ class DeclarativeCatalogMetaClass(type): def __repr__(cls): """Return string representation of the catalog.""" - return ''.format(cls.name) + return '<{0}({1})>'.format(cls.name, + ', '.join(six.iterkeys(cls.providers))) __str__ = __repr__ @@ -283,10 +284,10 @@ class DeclarativeCatalog(object): :param last_overriding: Reference to the last overriding catalog, if any """ - name = str() - catalog = DynamicCatalog Bundle = CatalogBundle + name = str() + cls_providers = dict() inherited_providers = dict() providers = dict() @@ -295,6 +296,8 @@ class DeclarativeCatalog(object): is_overridden = bool last_overriding = None + catalog = DynamicCatalog + __IS_CATALOG__ = True @classmethod diff --git a/tests/test_catalogs.py b/tests/test_catalogs.py index b1308705..d0fdb910 100644 --- a/tests/test_catalogs.py +++ b/tests/test_catalogs.py @@ -248,6 +248,23 @@ class DeclarativeCatalogTests(unittest.TestCase): def test_repr(self): """Test declarative catalog representation.""" + self.assertIn('CatalogA', repr(CatalogA)) + self.assertIn('p11', repr(CatalogA)) + self.assertIn('p12', repr(CatalogA)) + + self.assertIn('CatalogB', repr(CatalogB)) + self.assertIn('p11', repr(CatalogB)) + self.assertIn('p12', repr(CatalogB)) + self.assertIn('p21', repr(CatalogB)) + self.assertIn('p22', repr(CatalogB)) + + self.assertIn('CatalogC', repr(CatalogC)) + self.assertIn('p11', repr(CatalogC)) + self.assertIn('p12', repr(CatalogC)) + self.assertIn('p21', repr(CatalogC)) + self.assertIn('p22', repr(CatalogC)) + self.assertIn('p31', repr(CatalogC)) + self.assertIn('p32', repr(CatalogC)) def test_abstract_catalog_backward_compatibility(self): """Test that di.AbstractCatalog is available."""