Replace assertRaisesRegexp with assertRaisesRegex

assertRaisesRegexp is deprecated in python3

https://docs.python.org/3.2/library/unittest.html

Change-Id: I91c84cb8a49dc6ce7a522e4c2114507ce4b81925
This commit is contained in:
Moshe Levi 2016-06-21 10:37:21 +03:00
parent b83040bd30
commit 5a5e5772ad
12 changed files with 112 additions and 112 deletions

View File

@ -2518,57 +2518,57 @@ class TestPut(test_api_base.BaseApiTest):
class TestCheckCleanSteps(base.TestCase): class TestCheckCleanSteps(base.TestCase):
def test__check_clean_steps_not_list(self): def test__check_clean_steps_not_list(self):
clean_steps = {"step": "upgrade_firmware", "interface": "deploy"} clean_steps = {"step": "upgrade_firmware", "interface": "deploy"}
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
"not of type 'array'", "not of type 'array'",
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_not_dict(self): def test__check_clean_steps_step_not_dict(self):
clean_steps = ['clean step'] clean_steps = ['clean step']
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
"not of type 'object'", "not of type 'object'",
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_key_invalid(self): def test__check_clean_steps_step_key_invalid(self):
clean_steps = [{"step": "upgrade_firmware", "interface": "deploy", clean_steps = [{"step": "upgrade_firmware", "interface": "deploy",
"unknown": "upgrade_firmware"}] "unknown": "upgrade_firmware"}]
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'unexpected', 'unexpected',
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_missing_interface(self): def test__check_clean_steps_step_missing_interface(self):
clean_steps = [{"step": "upgrade_firmware"}] clean_steps = [{"step": "upgrade_firmware"}]
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'interface', 'interface',
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_missing_step_key(self): def test__check_clean_steps_step_missing_step_key(self):
clean_steps = [{"interface": "deploy"}] clean_steps = [{"interface": "deploy"}]
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'step', 'step',
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_missing_step_value(self): def test__check_clean_steps_step_missing_step_value(self):
clean_steps = [{"step": None, "interface": "deploy"}] clean_steps = [{"step": None, "interface": "deploy"}]
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
"not of type 'string'", "not of type 'string'",
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_min_length_step_value(self): def test__check_clean_steps_step_min_length_step_value(self):
clean_steps = [{"step": "", "interface": "deploy"}] clean_steps = [{"step": "", "interface": "deploy"}]
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'is too short', 'is too short',
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_interface_value_invalid(self): def test__check_clean_steps_step_interface_value_invalid(self):
clean_steps = [{"step": "upgrade_firmware", "interface": "not"}] clean_steps = [{"step": "upgrade_firmware", "interface": "not"}]
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'is not one of', 'is not one of',
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_args_value_invalid(self): def test__check_clean_steps_step_args_value_invalid(self):
clean_steps = [{"step": "upgrade_firmware", "interface": "deploy", clean_steps = [{"step": "upgrade_firmware", "interface": "deploy",
"args": "invalid args"}] "args": "invalid args"}]
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'args', 'args',
api_node._check_clean_steps, clean_steps) api_node._check_clean_steps, clean_steps)

View File

@ -51,11 +51,11 @@ class FSMTest(base.TestCase):
self.fsm._validate_target_state('working') self.fsm._validate_target_state('working')
# target doesn't exist # target doesn't exist
self.assertRaisesRegexp(excp.InvalidState, "does not exist", self.assertRaisesRegex(excp.InvalidState, "does not exist",
self.fsm._validate_target_state, 'new state') self.fsm._validate_target_state, 'new state')
# target isn't a stable state # target isn't a stable state
self.assertRaisesRegexp(excp.InvalidState, "stable", self.assertRaisesRegex(excp.InvalidState, "stable",
self.fsm._validate_target_state, 'daydream') self.fsm._validate_target_state, 'daydream')
def test_initialize(self): def test_initialize(self):

View File

@ -718,16 +718,16 @@ class GetUpdatedCapabilitiesTestCase(base.TestCase):
self.assertEqual(65535, port) self.assertEqual(65535, port)
def test_validate_network_port_fail(self): def test_validate_network_port_fail(self):
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'Port "65536" is out of range.', 'Port "65536" is out of range.',
utils.validate_network_port, utils.validate_network_port,
'65536') '65536')
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'fake_port "-1" is out of range.', 'fake_port "-1" is out of range.',
utils.validate_network_port, utils.validate_network_port,
'-1', '-1',
'fake_port') 'fake_port')
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'Port "invalid" is not a valid integer.', 'Port "invalid" is not a valid integer.',
utils.validate_network_port, utils.validate_network_port,
'invalid') 'invalid')

