mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Restrict overriding of providers with themselves
This commit is contained in:
parent
176ff06778
commit
99b9a5648a
|
@ -46,6 +46,9 @@ class Provider(object):
|
|||
|
||||
def override(self, provider):
|
||||
"""Override provider with another provider."""
|
||||
if provider is self:
|
||||
raise Error('Provider {0} could not be overridden '
|
||||
'with itself'.format(self))
|
||||
if not self.is_overridden:
|
||||
self.overridden_by = (ensure_is_provider(provider),)
|
||||
else:
|
||||
|
|
|
@ -65,6 +65,10 @@ class ProviderTests(unittest.TestCase):
|
|||
self.provider.override(overriding_provider)
|
||||
self.assertTrue(self.provider.is_overridden)
|
||||
|
||||
def test_override_with_itself(self):
|
||||
"""Test provider overriding with itself."""
|
||||
self.assertRaises(di.Error, self.provider.override, self.provider)
|
||||
|
||||
def test_override_with_not_provider(self):
|
||||
"""Test provider overriding with not provider instance."""
|
||||
self.assertRaises(di.Error, self.provider.override, object())
|
||||
|
|
Loading…
Reference in New Issue
Block a user