mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Rename provider ExternalDependency -> Dependency
This commit is contained in:
parent
dec490291b
commit
a67e4ebd44
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -25,10 +25,14 @@ cdef class Delegate(Object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
cdef class ExternalDependency(Provider):
|
cdef class Dependency(Provider):
|
||||||
cdef type __instance_of
|
cdef type __instance_of
|
||||||
|
|
||||||
|
|
||||||
|
cdef class ExternalDependency(Dependency):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
cdef class OverridingContext(object):
|
cdef class OverridingContext(object):
|
||||||
cdef Provider __overridden
|
cdef Provider __overridden
|
||||||
cdef Provider __overriding
|
cdef Provider __overriding
|
||||||
|
|
|
@ -295,8 +295,8 @@ cdef class Delegate(Object):
|
||||||
super(Delegate, self).__init__(ensure_is_provider(provides))
|
super(Delegate, self).__init__(ensure_is_provider(provides))
|
||||||
|
|
||||||
|
|
||||||
cdef class ExternalDependency(Provider):
|
cdef class Dependency(Provider):
|
||||||
""":py:class:`ExternalDependency` provider describes dependency interface.
|
""":py:class:`Dependency` provider describes dependency interface.
|
||||||
|
|
||||||
This provider is used for description of dependency interface. That might
|
This provider is used for description of dependency interface. That might
|
||||||
be useful when dependency could be provided in the client's code only,
|
be useful when dependency could be provided in the client's code only,
|
||||||
|
@ -305,7 +305,7 @@ cdef class ExternalDependency(Provider):
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
database_provider = ExternalDependency(sqlite3.dbapi2.Connection)
|
database_provider = Dependency(sqlite3.dbapi2.Connection)
|
||||||
database_provider.override(Factory(sqlite3.connect, ':memory:'))
|
database_provider.override(Factory(sqlite3.connect, ':memory:'))
|
||||||
|
|
||||||
database = database_provider()
|
database = database_provider()
|
||||||
|
@ -315,12 +315,12 @@ cdef class ExternalDependency(Provider):
|
||||||
Class of required dependency.
|
Class of required dependency.
|
||||||
|
|
||||||
:type: type
|
:type: type
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, type instance_of):
|
def __init__(self, type instance_of=object):
|
||||||
"""Initializer."""
|
"""Initializer."""
|
||||||
self.__instance_of = instance_of
|
self.__instance_of = instance_of
|
||||||
super(ExternalDependency, self).__init__()
|
super(Dependency, self).__init__()
|
||||||
|
|
||||||
def __deepcopy__(self, memo):
|
def __deepcopy__(self, memo):
|
||||||
"""Create and return full copy of provider."""
|
"""Create and return full copy of provider."""
|
||||||
|
@ -391,6 +391,33 @@ cdef class ExternalDependency(Provider):
|
||||||
return self.override(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):
|
cdef class OverridingContext(object):
|
||||||
"""Provider overriding context.
|
"""Provider overriding context.
|
||||||
|
|
||||||
|
|
|
@ -229,13 +229,13 @@ class DelegateTests(unittest.TestCase):
|
||||||
hex(id(self.delegate))))
|
hex(id(self.delegate))))
|
||||||
|
|
||||||
|
|
||||||
class ExternalDependencyTests(unittest.TestCase):
|
class DependencyTests(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.provider = providers.ExternalDependency(instance_of=list)
|
self.provider = providers.Dependency(instance_of=list)
|
||||||
|
|
||||||
def test_init_with_not_class(self):
|
def test_init_with_not_class(self):
|
||||||
self.assertRaises(TypeError, providers.ExternalDependency, object())
|
self.assertRaises(TypeError, providers.Dependency, object())
|
||||||
|
|
||||||
def test_is_provider(self):
|
def test_is_provider(self):
|
||||||
self.assertTrue(providers.is_provider(self.provider))
|
self.assertTrue(providers.is_provider(self.provider))
|
||||||
|
@ -252,15 +252,15 @@ class ExternalDependencyTests(unittest.TestCase):
|
||||||
self.assertRaises(errors.Error, self.provider)
|
self.assertRaises(errors.Error, self.provider)
|
||||||
|
|
||||||
def test_deepcopy(self):
|
def test_deepcopy(self):
|
||||||
provider = providers.ExternalDependency(int)
|
provider = providers.Dependency(int)
|
||||||
|
|
||||||
provider_copy = providers.deepcopy(provider)
|
provider_copy = providers.deepcopy(provider)
|
||||||
|
|
||||||
self.assertIsNot(provider, provider_copy)
|
self.assertIsNot(provider, provider_copy)
|
||||||
self.assertIsInstance(provider, providers.ExternalDependency)
|
self.assertIsInstance(provider, providers.Dependency)
|
||||||
|
|
||||||
def test_deepcopy_from_memo(self):
|
def test_deepcopy_from_memo(self):
|
||||||
provider = providers.ExternalDependency(int)
|
provider = providers.Dependency(int)
|
||||||
provider_copy_memo = providers.Provider()
|
provider_copy_memo = providers.Provider()
|
||||||
|
|
||||||
provider_copy = providers.deepcopy(
|
provider_copy = providers.deepcopy(
|
||||||
|
@ -269,7 +269,7 @@ class ExternalDependencyTests(unittest.TestCase):
|
||||||
self.assertIs(provider_copy, provider_copy_memo)
|
self.assertIs(provider_copy, provider_copy_memo)
|
||||||
|
|
||||||
def test_deepcopy_overridden(self):
|
def test_deepcopy_overridden(self):
|
||||||
provider = providers.ExternalDependency(int)
|
provider = providers.Dependency(int)
|
||||||
overriding_provider = providers.Provider()
|
overriding_provider = providers.Provider()
|
||||||
|
|
||||||
provider.override(overriding_provider)
|
provider.override(overriding_provider)
|
||||||
|
@ -278,7 +278,7 @@ class ExternalDependencyTests(unittest.TestCase):
|
||||||
overriding_provider_copy = provider_copy.overridden[0]
|
overriding_provider_copy = provider_copy.overridden[0]
|
||||||
|
|
||||||
self.assertIsNot(provider, provider_copy)
|
self.assertIsNot(provider, provider_copy)
|
||||||
self.assertIsInstance(provider, providers.ExternalDependency)
|
self.assertIsInstance(provider, providers.Dependency)
|
||||||
|
|
||||||
self.assertIsNot(overriding_provider, overriding_provider_copy)
|
self.assertIsNot(overriding_provider, overriding_provider_copy)
|
||||||
self.assertIsInstance(overriding_provider_copy, providers.Provider)
|
self.assertIsInstance(overriding_provider_copy, providers.Provider)
|
||||||
|
@ -286,6 +286,15 @@ class ExternalDependencyTests(unittest.TestCase):
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
self.assertEqual(repr(self.provider),
|
self.assertEqual(repr(self.provider),
|
||||||
'<dependency_injector.providers.'
|
'<dependency_injector.providers.'
|
||||||
'ExternalDependency({0}) at {1}>'.format(
|
'Dependency({0}) at {1}>'.format(
|
||||||
repr(list),
|
repr(list),
|
||||||
hex(id(self.provider))))
|
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user