Add ability to reset provider override

This commit is contained in:
Roman Mogilatov 2015-03-20 13:32:11 +02:00
parent 22b28d0023
commit 3b880d12a5
2 changed files with 23 additions and 0 deletions

View File

@ -34,6 +34,10 @@ class Provider(object):
"""Override provider with another provider."""
self.overridden.append(ensure_is_provider(provider))
def reset_override(self):
"""Reset all overriding providers."""
self.overridden = list()
@property
def last_overriding(self):
"""Return last overriding provider."""

View File

@ -65,6 +65,25 @@ class ProviderTests(unittest.TestCase):
"""Test provider overriding with not provider instance."""
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):
"""Test getting last overriding provider."""
overriding_provider1 = Provider()