Fix for mock-1.1.0

This includes 2 classes of fixes (and 1 skip) for mock.

The first is the change in allowed values for assert_has_calls -
https://github.com/testing-cabal/mock/issues/263

The second is a yet unsolved bug around the use of autospec
https://github.com/testing-cabal/mock/issues/264

The skip is because something has changed with mock.open that is
causing the vhduils test to fail. We don't know why, but it's one test
to skip.

This also includes a brute force fix for tox -e docs, because pip is
no longer respecting the sphinx pin in test requirements. This has to
be landed with the other changes because they won't work without it.

Change-Id: Id835d080a1ada52cbd3f24dad9bab5eeb2f29a54
Partial-Bug: 1473401
This commit is contained in:
ghanshyam 2015-07-10 21:26:41 +09:00 committed by Sean Dague
parent 22c3e7437a
commit 4442979e71
6 changed files with 31 additions and 23 deletions

View File

@ -190,7 +190,7 @@ class ConfirmPathTestCase(test.NoDBTestCase):
result = idmapshift.confirm_path('/test/path', uid_ranges, gid_ranges,
50000)
mock_lstat.assert_has_calls(mock.call('/test/path'))
mock_lstat.assert_has_calls([mock.call('/test/path')])
self.assertTrue(result)
@mock.patch('os.lstat')
@ -202,7 +202,7 @@ class ConfirmPathTestCase(test.NoDBTestCase):
result = idmapshift.confirm_path('/test/path', uid_ranges, gid_ranges,
50000)
mock_lstat.assert_has_calls(mock.call('/test/path'))
mock_lstat.assert_has_calls([mock.call('/test/path')])
self.assertTrue(result)
@mock.patch('os.lstat')
@ -214,7 +214,7 @@ class ConfirmPathTestCase(test.NoDBTestCase):
result = idmapshift.confirm_path('/test/path', uid_ranges, gid_ranges,
50000)
mock_lstat.assert_has_calls(mock.call('/test/path'))
mock_lstat.assert_has_calls([mock.call('/test/path')])
self.assertFalse(result)
@mock.patch('os.lstat')
@ -226,7 +226,7 @@ class ConfirmPathTestCase(test.NoDBTestCase):
result = idmapshift.confirm_path('/test/path', uid_ranges, gid_ranges,
50000)
mock_lstat.assert_has_calls(mock.call('/test/path'))
mock_lstat.assert_has_calls([mock.call('/test/path')])
self.assertFalse(result)
@mock.patch('os.lstat')
@ -238,7 +238,7 @@ class ConfirmPathTestCase(test.NoDBTestCase):
result = idmapshift.confirm_path('/test/path', uid_ranges, gid_ranges,
50000)
mock_lstat.assert_has_calls(mock.call('/test/path'))
mock_lstat.assert_has_calls([mock.call('/test/path')])
self.assertTrue(result)
@mock.patch('os.lstat')
@ -250,7 +250,7 @@ class ConfirmPathTestCase(test.NoDBTestCase):
result = idmapshift.confirm_path('/test/path', uid_ranges, gid_ranges,
50000)
mock_lstat.assert_has_calls(mock.call('/test/path'))
mock_lstat.assert_has_calls([mock.call('/test/path')])
self.assertTrue(result)

View File

@ -1372,9 +1372,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self.compute.attach_interface,
self.context, f_instance, 'net_id', 'port_id',
None)
add_fault.assert_has_calls(
add_fault.assert_has_calls([
mock.call(self.context, f_instance, e,
mock.ANY))
mock.ANY)])
do_test()
@ -1393,7 +1393,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self.compute.detach_interface,
self.context, f_instance, 'port_id')
add_fault.assert_has_calls(
mock.call(self.context, f_instance, mock.ANY, mock.ANY))
[mock.call(self.context, f_instance, mock.ANY, mock.ANY)])
do_test()
@ -3064,8 +3064,8 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
_validate_instance_group_policy.assert_called_once_with(
self.context, self.instance, self.filter_properties)
_build_networks_for_instance.assert_has_calls(
mock.call(self.context, self.instance,
self.requested_networks, self.security_groups))
[mock.call(self.context, self.instance,
self.requested_networks, self.security_groups)])
_notify_about_instance_usage.assert_has_calls([
mock.call(self.context, self.instance, 'create.start',
@ -3079,10 +3079,10 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
mock.call(
expected_task_state=task_states.BLOCK_DEVICE_MAPPING)])
spawn.assert_has_calls(mock.call(self.context, self.instance,
spawn.assert_has_calls([mock.call(self.context, self.instance,
self.image, self.injected_files, self.admin_pass,
network_info=self.network_info,
block_device_info=self.block_device_info))
block_device_info=self.block_device_info)])
_shutdown_instance.assert_called_once_with(self.context,
self.instance, self.block_device_mapping,
@ -3190,10 +3190,10 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
exception.UnexpectedDeletingTaskStateError)
_build_networks_for_instance.assert_has_calls(
mock.call(self.context, self.instance,
self.requested_networks, self.security_groups))
[mock.call(self.context, self.instance,
self.requested_networks, self.security_groups)])
save.assert_has_calls(mock.call())
save.assert_has_calls([mock.call()])
def test_build_resources_aborts_on_failed_network_alloc(self):
self.mox.StubOutWithMock(self.compute, '_build_networks_for_instance')
@ -3227,8 +3227,8 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
self.assertIsInstance(e, exc)
_build_networks.assert_has_calls(
mock.call(self.context, self.instance,
self.requested_networks, self.security_groups))
[mock.call(self.context, self.instance,
self.requested_networks, self.security_groups)])
def test_build_resources_with_network_info_obj_on_spawn_failure(self):
self.mox.StubOutWithMock(self.compute, '_build_networks_for_instance')

