Comply with new hacking 0.8 release

Fixes a couple of small issues to pass all PEP8 tests in
the new hacking release

H235  assert_ is deprecated, use assertTrue
H231  Python 3.x incompatible 'except x,y:' construct
H234  assertEquals is deprecated, use assertEqual
H301  one import per line
H302  import only modules
H233  Python 3.x incompatible use of print operator

Change-Id: I0e5e74944e2b034b223ada1b3d0be66f2a9a5722
This commit is contained in:
Zhongyue Luo 2013-11-26 18:22:06 +09:00
parent 652620d12f
commit e306800345
11 changed files with 39 additions and 39 deletions

View File

@ -51,7 +51,7 @@ class ComputeDriverCPUMonitorTestCase(test.TestCase):
def test_get_metric_names(self): def test_get_metric_names(self):
names = self.monitor.get_metric_names() names = self.monitor.get_metric_names()
self.assertEquals(10, len(names)) self.assertEqual(10, len(names))
self.assertIn("cpu.frequency", names) self.assertIn("cpu.frequency", names)
self.assertIn("cpu.user.time", names) self.assertIn("cpu.user.time", names)
self.assertIn("cpu.kernel.time", names) self.assertIn("cpu.kernel.time", names)

View File

@ -40,7 +40,7 @@ class ResourceMonitorBaseTestCase(test.TestCase):
def test_get_metric_names(self): def test_get_metric_names(self):
names = self.monitor.get_metric_names() names = self.monitor.get_metric_names()
self.assertEquals(2, len(names)) self.assertEqual(2, len(names))
self.assertIn("foo.metric1", names) self.assertIn("foo.metric1", names)
self.assertIn("foo.metric2", names) self.assertIn("foo.metric2", names)
@ -52,8 +52,8 @@ class ResourceMonitorBaseTestCase(test.TestCase):
self.assertIn(metric['name'], names) self.assertIn(metric['name'], names)
metrics[metric['name']] = metric['value'] metrics[metric['name']] = metric['value']
self.assertEquals(metrics["foo.metric1"], '1000') self.assertEqual(metrics["foo.metric1"], '1000')
self.assertEquals(metrics["foo.metric2"], '99.999') self.assertEqual(metrics["foo.metric2"], '99.999')
class ResourceMonitorsTestCase(test.TestCase): class ResourceMonitorsTestCase(test.TestCase):

View File

