renaming ProviderDelegate to Delegate

This commit is contained in:
Roman Mogilatov 2015-03-14 00:02:01 +02:00
parent 1c4abb7533
commit 6567ee2b4d
3 changed files with 21 additions and 11 deletions

View File

@ -3,7 +3,7 @@
from .catalog import AbstractCatalog, overrides from .catalog import AbstractCatalog, overrides
from .providers import Provider from .providers import Provider
from .providers import ProviderDelegate from .providers import Delegate
from .providers import NewInstance from .providers import NewInstance
from .providers import Singleton from .providers import Singleton
from .providers import Scoped from .providers import Scoped
@ -19,13 +19,15 @@ from .injections import InitArg
from .injections import Attribute from .injections import Attribute
from .injections import Method from .injections import Method
from .errors import Error
__all__ = ('AbstractCatalog', __all__ = ('AbstractCatalog',
'overrides', 'overrides',
# Providers # Providers
'Provider', 'Provider',
'ProviderDelegate', 'Delegate',
'NewInstance', 'NewInstance',
'Singleton', 'Singleton',
'Scoped', 'Scoped',
@ -40,4 +42,7 @@ __all__ = ('AbstractCatalog',
# Injections # Injections
'InitArg', 'InitArg',
'Attribute', 'Attribute',
'Method') 'Method',
# Errors
'Error')

View File

@ -28,7 +28,7 @@ class Provider(object):
def delegate(self): def delegate(self):
"""Return provider's delegate.""" """Return provider's delegate."""
return ProviderDelegate(self) return Delegate(self)
def override(self, provider): def override(self, provider):
"""Override provider with another provider.""" """Override provider with another provider."""
@ -44,7 +44,7 @@ class Provider(object):
'is not overridden') 'is not overridden')
class ProviderDelegate(Provider): class Delegate(Provider):
"""Provider's delegate.""" """Provider's delegate."""
@ -56,7 +56,7 @@ class ProviderDelegate(Provider):
:type delegated: Provider :type delegated: Provider
""" """
self.delegated = ensure_is_provider(delegated) self.delegated = ensure_is_provider(delegated)
super(ProviderDelegate, self).__init__() super(Delegate, self).__init__()
def __call__(self): def __call__(self):
"""Return provided instance.""" """Return provided instance."""

View File

@ -3,7 +3,7 @@
import unittest2 as unittest import unittest2 as unittest
from objects.providers import Provider from objects.providers import Provider
from objects.providers import ProviderDelegate from objects.providers import Delegate
from objects.providers import NewInstance from objects.providers import NewInstance
from objects.providers import Singleton from objects.providers import Singleton
from objects.providers import Scoped from objects.providers import Scoped
@ -40,12 +40,12 @@ class ProviderTest(unittest.TestCase):
"""Test creating of provider delegation.""" """Test creating of provider delegation."""
delegate1 = self.provider.delegate() delegate1 = self.provider.delegate()
self.assertIsInstance(delegate1, ProviderDelegate) self.assertIsInstance(delegate1, Delegate)
self.assertIs(delegate1.delegated, self.provider) self.assertIs(delegate1.delegated, self.provider)
delegate2 = self.provider.delegate() delegate2 = self.provider.delegate()
self.assertIsInstance(delegate2, ProviderDelegate) self.assertIsInstance(delegate2, Delegate)
self.assertIs(delegate2.delegated, self.provider) self.assertIs(delegate2.delegated, self.provider)
self.assertIsNot(delegate1, delegate2) self.assertIsNot(delegate1, delegate2)
@ -89,7 +89,7 @@ class ProviderDelegateTest(unittest.TestCase):
def setUp(self): def setUp(self):
"""Set test cases environment up.""" """Set test cases environment up."""
self.delegated = Provider() self.delegated = Provider()
self.delegate = ProviderDelegate(delegated=self.delegated) self.delegate = Delegate(delegated=self.delegated)
def test_is_provider(self): def test_is_provider(self):
"""Test `is_provider` check.""" """Test `is_provider` check."""
@ -97,7 +97,7 @@ class ProviderDelegateTest(unittest.TestCase):
def test_init_with_not_provider(self): def test_init_with_not_provider(self):
"""Test that delegate accepts only another provider as delegated.""" """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): def test_call(self):
""" Test returning of delegated provider.""" """ Test returning of delegated provider."""
@ -106,3 +106,8 @@ class ProviderDelegateTest(unittest.TestCase):
self.assertIs(delegated1, self.delegated) self.assertIs(delegated1, self.delegated)
self.assertIs(delegated2, self.delegated) self.assertIs(delegated2, self.delegated)
class NewInstanceTest(unittest.TestCase):
"""NewInstance test cases."""