Add missing 'autospec' statements to unit test mocks
Add missing 'autospec' statements to unit test mocks. This helps to make sure we don't accidentally call invalid assert methods. Change-Id: I8dd2a3165b983dcc105e412717453b3bf3293546
This commit is contained in:
parent
d063e1e2fd
commit
866a34ccab
|
@ -1058,7 +1058,7 @@ class WholeDiskConfigDriveTestCases(test_base.BaseTestCase):
|
|||
|
||||
@mock.patch.object(disk_utils, 'count_mbr_partitions', autospec=True)
|
||||
@mock.patch.object(utils, 'execute', autospec=True)
|
||||
@mock.patch.object(disk_utils.LOG, 'warning')
|
||||
@mock.patch.object(disk_utils.LOG, 'warning', autospec=True)
|
||||
@mock.patch.object(utils, 'unlink_without_raise',
|
||||
autospec=True)
|
||||
@mock.patch.object(disk_utils, 'dd',
|
||||
|
|
|
@ -21,6 +21,11 @@ from oslotest import base as test_base
|
|||
from ironic_lib import metrics_statsd
|
||||
|
||||
|
||||
def connect(family=None, type=None, proto=None):
|
||||
"""Dummy function to provide signature for autospec"""
|
||||
pass
|
||||
|
||||
|
||||
class TestStatsdMetricLogger(test_base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestStatsdMetricLogger, self).setUp()
|
||||
|
@ -56,14 +61,14 @@ class TestStatsdMetricLogger(test_base.BaseTestCase):
|
|||
self.ml._timer('metric', 10)
|
||||
mock_send.assert_called_once_with(self.ml, 'metric', 10, 'ms')
|
||||
|
||||
@mock.patch('socket.socket')
|
||||
@mock.patch('socket.socket', autospec=connect)
|
||||
def test_open_socket(self, mock_socket_constructor):
|
||||
self.ml._open_socket()
|
||||
mock_socket_constructor.assert_called_once_with(
|
||||
socket.AF_INET,
|
||||
socket.SOCK_DGRAM)
|
||||
|
||||
@mock.patch('socket.socket')
|
||||
@mock.patch('socket.socket', autospec=connect)
|
||||
def test_send(self, mock_socket_constructor):
|
||||
mock_socket = mock.Mock()
|
||||
mock_socket_constructor.return_value = mock_socket
|
||||
|
|
|
@ -195,7 +195,8 @@ grep foo
|
|||
|
||||
@mock.patch.object(utils, 'LOG', autospec=True)
|
||||
def _test_execute_with_log_stdout(self, log_mock, log_stdout=None):
|
||||
with mock.patch.object(processutils, 'execute') as execute_mock:
|
||||
with mock.patch.object(
|
||||
processutils, 'execute', autospec=True) as execute_mock:
|
||||
execute_mock.return_value = ('stdout', 'stderr')
|
||||
if log_stdout is not None:
|
||||
utils.execute('foo', log_stdout=log_stdout)
|
||||
|
|
Loading…
Reference in New Issue