View File

@ -155,7 +155,7 @@ class StartStopTestCase(mgr_utils.ServiceSetUpMixin, tests_db_base.DbTestCase):
def test_prevent_double_start(self): def test_prevent_double_start(self):
self._start_service() self._start_service()
self.assertRaisesRegexp(RuntimeError, 'already running', self.assertRaisesRegex(RuntimeError, 'already running',
self.service.init_host) self.service.init_host)
@mock.patch.object(base_manager, 'LOG') @mock.patch.object(base_manager, 'LOG')

View File

@ -526,7 +526,7 @@ class NodeCleaningStepsTestCase(base.DbTestCase):
{'step': 'bad_step', 'interface': 'deploy'}] {'step': 'bad_step', 'interface': 'deploy'}]
with task_manager.acquire(self.context, node.uuid) as task: with task_manager.acquire(self.context, node.uuid) as task:
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
"does not support.*bad_step", "does not support.*bad_step",
conductor_utils._validate_user_clean_steps, conductor_utils._validate_user_clean_steps,
task, user_steps) task, user_steps)
@ -541,7 +541,7 @@ class NodeCleaningStepsTestCase(base.DbTestCase):
{'step': 'erase_disks', 'interface': 'deploy'}] {'step': 'erase_disks', 'interface': 'deploy'}]
with task_manager.acquire(self.context, node.uuid) as task: with task_manager.acquire(self.context, node.uuid) as task:
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
"update_firmware.*invalid.*arg1", "update_firmware.*invalid.*arg1",
conductor_utils._validate_user_clean_steps, conductor_utils._validate_user_clean_steps,
task, user_steps) task, user_steps)
@ -555,7 +555,7 @@ class NodeCleaningStepsTestCase(base.DbTestCase):
{'step': 'build_raid', 'interface': 'deploy'}] {'step': 'build_raid', 'interface': 'deploy'}]
with task_manager.acquire(self.context, node.uuid) as task: with task_manager.acquire(self.context, node.uuid) as task:
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
"build_raid.*missing.*arg1", "build_raid.*missing.*arg1",
conductor_utils._validate_user_clean_steps, conductor_utils._validate_user_clean_steps,
task, user_steps) task, user_steps)

View File

@ -99,7 +99,7 @@ class FirmwareProcessorTestCase(base.TestCase):
'component': 'bios' 'component': 'bios'
} }
# | WHEN | & | THEN | # | WHEN | & | THEN |
self.assertRaisesRegexp( self.assertRaisesRegex(
exception.MissingParameterValue, 'checksum', exception.MissingParameterValue, 'checksum',
ilo_fw_processor.get_and_validate_firmware_image_info, ilo_fw_processor.get_and_validate_firmware_image_info,
invalid_firmware_image_info) invalid_firmware_image_info)
@ -113,7 +113,7 @@ class FirmwareProcessorTestCase(base.TestCase):
'component': '' 'component': ''
} }
# | WHEN | & | THEN | # | WHEN | & | THEN |
self.assertRaisesRegexp( self.assertRaisesRegex(
exception.MissingParameterValue, 'component', exception.MissingParameterValue, 'component',
ilo_fw_processor.get_and_validate_firmware_image_info, ilo_fw_processor.get_and_validate_firmware_image_info,
invalid_firmware_image_info) invalid_firmware_image_info)

View File

