Merge "Replaces __builtin__ with six.moves.builtins"

This commit is contained in:
Jenkins
2015-12-04 17:59:42 +00:00
committed by Gerrit Code Review
6 changed files with 18 additions and 19 deletions

View File

@@ -21,6 +21,7 @@ import glanceclient.exc
import mock
from oslo_config import cfg
from oslo_utils import netutils
import six
import testtools
from nova import context
@@ -459,7 +460,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
default of not allowing direct URI transfers is set.
"""
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageService.show')
def test_download_no_data_no_dest_path(self, show_mock, open_mock):
client = mock.MagicMock()
@@ -474,7 +475,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
mock.sentinel.image_id)
self.assertEqual(mock.sentinel.image_chunks, res)
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageService.show')
def test_download_data_no_dest_path(self, show_mock, open_mock):
client = mock.MagicMock()
@@ -498,7 +499,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
)
self.assertFalse(data.close.called)
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageService.show')
def test_download_no_data_dest_path(self, show_mock, open_mock):
client = mock.MagicMock()
@@ -524,7 +525,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
)
writer.close.assert_called_once_with()
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageService.show')
def test_download_data_dest_path(self, show_mock, open_mock):
# NOTE(jaypipes): This really shouldn't be allowed, but because of the
@@ -553,7 +554,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
)
self.assertFalse(data.close.called)
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageService.show')
def test_download_data_dest_path_write_fails(self, show_mock, open_mock):
client = mock.MagicMock()
@@ -603,7 +604,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
mock.sentinel.dst_path,
mock.sentinel.loc_meta)
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageService._get_transfer_module')
@mock.patch('nova.image.glance.GlanceImageService.show')
def test_download_direct_exception_fallback(self, show_mock,
@@ -656,7 +657,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
]
)
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('nova.image.glance.GlanceImageService._get_transfer_module')
@mock.patch('nova.image.glance.GlanceImageService.show')
def test_download_direct_no_mod_fallback(self, show_mock,

View File

@@ -3912,7 +3912,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
self.flags(sysinfo_serial="os", group="libvirt")
theuuid = "56b40135-a973-4eb3-87bb-a2382a3e6dbc"
with test.nested(
mock.patch('__builtin__.open',
mock.patch.object(six.moves.builtins, "open",
mock.mock_open(read_data=theuuid)),
self.patch_exists(True)):
self._test_get_guest_config_sysinfo_serial(theuuid)
@@ -3920,7 +3920,8 @@ class LibvirtConnTestCase(test.NoDBTestCase):
def test_get_guest_config_sysinfo_serial_os_empty_machine_id(self):
self.flags(sysinfo_serial="os", group="libvirt")
with test.nested(
mock.patch('__builtin__.open', mock.mock_open(read_data="")),
mock.patch.object(six.moves.builtins, "open",
mock.mock_open(read_data="")),
self.patch_exists(True)):
self.assertRaises(exception.NovaException,
self._test_get_guest_config_sysinfo_serial,

View File

@@ -19,6 +19,7 @@ import uuid
import eventlet
from eventlet import greenthread
import mock
import six
from nova.compute import arch
from nova import exception
@@ -772,7 +773,7 @@ SwapCached: 0 kB
Active: 8381604 kB
""")
with test.nested(
mock.patch("__builtin__.open", m, create=True),
mock.patch.object(six.moves.builtins, "open", m, create=True),
mock.patch.object(host.Host,
"get_connection"),
mock.patch('sys.platform', 'linux2'),
@@ -813,7 +814,7 @@ Active: 8381604 kB
""")
with test.nested(
mock.patch("__builtin__.open", m, create=True),
mock.patch.object(six.moves.builtins, "open", m, create=True),
mock.patch.object(host.Host,
"list_instance_domains"),
mock.patch.object(libvirt_driver.LibvirtDriver,

View File

@@ -124,7 +124,7 @@ class TestDiskImage(test.NoDBTestCase):
response = io.StringIO(six.text_type(PROC_MOUNTS_CONTENTS))
mock_open.return_value = response
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
def test_mount(self, mock_open):
self.mock_proc_mounts(mock_open)
image = '/tmp/fake-image'
@@ -141,7 +141,7 @@ class TestDiskImage(test.NoDBTestCase):
self.assertEqual(diskimage._mounter, fakemount)
self.assertEqual(dev, '/dev/fake')
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
def test_umount(self, mock_open):
self.mock_proc_mounts(mock_open)
@@ -161,7 +161,7 @@ class TestDiskImage(test.NoDBTestCase):
diskimage.umount()
self.assertIsNone(diskimage._mounter)
@mock.patch('__builtin__.open')
@mock.patch.object(six.moves.builtins, 'open')
def test_teardown(self, mock_open):
self.mock_proc_mounts(mock_open)

View File

@@ -1282,7 +1282,6 @@ class FakeFile(object):
class StreamDiskTestCase(VMUtilsTestBase):
def setUp(self):
import __builtin__
super(StreamDiskTestCase, self).setUp()
self.mox.StubOutWithMock(vm_utils.utils, 'make_dev_path')
self.mox.StubOutWithMock(vm_utils.utils, 'temporary_chown')
@@ -1290,7 +1289,7 @@ class StreamDiskTestCase(VMUtilsTestBase):
# NOTE(matelakat): This might hide the fail reason, as test runners
# are unhappy with a mocked out open.
self.mox.StubOutWithMock(__builtin__, 'open')
self.mox.StubOutWithMock(six.moves.builtins, 'open')
self.image_service_func = self.mox.CreateMockAnything()
def test_non_ami(self):

View File

@@ -191,7 +191,6 @@ nova.tests.unit.db.test_migrations.TestNovaMigrationsMySQL
nova.tests.unit.db.test_migrations.TestNovaMigrationsPostgreSQL
nova.tests.unit.db.test_migrations.TestNovaMigrationsSQLite
nova.tests.unit.image.test_fake.FakeImageServiceTestCase
nova.tests.unit.image.test_glance.TestDownloadNoDirectUri
nova.tests.unit.image.test_s3.TestS3ImageService
nova.tests.unit.keymgr.test_barbican.BarbicanKeyManagerTestCase
nova.tests.unit.keymgr.test_conf_key_mgr.ConfKeyManagerTestCase
@@ -297,7 +296,6 @@ nova.tests.unit.virt.libvirt.test_vif.LibvirtVifTestCase
nova.tests.unit.virt.test_block_device.TestDriverBlockDevice
nova.tests.unit.virt.test_hardware.CPUPinningCellTestCase
nova.tests.unit.virt.test_hardware.CPUPinningTestCase
nova.tests.unit.virt.test_virt.TestDiskImage
nova.tests.unit.virt.test_virt_drivers.AbstractDriverTestCase
nova.tests.unit.virt.test_virt_drivers.FakeConnectionTestCase
nova.tests.unit.virt.test_virt_drivers.LibvirtConnTestCase
@@ -329,7 +327,6 @@ nova.tests.unit.virt.xenapi.test_vm_utils.CreateVmTestCase
nova.tests.unit.virt.xenapi.test_vm_utils.GenerateDiskTestCase
nova.tests.unit.virt.xenapi.test_vm_utils.ResizeFunctionTestCase
nova.tests.unit.virt.xenapi.test_vm_utils.ScanSrTestCase
nova.tests.unit.virt.xenapi.test_vm_utils.StreamDiskTestCase
nova.tests.unit.virt.xenapi.test_vm_utils.UnplugVbdTestCase
nova.tests.unit.virt.xenapi.test_vm_utils.VMInfoTests
nova.tests.unit.virt.xenapi.test_vm_utils.VMUtilsSRPath