Merge "Remove "patch mock to raise for invalid assert calls""

This commit is contained in:
Jenkins 2016-04-07 00:40:36 +00:00 committed by Gerrit Code Review
commit bec0dd843b
2 changed files with 0 additions and 29 deletions

View File

@ -101,29 +101,6 @@ class Database(fixtures.Fixture):
os.path.join(CONF.state_path, self.sqlite_db))
def _patch_mock_to_raise_for_invalid_assert_calls():
def raise_for_invalid_assert_calls(wrapped):
def wrapper(_self, name):
valid_asserts = [
'assert_called_with',
'assert_called_once_with',
'assert_has_calls',
'assert_any_call']
if name.startswith('assert') and name not in valid_asserts:
raise AttributeError('%s is not a valid mock assert method'
% name)
return wrapped(_self, name)
return wrapper
mock.Mock.__getattr__ = raise_for_invalid_assert_calls(
mock.Mock.__getattr__)
# NOTE(gibi): needs to be called only once at import time
# to patch the mock lib
_patch_mock_to_raise_for_invalid_assert_calls()
class TestCase(testtools.TestCase):
"""Test case base class for all unit tests."""

View File

@ -71,9 +71,3 @@ class MockAssertTestCase(test.TestCase):
mock_call = mock.MagicMock(return_value=None)
mock_call(1, 'foobar', a='123')
mock_call.assert_called_once_with(1, 'foobar', a='123')
def test_invalid_assert_calls(self):
mock_call = mock.MagicMock()
self.assertRaises(AttributeError, lambda: mock_call.assert_called)
self.assertRaises(AttributeError,
lambda: mock_call.assert_once_called_with)