Merge "Remove "patch mock to raise for invalid assert calls""
This commit is contained in:
commit
bec0dd843b
@ -101,29 +101,6 @@ class Database(fixtures.Fixture):
|
|||||||
os.path.join(CONF.state_path, self.sqlite_db))
|
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):
|
class TestCase(testtools.TestCase):
|
||||||
"""Test case base class for all unit tests."""
|
"""Test case base class for all unit tests."""
|
||||||
|
|
||||||
|
@ -71,9 +71,3 @@ class MockAssertTestCase(test.TestCase):
|
|||||||
mock_call = mock.MagicMock(return_value=None)
|
mock_call = mock.MagicMock(return_value=None)
|
||||||
mock_call(1, 'foobar', a='123')
|
mock_call(1, 'foobar', a='123')
|
||||||
mock_call.assert_called_once_with(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)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user