mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 02:53:56 +03:00
Add ability to reset provider override
This commit is contained in:
parent
22b28d0023
commit
3b880d12a5
|
@ -34,6 +34,10 @@ class Provider(object):
|
||||||
"""Override provider with another provider."""
|
"""Override provider with another provider."""
|
||||||
self.overridden.append(ensure_is_provider(provider))
|
self.overridden.append(ensure_is_provider(provider))
|
||||||
|
|
||||||
|
def reset_override(self):
|
||||||
|
"""Reset all overriding providers."""
|
||||||
|
self.overridden = list()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_overriding(self):
|
def last_overriding(self):
|
||||||
"""Return last overriding provider."""
|
"""Return last overriding provider."""
|
||||||
|
|
|
@ -65,6 +65,25 @@ class ProviderTests(unittest.TestCase):
|
||||||
"""Test provider overriding with not provider instance."""
|
"""Test provider overriding with not provider instance."""
|
||||||
self.assertRaises(Error, self.provider.override, object())
|
self.assertRaises(Error, self.provider.override, object())
|
||||||
|
|
||||||
|
def test_reset_override(self):
|
||||||
|
"""Test reset of provider's override."""
|
||||||
|
overriding_provider = Provider()
|
||||||
|
self.provider.override(overriding_provider)
|
||||||
|
|
||||||
|
self.assertTrue(self.provider.overridden)
|
||||||
|
self.assertIs(self.provider.last_overriding, overriding_provider)
|
||||||
|
|
||||||
|
self.provider.reset_override()
|
||||||
|
|
||||||
|
self.assertFalse(self.provider.overridden)
|
||||||
|
try:
|
||||||
|
self.provider.last_overriding
|
||||||
|
except Error:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.fail('Got en error in {}'.format(
|
||||||
|
str(self.test_last_overriding_of_not_overridden_provider)))
|
||||||
|
|
||||||
def test_last_overriding(self):
|
def test_last_overriding(self):
|
||||||
"""Test getting last overriding provider."""
|
"""Test getting last overriding provider."""
|
||||||
overriding_provider1 = Provider()
|
overriding_provider1 = Provider()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user