diff --git a/objects/__init__.py b/objects/__init__.py index e735b05c..b87f761d 100644 --- a/objects/__init__.py +++ b/objects/__init__.py @@ -3,7 +3,7 @@ from .catalog import AbstractCatalog, overrides from .providers import Provider -from .providers import ProviderDelegate +from .providers import Delegate from .providers import NewInstance from .providers import Singleton from .providers import Scoped @@ -19,13 +19,15 @@ from .injections import InitArg from .injections import Attribute from .injections import Method +from .errors import Error + __all__ = ('AbstractCatalog', 'overrides', # Providers 'Provider', - 'ProviderDelegate', + 'Delegate', 'NewInstance', 'Singleton', 'Scoped', @@ -40,4 +42,7 @@ __all__ = ('AbstractCatalog', # Injections 'InitArg', 'Attribute', - 'Method') + 'Method', + + # Errors + 'Error') diff --git a/objects/providers.py b/objects/providers.py index a72fad08..2f2d9c6d 100644 --- a/objects/providers.py +++ b/objects/providers.py @@ -28,7 +28,7 @@ class Provider(object): def delegate(self): """Return provider's delegate.""" - return ProviderDelegate(self) + return Delegate(self) def override(self, provider): """Override provider with another provider.""" @@ -44,7 +44,7 @@ class Provider(object): 'is not overridden') -class ProviderDelegate(Provider): +class Delegate(Provider): """Provider's delegate.""" @@ -56,7 +56,7 @@ class ProviderDelegate(Provider): :type delegated: Provider """ self.delegated = ensure_is_provider(delegated) - super(ProviderDelegate, self).__init__() + super(Delegate, self).__init__() def __call__(self): """Return provided instance.""" diff --git a/tests/test_providers.py b/tests/test_providers.py index e77900b4..c527fb91 100644 --- a/tests/test_providers.py +++ b/tests/test_providers.py @@ -3,7 +3,7 @@ import unittest2 as unittest from objects.providers import Provider -from objects.providers import ProviderDelegate +from objects.providers import Delegate from objects.providers import NewInstance from objects.providers import Singleton from objects.providers import Scoped @@ -40,12 +40,12 @@ class ProviderTest(unittest.TestCase): """Test creating of provider delegation.""" delegate1 = self.provider.delegate() - self.assertIsInstance(delegate1, ProviderDelegate) + self.assertIsInstance(delegate1, Delegate) self.assertIs(delegate1.delegated, self.provider) delegate2 = self.provider.delegate() - self.assertIsInstance(delegate2, ProviderDelegate) + self.assertIsInstance(delegate2, Delegate) self.assertIs(delegate2.delegated, self.provider) self.assertIsNot(delegate1, delegate2) @@ -89,7 +89,7 @@ class ProviderDelegateTest(unittest.TestCase): def setUp(self): """Set test cases environment up.""" self.delegated = Provider() - self.delegate = ProviderDelegate(delegated=self.delegated) + self.delegate = Delegate(delegated=self.delegated) def test_is_provider(self): """Test `is_provider` check.""" @@ -97,7 +97,7 @@ class ProviderDelegateTest(unittest.TestCase): def test_init_with_not_provider(self): """Test that delegate accepts only another provider as delegated.""" - self.assertRaises(Error, ProviderDelegate, delegated=object()) + self.assertRaises(Error, Delegate, delegated=object()) def test_call(self): """ Test returning of delegated provider.""" @@ -106,3 +106,8 @@ class ProviderDelegateTest(unittest.TestCase): self.assertIs(delegated1, self.delegated) self.assertIs(delegated2, self.delegated) + + +class NewInstanceTest(unittest.TestCase): + + """NewInstance test cases."""