@ -26,7 +26,7 @@ import time
import sys import sys
import testtools import testtools
from mock import patch import mock
import mox import mox
import glanceclient.exc import glanceclient.exc
@ -35,7 +35,6 @@ from oslo.config import cfg
from nova import context from nova import context
from nova import exception from nova import exception
from nova.image import glance from nova.image import glance
from nova.image.glance import GlanceClientWrapper
from nova import test from nova import test
from nova.tests.api.openstack import fakes from nova.tests.api.openstack import fakes
from nova.tests.glance import stubs as glance_stubs from nova.tests.glance import stubs as glance_stubs
@ -307,7 +306,7 @@ class TestGlanceImageService(test.NoDBTestCase):
self.assertEqual(len(image_metas), 5) self.assertEqual(len(image_metas), 5)
def test_page_size(self): def test_page_size(self):
with patch.object(GlanceClientWrapper, 'call') as a_mock: with mock.patch.object(glance.GlanceClientWrapper, 'call') as a_mock:
self.service.detail(self.context, page_size=5) self.service.detail(self.context, page_size=5)
self.assertEqual(a_mock.called, True) self.assertEqual(a_mock.called, True)
a_mock.assert_called_with(self.context, 1, 'list', a_mock.assert_called_with(self.context, 1, 'list',

View File

@ -111,7 +111,7 @@ class TestNeutronDriver(test.NoDBTestCase):
sg_api = neutron_driver.SecurityGroupAPI() sg_api = neutron_driver.SecurityGroupAPI()
result = sg_api.get_instances_security_groups_bindings( result = sg_api.get_instances_security_groups_bindings(
self.context, servers) self.context, servers)
self.assertEquals(result, sg_bindings) self.assertEqual(result, sg_bindings)
def _test_instances_security_group_bindings_scale(self, num_servers): def _test_instances_security_group_bindings_scale(self, num_servers):
max_query = 150 max_query = 150
@ -146,7 +146,7 @@ class TestNeutronDriver(test.NoDBTestCase):
sg_api = neutron_driver.SecurityGroupAPI() sg_api = neutron_driver.SecurityGroupAPI()
result = sg_api.get_instances_security_groups_bindings( result = sg_api.get_instances_security_groups_bindings(
self.context, servers) self.context, servers)
self.assertEquals(result, sg_bindings) self.assertEqual(result, sg_bindings)
def test_instances_security_group_bindings_less_than_max(self): def test_instances_security_group_bindings_less_than_max(self):
self._test_instances_security_group_bindings_scale(100) self._test_instances_security_group_bindings_scale(100)
@ -178,4 +178,4 @@ class TestNeutronDriver(test.NoDBTestCase):
sg_api = neutron_driver.SecurityGroupAPI() sg_api = neutron_driver.SecurityGroupAPI()
result = sg_api.get_instances_security_groups_bindings( result = sg_api.get_instances_security_groups_bindings(
self.context, servers) self.context, servers)
self.assertEquals(result, sg_bindings) self.assertEqual(result, sg_bindings)

View File

@ -29,8 +29,8 @@ from nova import exception
from nova import network from nova import network
from nova.network import api from nova.network import api
from nova.network import floating_ips from nova.network import floating_ips
from nova.network import model as network_model
from nova.network import rpcapi as network_rpcapi from nova.network import rpcapi as network_rpcapi
from nova.network.model import NetworkInfo, VIF
from nova import policy from nova import policy
from nova import test from nova import test
from nova import utils from nova import utils
@ -295,7 +295,8 @@ class TestUpdateInstanceCache(test.TestCase):
self.context = context.get_admin_context() self.context = context.get_admin_context()
self.instance = {'uuid': FAKE_UUID} self.instance = {'uuid': FAKE_UUID}
self.impl = self.mox.CreateMock(api.API) self.impl = self.mox.CreateMock(api.API)
self.nw_info = NetworkInfo([VIF(id='super_vif')]) vifs = [network_model.VIF(id='super_vif')]
self.nw_info = network_model.NetworkInfo(vifs)
self.is_nw_info = mox.Func(lambda d: 'super_vif' in d['network_info']) self.is_nw_info = mox.Func(lambda d: 'super_vif' in d['network_info'])
def expect_cache_update(self, nw_info): def expect_cache_update(self, nw_info):
@ -322,12 +323,13 @@ class TestUpdateInstanceCache(test.TestCase):
self.expect_cache_update({'network_info': '[]'}) self.expect_cache_update({'network_info': '[]'})
self.mox.ReplayAll() self.mox.ReplayAll()
api.update_instance_cache_with_nw_info(self.impl, self.context, api.update_instance_cache_with_nw_info(self.impl, self.context,
self.instance, NetworkInfo([])) self.instance,
network_model.NetworkInfo([]))
def test_decorator_return_object(self): def test_decorator_return_object(self):
@api.refresh_cache @api.refresh_cache
def func(self, context, instance): def func(self, context, instance):
return NetworkInfo([]) return network_model.NetworkInfo([])
self.expect_cache_update({'network_info': '[]'}) self.expect_cache_update({'network_info': '[]'})
self.mox.ReplayAll() self.mox.ReplayAll()
func(self.impl, self.context, self.instance) func(self.impl, self.context, self.instance)

View File

@ -82,7 +82,7 @@ class QuotaIntegrationTestCase(test.TestCase):
try: try:
compute.API().create(self.context, min_count=1, max_count=1, compute.API().create(self.context, min_count=1, max_count=1,
instance_type=inst_type, image_href=image_uuid) instance_type=inst_type, image_href=image_uuid)
except exception.QuotaError, e: except exception.QuotaError as e:
expected_kwargs = {'code': 413, 'resource': 'cores', 'req': 1, expected_kwargs = {'code': 413, 'resource': 'cores', 'req': 1,
'used': 4, 'allowed': 4, 'overs': 'cores,instances'} 'used': 4, 'allowed': 4, 'overs': 'cores,instances'}
self.assertEqual(e.kwargs, expected_kwargs) self.assertEqual(e.kwargs, expected_kwargs)
@ -98,7 +98,7 @@ class QuotaIntegrationTestCase(test.TestCase):
try: try:
compute.API().create(self.context, min_count=1, max_count=1, compute.API().create(self.context, min_count=1, max_count=1,
instance_type=inst_type, image_href=image_uuid) instance_type=inst_type, image_href=image_uuid)
except exception.QuotaError, e: except exception.QuotaError as e:
expected_kwargs = {'code': 413, 'resource': 'cores', 'req': 1, expected_kwargs = {'code': 413, 'resource': 'cores', 'req': 1,
'used': 4, 'allowed': 4, 'overs': 'cores'} 'used': 4, 'allowed': 4, 'overs': 'cores'}
self.assertEqual(e.kwargs, expected_kwargs) self.assertEqual(e.kwargs, expected_kwargs)
@ -2332,7 +2332,7 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase):
try: try:
sqa_api.quota_reserve(context, self.resources, self.quotas, sqa_api.quota_reserve(context, self.resources, self.quotas,
self.quotas, self.deltas, self.expire, 0, 0) self.quotas, self.deltas, self.expire, 0, 0)
except exception.OverQuota, e: except exception.OverQuota as e:
expected_kwargs = {'code': 500, expected_kwargs = {'code': 500,
'usages': {'instances': {'reserved': 0, 'in_use': 4}, 'usages': {'instances': {'reserved': 0, 'in_use': 4},
'ram': {'reserved': 0, 'in_use': 10240}, 'ram': {'reserved': 0, 'in_use': 10240},

View File

@ -20,7 +20,7 @@ import os
import fixtures import fixtures
from oslo.config import cfg from oslo.config import cfg
from inspect import getargspec import inspect
from nova import exception from nova import exception
from nova.openstack.common import uuidutils from nova.openstack.common import uuidutils
@ -644,8 +644,8 @@ class RbdTestCase(_ImageTestCase, test.NoDBTestCase):
self.assertEqual(fake_processutils.fake_execute_get_log(), []) self.assertEqual(fake_processutils.fake_execute_get_log(), [])
def test_parent_compatible(self): def test_parent_compatible(self):
self.assertEqual(getargspec(imagebackend.Image.libvirt_info), self.assertEqual(inspect.getargspec(imagebackend.Image.libvirt_info),
getargspec(self.image_class.libvirt_info)) inspect.getargspec(self.image_class.libvirt_info))
class BackendTestCase(test.NoDBTestCase): class BackendTestCase(test.NoDBTestCase):

View File

@ -18,7 +18,7 @@ import fixtures
import os import os
import sys import sys
from posix import stat_result import posix
from nova import exception from nova import exception
from nova import test from nova import test
@ -40,10 +40,10 @@ class VirtDiskTest(test.NoDBTestCase):
def fake_stat(arg): def fake_stat(arg):
if arg == '/some/file': # fake success if arg == '/some/file': # fake success
return stat_result((16877, 2, 2049L, return posix.stat_result((16877, 2, 2049L,
23, 0, 0, 23, 0, 0,
4096, 1381787843, 4096, 1381787843,
1381635971, 1381635971)) 1381635971, 1381635971))
else: else:
return orig_os_stat(arg) return orig_os_stat(arg)

View File

@ -19,7 +19,7 @@ import fixtures
import sys import sys
import traceback import traceback
from mock import MagicMock import mock
import netaddr import netaddr
import six import six
@ -708,7 +708,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase):
self.driver_module = 'nova.virt.libvirt.LibvirtDriver' self.driver_module = 'nova.virt.libvirt.LibvirtDriver'
super(LibvirtConnTestCase, self).setUp() super(LibvirtConnTestCase, self).setUp()
self.stubs.Set(self.connection, self.stubs.Set(self.connection,
'set_host_enabled', MagicMock()) 'set_host_enabled', mock.MagicMock())
self.useFixture(fixtures.MonkeyPatch( self.useFixture(fixtures.MonkeyPatch(
'nova.context.get_admin_context', 'nova.context.get_admin_context',
self._fake_admin_context)) self._fake_admin_context))
@ -727,7 +727,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase):
def test_set_host_enabled(self): def test_set_host_enabled(self):
self.mox.UnsetStubs() self.mox.UnsetStubs()
service_mock = MagicMock() service_mock = mock.MagicMock()
# Previous status of the service: disabled: False # Previous status of the service: disabled: False
# service_mock.__getitem__.return_value = False # service_mock.__getitem__.return_value = False
@ -745,7 +745,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase):
def test_set_host_enabled_when_auto_disabled(self): def test_set_host_enabled_when_auto_disabled(self):
self.mox.UnsetStubs() self.mox.UnsetStubs()
service_mock = MagicMock() service_mock = mock.MagicMock()
# Previous status of the service: disabled: True, 'AUTO: ERROR' # Previous status of the service: disabled: True, 'AUTO: ERROR'
service_mock.configure_mock(disabled_reason='AUTO: ERROR', service_mock.configure_mock(disabled_reason='AUTO: ERROR',
@ -762,7 +762,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase):
def test_set_host_enabled_when_manually_disabled(self): def test_set_host_enabled_when_manually_disabled(self):
self.mox.UnsetStubs() self.mox.UnsetStubs()
service_mock = MagicMock() service_mock = mock.MagicMock()
# Previous status of the service: disabled: True, 'Manually disabled' # Previous status of the service: disabled: True, 'Manually disabled'
service_mock.configure_mock(disabled_reason='Manually disabled', service_mock.configure_mock(disabled_reason='Manually disabled',
@ -779,7 +779,7 @@ class LibvirtConnTestCase(_VirtDriverTestCase, test.TestCase):
def test_set_host_enabled_dont_override_manually_disabled(self): def test_set_host_enabled_dont_override_manually_disabled(self):
self.mox.UnsetStubs() self.mox.UnsetStubs()
service_mock = MagicMock() service_mock = mock.MagicMock()
# Previous status of the service: disabled: True, 'Manually disabled' # Previous status of the service: disabled: True, 'Manually disabled'
service_mock.configure_mock(disabled_reason='Manually disabled', service_mock.configure_mock(disabled_reason='Manually disabled',

View File

@ -4009,7 +4009,6 @@ class XenAPISessionTestCase(test.NoDBTestCase):
with open(path) as plugin_file: with open(path) as plugin_file:
for line in plugin_file: for line in plugin_file:
if "PLUGIN_VERSION = " in line: if "PLUGIN_VERSION = " in line:
print line
plugin_version = line.strip()[17:].strip('"') plugin_version = line.strip()[17:].strip('"')
self.assertEqual(session.PLUGIN_REQUIRED_VERSION, self.assertEqual(session.PLUGIN_REQUIRED_VERSION,

View File

@ -64,7 +64,7 @@ class ImageTests(base.UserSmokeTestCase):
def test_003_can_register_image(self): def test_003_can_register_image(self):
image_id = self.conn.register_image('%s/%s.manifest.xml' % image_id = self.conn.register_image('%s/%s.manifest.xml' %
(TEST_BUCKET, FLAGS.bundle_image)) (TEST_BUCKET, FLAGS.bundle_image))
self.assert_(image_id is not None) self.assertTrue(image_id is not None)
self.data['image_id'] = image_id self.data['image_id'] = image_id
def test_004_can_bundle_kernel(self): def test_004_can_bundle_kernel(self):
@ -76,7 +76,7 @@ class ImageTests(base.UserSmokeTestCase):
def test_006_can_register_kernel(self): def test_006_can_register_kernel(self):
kernel_id = self.conn.register_image('%s/%s.manifest.xml' % kernel_id = self.conn.register_image('%s/%s.manifest.xml' %
(TEST_BUCKET, FLAGS.bundle_kernel)) (TEST_BUCKET, FLAGS.bundle_kernel))
self.assert_(kernel_id is not None) self.assertTrue(kernel_id is not None)
self.data['kernel_id'] = kernel_id self.data['kernel_id'] = kernel_id
def test_007_images_are_available_within_10_seconds(self): def test_007_images_are_available_within_10_seconds(self):
@ -86,8 +86,8 @@ class ImageTests(base.UserSmokeTestCase):
break break
time.sleep(1) time.sleep(1)
else: else:
self.assert_(False) # wasn't available within 10 seconds self.assertTrue(False) # wasn't available within 10 seconds
self.assert_(image.type == 'machine') self.assertTrue(image.type == 'machine')
for i in xrange(10): for i in xrange(10):
kernel = self.conn.get_image(self.data['kernel_id']) kernel = self.conn.get_image(self.data['kernel_id'])
@ -95,13 +95,13 @@ class ImageTests(base.UserSmokeTestCase):
break break
time.sleep(1) time.sleep(1)
else: else:
self.assert_(False) # wasn't available within 10 seconds self.assertTrue(False) # wasn't available within 10 seconds
self.assert_(kernel.type == 'kernel') self.assertTrue(kernel.type == 'kernel')
def test_008_can_describe_image_attribute(self): def test_008_can_describe_image_attribute(self):
attrs = self.conn.get_image_attribute(self.data['image_id'], attrs = self.conn.get_image_attribute(self.data['image_id'],
'launchPermission') 'launchPermission')
self.assert_(attrs.name, 'launch_permission') self.assertTrue(attrs.name, 'launch_permission')
def test_009_can_add_image_launch_permission(self): def test_009_can_add_image_launch_permission(self):
image = self.conn.get_image(self.data['image_id']) image = self.conn.get_image(self.data['image_id'])