Implement DeclarativeCatalog.__repr__ and add some tests for it

This commit is contained in:
Roman Mogilatov 2015-11-12 01:00:27 +02:00
parent 3fc5f044f9
commit 4252fbfe4c
2 changed files with 23 additions and 3 deletions

View File

@ -243,7 +243,8 @@ class DeclarativeCatalogMetaClass(type):
def __repr__(cls):
"""Return string representation of the catalog."""
return '<DeclarativeCatalog {0}>'.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

View File

@ -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."""