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):
def test__check_clean_steps_not_list(self):
clean_steps = {"step": "upgrade_firmware", "interface": "deploy"}
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
"not of type 'array'",
api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_not_dict(self):
clean_steps = ['clean step']
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
"not of type 'object'",
api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_key_invalid(self):
clean_steps = [{"step": "upgrade_firmware", "interface": "deploy",
"unknown": "upgrade_firmware"}]
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'unexpected',
api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_missing_interface(self):
clean_steps = [{"step": "upgrade_firmware"}]
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'interface',
api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_missing_step_key(self):
clean_steps = [{"interface": "deploy"}]
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'step',
api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_missing_step_value(self):
clean_steps = [{"step": None, "interface": "deploy"}]
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
"not of type 'string'",
api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_min_length_step_value(self):
clean_steps = [{"step": "", "interface": "deploy"}]
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'is too short',
api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_interface_value_invalid(self):
clean_steps = [{"step": "upgrade_firmware", "interface": "not"}]
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'is not one of',
api_node._check_clean_steps, clean_steps)
def test__check_clean_steps_step_args_value_invalid(self):
clean_steps = [{"step": "upgrade_firmware", "interface": "deploy",
"args": "invalid args"}]
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'args',
api_node._check_clean_steps, clean_steps)

View File

@ -51,11 +51,11 @@ class FSMTest(base.TestCase):
self.fsm._validate_target_state('working')
# 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')
# target isn't a stable state
self.assertRaisesRegexp(excp.InvalidState, "stable",
self.assertRaisesRegex(excp.InvalidState, "stable",
self.fsm._validate_target_state, 'daydream')
def test_initialize(self):

View File

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

View File

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

View File

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

View File

@ -99,7 +99,7 @@ class FirmwareProcessorTestCase(base.TestCase):
'component': 'bios'
}
# | WHEN | & | THEN |
self.assertRaisesRegexp(
self.assertRaisesRegex(
exception.MissingParameterValue, 'checksum',
ilo_fw_processor.get_and_validate_firmware_image_info,
invalid_firmware_image_info)
@ -113,7 +113,7 @@ class FirmwareProcessorTestCase(base.TestCase):
'component': ''
}
# | WHEN | & | THEN |
self.assertRaisesRegexp(
self.assertRaisesRegex(
exception.MissingParameterValue, 'component',
ilo_fw_processor.get_and_validate_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,"
"server_profile_template_uri:fake_spt_uri")
}
with self.assertRaisesRegexp(exception.MissingParameterValue,
with self.assertRaisesRegex(exception.MissingParameterValue,
"server_hardware_type_uri"):
common.verify_node_info(self.node)
def test_verify_node_info_missing_node_driver_info(self):
self.node.driver_info = {}
with self.assertRaisesRegexp(exception.MissingParameterValue,
with self.assertRaisesRegex(exception.MissingParameterValue,
"server_hardware_uri"):
common.verify_node_info(self.node)
@ -73,7 +73,7 @@ class OneViewCommonTestCase(db_base.DbTestCase):
"enclosure_group_uri:fake_eg_uri")
self.node.properties = properties
with self.assertRaisesRegexp(exception.MissingParameterValue,
with self.assertRaisesRegex(exception.MissingParameterValue,
"server_profile_template_uri"):
common.verify_node_info(self.node)
@ -90,7 +90,7 @@ class OneViewCommonTestCase(db_base.DbTestCase):
self.node.properties = properties
self.node.driver_info = driver_info
with self.assertRaisesRegexp(exception.MissingParameterValue,
with self.assertRaisesRegex(exception.MissingParameterValue,
"server_hardware_uri"):
common.verify_node_info(self.node)
@ -104,7 +104,7 @@ class OneViewCommonTestCase(db_base.DbTestCase):
self.node.properties = properties
self.node.driver_info = driver_info
with self.assertRaisesRegexp(exception.MissingParameterValue,
with self.assertRaisesRegex(exception.MissingParameterValue,
"server_hardware_type_uri"):
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):
with self.assertRaisesRegexp(exception.MissingParameterValue,
with self.assertRaisesRegex(exception.MissingParameterValue,
"'properties:a', 'properties:b'"):
common._verify_node_info("properties",
{"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.'
% self.node.uuid
)
self.assertRaisesRegexp(
self.assertRaisesRegex(
exception.OperationNotPermitted,
expected_msg,
self.driver.management.set_boot_device,

View File

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

View File

@ -125,43 +125,43 @@ class CleanStepDecoratorTestCase(base.TestCase):
'arg2': {'description': 'desc2'}})
def test__validate_argsinfo_not_dict(self):
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'argsinfo.+dictionary',
driver_base._validate_argsinfo, 'not-a-dict')
def test__validate_argsinfo_arg_not_dict(self):
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'Argument.+dictionary',
driver_base._validate_argsinfo,
{'arg1': 'not-a-dict'})
def test__validate_argsinfo_arg_empty_dict(self):
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'description',
driver_base._validate_argsinfo,
{'arg1': {}})
def test__validate_argsinfo_arg_missing_description(self):
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'description',
driver_base._validate_argsinfo,
{'arg1': {'required': True}})
def test__validate_argsinfo_arg_description_invalid(self):
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'string',
driver_base._validate_argsinfo,
{'arg1': {'description': True}})
def test__validate_argsinfo_arg_required_invalid(self):
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'Boolean',
driver_base._validate_argsinfo,
{'arg1': {'description': 'desc1',
'required': 'maybe'}})
def test__validate_argsinfo_arg_unknown_key(self):
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
'invalid',
driver_base._validate_argsinfo,
{'arg1': {'description': 'desc1',
@ -188,7 +188,7 @@ class CleanStepDecoratorTestCase(base.TestCase):
def test_clean_step_bad_priority(self):
d = driver_base.clean_step(priority='hi')
self.assertRaisesRegexp(exception.InvalidParameterValue, 'priority',
self.assertRaisesRegex(exception.InvalidParameterValue, 'priority',
d, self.method)
self.assertTrue(self.method._is_clean_step)
self.assertFalse(hasattr(self.method, '_clean_step_priority'))
@ -197,7 +197,7 @@ class CleanStepDecoratorTestCase(base.TestCase):
def test_clean_step_bad_abortable(self):
d = driver_base.clean_step(priority=0, abortable='blue')
self.assertRaisesRegexp(exception.InvalidParameterValue, 'abortable',
self.assertRaisesRegex(exception.InvalidParameterValue, 'abortable',
d, self.method)
self.assertTrue(self.method._is_clean_step)
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.properties = {"local_gb": "5G", "memory_mb": "5",
'cpus': '-1', 'cpu_arch': 'x86_64'}
self.assertRaisesRegexp(exception.InvalidParameterValue,
self.assertRaisesRegex(exception.InvalidParameterValue,
".*local_gb=5G, cpus=-1$", node.save)
mock_get_node.assert_called_once_with(uuid)

View File

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