#4071 Mixin to prevent setting return_value after initializing certain Mock objects (#4963)

* Addressing #4071 Wrote an ImmutableReturnMixin to prevent developers overriding return_value in certain Mock objects

* Language

* Loosening the assumption that underlying _mock objects need to be Immutable-like simplifies implementation

* Addressing #4071

* Ensure side_effects and return_values are pushed down to the underlying _mock in FreezableMocks. And IDisplay mocks are no longer frozen in _create_get_utility_mock()

* Edit a handful of tests to not override the mock_get_utility return_value

* Brief explainer of FreezableMock.__setattr__

* Incorporating PR feedback and some compatibility

* FreezableMock __getattr__ needs a shortcut in case of return_value or side_effect

* Changing return_value only forbidden if set before freezing

* Remove unnecessary else block

* Expanded doc strings

* Bring a couple new tests in line with patch_get_utility() norms
This commit is contained in:
Chris Julian
2017-08-30 09:52:45 -07:00
committed by Brad Warren
parent ae0be73b53
commit 2bfc92e58d
6 changed files with 55 additions and 33 deletions
+4 -2
View File
@@ -158,10 +158,11 @@ class AuthenticatorTest(unittest.TestCase):
@test_util.patch_get_utility()
def test_perform_eaddrinuse_retry(self, mock_get_utility):
mock_utility = mock_get_utility()
errno = socket.errno.EADDRINUSE
error = errors.StandaloneBindError(mock.MagicMock(errno=errno), -1)
self.auth.servers.run.side_effect = [error] + 2 * [mock.MagicMock()]
mock_yesno = mock_get_utility.return_value.yesno
mock_yesno = mock_utility.yesno
mock_yesno.return_value = True
self.test_perform()
@@ -169,7 +170,8 @@ class AuthenticatorTest(unittest.TestCase):
@test_util.patch_get_utility()
def test_perform_eaddrinuse_no_retry(self, mock_get_utility):
mock_yesno = mock_get_utility.return_value.yesno
mock_utility = mock_get_utility()
mock_yesno = mock_utility.yesno
mock_yesno.return_value = False
errno = socket.errno.EADDRINUSE