Rename provider ExternalDependency -> Dependency

This commit is contained in:
Roman Mogylatov 2017-12-21 22:47:31 +02:00
parent dec490291b
commit a67e4ebd44
5 changed files with 3780 additions and 2698 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -25,10 +25,14 @@ cdef class Delegate(Object):
pass
cdef class ExternalDependency(Provider):
cdef class Dependency(Provider):
cdef type __instance_of
cdef class ExternalDependency(Dependency):
pass
cdef class OverridingContext(object):
cdef Provider __overridden
cdef Provider __overriding

View File

@ -295,8 +295,8 @@ cdef class Delegate(Object):
super(Delegate, self).__init__(ensure_is_provider(provides))
cdef class ExternalDependency(Provider):
""":py:class:`ExternalDependency` provider describes dependency interface.
cdef class Dependency(Provider):
""":py:class:`Dependency` provider describes dependency interface.
This provider is used for description of dependency interface. That might
be useful when dependency could be provided in the client's code only,
@ -305,7 +305,7 @@ cdef class ExternalDependency(Provider):
.. code-block:: python
database_provider = ExternalDependency(sqlite3.dbapi2.Connection)
database_provider = Dependency(sqlite3.dbapi2.Connection)
database_provider.override(Factory(sqlite3.connect, ':memory:'))
database = database_provider()
@ -317,10 +317,10 @@ cdef class ExternalDependency(Provider):
:type: type
"""
def __init__(self, type instance_of):
def __init__(self, type instance_of=object):
"""Initializer."""
self.__instance_of = instance_of
super(ExternalDependency, self).__init__()
super(Dependency, self).__init__()
def __deepcopy__(self, memo):
"""Create and return full copy of provider."""
@ -391,6 +391,33 @@ cdef class ExternalDependency(Provider):
return self.override(provider)
cdef class ExternalDependency(Dependency):
""":py:class:`ExternalDependency` provider describes dependency interface.
This provider is used for description of dependency interface. That might
be useful when dependency could be provided in the client's code only,
but it's interface is known. Such situations could happen when required
dependency has non-determenistic list of dependencies itself.
.. code-block:: python
database_provider = ExternalDependency(sqlite3.dbapi2.Connection)
database_provider.override(Factory(sqlite3.connect, ':memory:'))
database = database_provider()
.. deprecated:: 3.9
Use :py:class:`Dependency` instead.
.. py:attribute:: instance_of
Class of required dependency.
:type: type
"""
cdef class OverridingContext(object):
"""Provider overriding context.

View File

@ -229,13 +229,13 @@ class DelegateTests(unittest.TestCase):
hex(id(self.delegate))))
class ExternalDependencyTests(unittest.TestCase):
class DependencyTests(unittest.TestCase):
def setUp(self):
self.provider = providers.ExternalDependency(instance_of=list)
self.provider = providers.Dependency(instance_of=list)
def test_init_with_not_class(self):
self.assertRaises(TypeError, providers.ExternalDependency, object())
self.assertRaises(TypeError, providers.Dependency, object())
def test_is_provider(self):
self.assertTrue(providers.is_provider(self.provider))
@ -252,15 +252,15 @@ class ExternalDependencyTests(unittest.TestCase):
self.assertRaises(errors.Error, self.provider)
def test_deepcopy(self):
provider = providers.ExternalDependency(int)
provider = providers.Dependency(int)
provider_copy = providers.deepcopy(provider)
self.assertIsNot(provider, provider_copy)
self.assertIsInstance(provider, providers.ExternalDependency)
self.assertIsInstance(provider, providers.Dependency)
def test_deepcopy_from_memo(self):
provider = providers.ExternalDependency(int)
provider = providers.Dependency(int)
provider_copy_memo = providers.Provider()
provider_copy = providers.deepcopy(
@ -269,7 +269,7 @@ class ExternalDependencyTests(unittest.TestCase):
self.assertIs(provider_copy, provider_copy_memo)
def test_deepcopy_overridden(self):
provider = providers.ExternalDependency(int)
provider = providers.Dependency(int)
overriding_provider = providers.Provider()
provider.override(overriding_provider)
@ -278,7 +278,7 @@ class ExternalDependencyTests(unittest.TestCase):
overriding_provider_copy = provider_copy.overridden[0]
self.assertIsNot(provider, provider_copy)
self.assertIsInstance(provider, providers.ExternalDependency)
self.assertIsInstance(provider, providers.Dependency)
self.assertIsNot(overriding_provider, overriding_provider_copy)
self.assertIsInstance(overriding_provider_copy, providers.Provider)
@ -286,6 +286,15 @@ class ExternalDependencyTests(unittest.TestCase):
def test_repr(self):
self.assertEqual(repr(self.provider),
'<dependency_injector.providers.'
'ExternalDependency({0}) at {1}>'.format(
'Dependency({0}) at {1}>'.format(
repr(list),
hex(id(self.provider))))
class ExternalDependencyTests(unittest.TestCase):
def setUp(self):
self.provider = providers.ExternalDependency(instance_of=list)
def test_is_instance(self):
self.assertIsInstance(self.provider, providers.Dependency)