View File

@ -14,6 +14,7 @@
import mock
from oslo_utils import units
import testtools
from nova import test
from nova.virt.hyperv import constants
@ -242,6 +243,7 @@ class VHDUtilsTestCase(VHDUtilsBaseTestCase):
self.assertEqual(constants.DISK_FORMAT_VHDX, format)
def test_get_vhd_format_vhd(self):
raise testtools.TestCase.skipException("Bug 1473401")
with mock.patch('nova.virt.hyperv.vhdutils.open',
mock.mock_open(read_data=vhdutils.VHD_SIGNATURE),
create=True) as mock_open:

View File

@ -974,7 +974,8 @@ class VMOpsTestCase(test_base.HyperVBaseTestCase):
mock.sentinel.FAKE_PATH, mock.sentinel.FAKE_PATH_ARCHIVED)
with mock.patch('nova.virt.hyperv.vmops.open',
mock.mock_open(read_data=self.FAKE_LOG), create=True):
mock.mock_open(read_data=self.FAKE_LOG * 2),
create=True):
instance_log = self._vmops.get_console_output(mock_instance)
# get_vm_console_log_paths returns 2 paths.
self.assertEqual(self.FAKE_LOG * 2, instance_log)

View File

@ -114,7 +114,7 @@ class CallPluginTestCase(stubs.XenAPITestBaseNoDB):
callback = None
retry_cb = mock.Mock()
with mock.patch.object(self.session, 'call_plugin_serialized',
autospec=True) as call_plugin_serialized:
spec=True) as call_plugin_serialized:
call_plugin_serialized.side_effect = exc
self.assertRaises(exception.PluginRetriesExceeded,
self.session.call_plugin_serialized_with_retry, plugin, fn,
@ -132,7 +132,7 @@ class CallPluginTestCase(stubs.XenAPITestBaseNoDB):
callback = None
retry_cb = mock.Mock()
with mock.patch.object(self.session, 'call_plugin_serialized',
autospec=True) as call_plugin_serialized:
spec=True) as call_plugin_serialized:
call_plugin_serialized.side_effect = exc
self.assertRaises(socket.error,
self.session.call_plugin_serialized_with_retry, plugin, fn,
@ -149,7 +149,7 @@ class CallPluginTestCase(stubs.XenAPITestBaseNoDB):
callback = None
retry_cb = mock.Mock()
with mock.patch.object(self.session, 'call_plugin_serialized',
autospec=True) as call_plugin_serialized:
spec=True) as call_plugin_serialized:
call_plugin_serialized.side_effect = exc
self.assertRaises(exception.PluginRetriesExceeded,
self.session.call_plugin_serialized_with_retry, plugin, fn,

View File

@ -104,10 +104,15 @@ commands =
coverage html --include='nova/*' --omit='nova/openstack/common/*' -d covhtml -i
[testenv:venv]
commands = {posargs}
commands =
# TODO(sdague) this is a brute force work around for pip not respecting test-requirements.txt
pip install "sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2"
{posargs}
[testenv:docs]
commands =
# TODO(sdague) this is a brute force work around for pip not respecting test-requirements.txt
pip install "sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2"
python setup.py build_sphinx
bash -c '! find doc/ -type f -name *.json | xargs -t -n1 python -m json.tool 2>&1 > /dev/null | grep -B1 -v ^python'