@ -56,14 +56,14 @@ class OneViewCommonTestCase(db_base.DbTestCase):
"capabilities": ("enclosure_group_uri:fake_eg_uri," "capabilities": ("enclosure_group_uri:fake_eg_uri,"
"server_profile_template_uri:fake_spt_uri") "server_profile_template_uri:fake_spt_uri")
} }
with self.assertRaisesRegexp(exception.MissingParameterValue, with self.assertRaisesRegex(exception.MissingParameterValue,
"server_hardware_type_uri"): "server_hardware_type_uri"):
common.verify_node_info(self.node) common.verify_node_info(self.node)
def test_verify_node_info_missing_node_driver_info(self): def test_verify_node_info_missing_node_driver_info(self):
self.node.driver_info = {} self.node.driver_info = {}
with self.assertRaisesRegexp(exception.MissingParameterValue, with self.assertRaisesRegex(exception.MissingParameterValue,
"server_hardware_uri"): "server_hardware_uri"):
common.verify_node_info(self.node) common.verify_node_info(self.node)
@ -73,7 +73,7 @@ class OneViewCommonTestCase(db_base.DbTestCase):
"enclosure_group_uri:fake_eg_uri") "enclosure_group_uri:fake_eg_uri")
self.node.properties = properties self.node.properties = properties
with self.assertRaisesRegexp(exception.MissingParameterValue, with self.assertRaisesRegex(exception.MissingParameterValue,
"server_profile_template_uri"): "server_profile_template_uri"):
common.verify_node_info(self.node) common.verify_node_info(self.node)
@ -90,7 +90,7 @@ class OneViewCommonTestCase(db_base.DbTestCase):
self.node.properties = properties self.node.properties = properties
self.node.driver_info = driver_info self.node.driver_info = driver_info
with self.assertRaisesRegexp(exception.MissingParameterValue, with self.assertRaisesRegex(exception.MissingParameterValue,
"server_hardware_uri"): "server_hardware_uri"):
common.verify_node_info(self.node) common.verify_node_info(self.node)
@ -104,7 +104,7 @@ class OneViewCommonTestCase(db_base.DbTestCase):
self.node.properties = properties self.node.properties = properties
self.node.driver_info = driver_info self.node.driver_info = driver_info
with self.assertRaisesRegexp(exception.MissingParameterValue, with self.assertRaisesRegex(exception.MissingParameterValue,
"server_hardware_type_uri"): "server_hardware_type_uri"):
common.verify_node_info(self.node) common.verify_node_info(self.node)
@ -255,7 +255,7 @@ class OneViewCommonTestCase(db_base.DbTestCase):
) )
def test__verify_node_info_missing_values_empty_string(self): def test__verify_node_info_missing_values_empty_string(self):
with self.assertRaisesRegexp(exception.MissingParameterValue, with self.assertRaisesRegex(exception.MissingParameterValue,
"'properties:a', 'properties:b'"): "'properties:a', 'properties:b'"):
common._verify_node_info("properties", common._verify_node_info("properties",
{"a": '', "b": None, "c": "something"}, {"a": '', "b": None, "c": "something"},

View File

@ -120,7 +120,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
'A Server Profile is not associated with node %s.' 'A Server Profile is not associated with node %s.'
% self.node.uuid % self.node.uuid
) )
self.assertRaisesRegexp( self.assertRaisesRegex(
exception.OperationNotPermitted, exception.OperationNotPermitted,
expected_msg, expected_msg,
self.driver.management.set_boot_device, self.driver.management.set_boot_device,

View File

@ -425,7 +425,7 @@ class TestAgentDeploy(db_base.DbTestCase):
'image_https_proxy': 'git://spam.ni', 'image_https_proxy': 'git://spam.ni',
'image_http_proxy': 'http://spam.ni', 'image_http_proxy': 'http://spam.ni',
'image_no_proxy': '1' * 500}) 'image_no_proxy': '1' * 500})
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'image_https_proxy.*image_no_proxy', 'image_https_proxy.*image_no_proxy',
task.driver.deploy.validate, task) task.driver.deploy.validate, task)
pxe_boot_validate_mock.assert_called_once_with( pxe_boot_validate_mock.assert_called_once_with(

View File

@ -125,43 +125,43 @@ class CleanStepDecoratorTestCase(base.TestCase):
'arg2': {'description': 'desc2'}}) 'arg2': {'description': 'desc2'}})
def test__validate_argsinfo_not_dict(self): def test__validate_argsinfo_not_dict(self):
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'argsinfo.+dictionary', 'argsinfo.+dictionary',
driver_base._validate_argsinfo, 'not-a-dict') driver_base._validate_argsinfo, 'not-a-dict')
def test__validate_argsinfo_arg_not_dict(self): def test__validate_argsinfo_arg_not_dict(self):
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'Argument.+dictionary', 'Argument.+dictionary',
driver_base._validate_argsinfo, driver_base._validate_argsinfo,
{'arg1': 'not-a-dict'}) {'arg1': 'not-a-dict'})
def test__validate_argsinfo_arg_empty_dict(self): def test__validate_argsinfo_arg_empty_dict(self):
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'description', 'description',
driver_base._validate_argsinfo, driver_base._validate_argsinfo,
{'arg1': {}}) {'arg1': {}})
def test__validate_argsinfo_arg_missing_description(self): def test__validate_argsinfo_arg_missing_description(self):
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'description', 'description',
driver_base._validate_argsinfo, driver_base._validate_argsinfo,
{'arg1': {'required': True}}) {'arg1': {'required': True}})
def test__validate_argsinfo_arg_description_invalid(self): def test__validate_argsinfo_arg_description_invalid(self):
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'string', 'string',
driver_base._validate_argsinfo, driver_base._validate_argsinfo,
{'arg1': {'description': True}}) {'arg1': {'description': True}})
def test__validate_argsinfo_arg_required_invalid(self): def test__validate_argsinfo_arg_required_invalid(self):
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'Boolean', 'Boolean',
driver_base._validate_argsinfo, driver_base._validate_argsinfo,
{'arg1': {'description': 'desc1', {'arg1': {'description': 'desc1',
'required': 'maybe'}}) 'required': 'maybe'}})
def test__validate_argsinfo_arg_unknown_key(self): def test__validate_argsinfo_arg_unknown_key(self):
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
'invalid', 'invalid',
driver_base._validate_argsinfo, driver_base._validate_argsinfo,
{'arg1': {'description': 'desc1', {'arg1': {'description': 'desc1',
@ -188,7 +188,7 @@ class CleanStepDecoratorTestCase(base.TestCase):
def test_clean_step_bad_priority(self): def test_clean_step_bad_priority(self):
d = driver_base.clean_step(priority='hi') d = driver_base.clean_step(priority='hi')
self.assertRaisesRegexp(exception.InvalidParameterValue, 'priority', self.assertRaisesRegex(exception.InvalidParameterValue, 'priority',
d, self.method) d, self.method)
self.assertTrue(self.method._is_clean_step) self.assertTrue(self.method._is_clean_step)
self.assertFalse(hasattr(self.method, '_clean_step_priority')) self.assertFalse(hasattr(self.method, '_clean_step_priority'))
@ -197,7 +197,7 @@ class CleanStepDecoratorTestCase(base.TestCase):
def test_clean_step_bad_abortable(self): def test_clean_step_bad_abortable(self):
d = driver_base.clean_step(priority=0, abortable='blue') d = driver_base.clean_step(priority=0, abortable='blue')
self.assertRaisesRegexp(exception.InvalidParameterValue, 'abortable', self.assertRaisesRegex(exception.InvalidParameterValue, 'abortable',
d, self.method) d, self.method)
self.assertTrue(self.method._is_clean_step) self.assertTrue(self.method._is_clean_step)
self.assertEqual(0, self.method._clean_step_priority) self.assertEqual(0, self.method._clean_step_priority)

View File

@ -163,7 +163,7 @@ class TestNodeObject(base.DbTestCase):
node = objects.Node.get(self.context, uuid) node = objects.Node.get(self.context, uuid)
node.properties = {"local_gb": "5G", "memory_mb": "5", node.properties = {"local_gb": "5G", "memory_mb": "5",
'cpus': '-1', 'cpu_arch': 'x86_64'} 'cpus': '-1', 'cpu_arch': 'x86_64'}
self.assertRaisesRegexp(exception.InvalidParameterValue, self.assertRaisesRegex(exception.InvalidParameterValue,
".*local_gb=5G, cpus=-1$", node.save) ".*local_gb=5G, cpus=-1$", node.save)
mock_get_node.assert_called_once_with(uuid) mock_get_node.assert_called_once_with(uuid)

View File

@ -176,7 +176,7 @@ class _TestObject(object):
fields = {'foobar': fields.IntegerField()} fields = {'foobar': fields.IntegerField()}
obj = Foo(self.context) obj = Foo(self.context)
self.assertRaisesRegexp( self.assertRaisesRegex(
NotImplementedError, "Cannot load 'foobar' in the base class", NotImplementedError, "Cannot load 'foobar' in the base class",
getattr, obj, 'foobar') getattr, obj, 'foobar')