Make Provider.last_overriding None by default

This commit is contained in:
Roman Mogilatov 2015-11-25 13:25:40 +02:00
parent dd80bb3c17
commit b7f42a3ff4
2 changed files with 5 additions and 20 deletions

View File

@ -76,12 +76,9 @@ class Provider(object):
def last_overriding(self): def last_overriding(self):
"""Read-only reference to the last overriding provider, if any. """Read-only reference to the last overriding provider, if any.
:type: :py:class:`Provider` :type: :py:class:`Provider` | None
""" """
try: return self.overridden_by[-1] if self.overridden_by else None
return self.overridden_by[-1]
except (TypeError, IndexError):
raise Error('Provider {0} is not overridden'.format(str(self)))
def override(self, provider): def override(self, provider):
"""Override provider with another provider. """Override provider with another provider.
@ -104,7 +101,7 @@ class Provider(object):
:rtype: None :rtype: None
""" """
if not self.is_overridden: if not self.overridden_by:
raise Error('Provider {0} is not overridden'.format(str(self))) raise Error('Provider {0} is not overridden'.format(str(self)))
self.overridden_by = self.overridden_by[:-1] self.overridden_by = self.overridden_by[:-1]

View File

@ -90,13 +90,7 @@ class ProviderTests(unittest.TestCase):
def test_last_overriding_of_not_overridden_provider(self): def test_last_overriding_of_not_overridden_provider(self):
"""Test getting last overriding from not overridden provider.""" """Test getting last overriding from not overridden provider."""
try: self.assertIsNone(self.provider.last_overriding)
self.provider.last_overriding
except errors.Error:
pass
else:
self.fail('Got en error in {}'.format(
str(self.test_last_overriding_of_not_overridden_provider)))
def test_reset_last_overriding(self): def test_reset_last_overriding(self):
"""Test reseting of last overriding provider.""" """Test reseting of last overriding provider."""
@ -129,13 +123,7 @@ class ProviderTests(unittest.TestCase):
self.provider.reset_override() self.provider.reset_override()
self.assertFalse(self.provider.is_overridden) self.assertFalse(self.provider.is_overridden)
try: self.assertIsNone(self.provider.last_overriding)
self.provider.last_overriding
except errors.Error:
pass
else:
self.fail('Got en error in {}'.format(
str(self.test_last_overriding_of_not_overridden_provider)))
class DelegateTests(unittest.TestCase): class DelegateTests(unittest.TestCase):