Add Provider.last_overriding read-only property

This commit is contained in:
Roman Mogilatov 2017-05-08 17:07:22 +03:00
parent 0766df39d7
commit e8bd524b6d
4 changed files with 1944 additions and 1867 deletions

View File

@ -11,6 +11,12 @@ Development version
------------------- -------------------
- No features. - No features.
3.4.4
-----
- Add ``Provider.last_overriding`` read-only property that points to last
overriding provider, if any. If target provider is not overridden, ``None``
would be returned.
3.4.3 3.4.3
----- -----
- Update doc block for ``Provider.overriding_lock`` attribute. - Update doc block for ``Provider.overriding_lock`` attribute.

File diff suppressed because it is too large Load Diff

View File

@ -129,6 +129,14 @@ cdef class Provider(object):
with self.__overriding_lock: with self.__overriding_lock:
return self.__overridden return self.__overridden
@property
def last_overriding(self):
"""Return last overriding provider.
If provider is not overridden, then None is returned.
"""
return self.__last_overriding
def override(self, provider): def override(self, provider):
"""Override provider with another provider. """Override provider with another provider.

View File

@ -36,6 +36,7 @@ class ProviderTests(unittest.TestCase):
overriding_provider = providers.Provider() overriding_provider = providers.Provider()
self.provider.override(overriding_provider) self.provider.override(overriding_provider)
self.assertTrue(self.provider.overridden) self.assertTrue(self.provider.overridden)
self.assertIs(self.provider.last_overriding, overriding_provider)
def test_overriding_context(self): def test_overriding_context(self):
overriding_provider = providers.Provider() overriding_provider = providers.Provider()
@ -59,12 +60,15 @@ class ProviderTests(unittest.TestCase):
self.provider.override(overriding_provider2) self.provider.override(overriding_provider2)
self.assertIs(self.provider.overridden[-1], overriding_provider2) self.assertIs(self.provider.overridden[-1], overriding_provider2)
self.assertIs(self.provider.last_overriding, overriding_provider2)
self.provider.reset_last_overriding() self.provider.reset_last_overriding()
self.assertIs(self.provider.overridden[-1], overriding_provider1) self.assertIs(self.provider.overridden[-1], overriding_provider1)
self.assertIs(self.provider.last_overriding, overriding_provider1)
self.provider.reset_last_overriding() self.provider.reset_last_overriding()
self.assertFalse(self.provider.overridden) self.assertFalse(self.provider.overridden)
self.assertIsNone(self.provider.last_overriding)
def test_reset_last_overriding_of_not_overridden_provider(self): def test_reset_last_overriding_of_not_overridden_provider(self):
self.assertRaises(errors.Error, self.provider.reset_last_overriding) self.assertRaises(errors.Error, self.provider.reset_last_overriding)