From 5a5e5772adb3dfc0903364b9af33c4fe33ec2b98 Mon Sep 17 00:00:00 2001 From: Moshe Levi Date: Tue, 21 Jun 2016 10:37:21 +0300 Subject: [PATCH] Replace assertRaisesRegexp with assertRaisesRegex assertRaisesRegexp is deprecated in python3 https://docs.python.org/3.2/library/unittest.html Change-Id: I91c84cb8a49dc6ce7a522e4c2114507ce4b81925 --- ironic/tests/unit/api/v1/test_nodes.py | 54 +++++++-------- ironic/tests/unit/common/test_fsm.py | 8 +-- ironic/tests/unit/common/test_utils.py | 26 ++++---- .../tests/unit/conductor/test_base_manager.py | 4 +- ironic/tests/unit/conductor/test_utils.py | 24 +++---- .../modules/ilo/test_firmware_processor.py | 4 +- .../drivers/modules/oneview/test_common.py | 24 +++---- .../modules/oneview/test_management.py | 2 +- .../tests/unit/drivers/modules/test_agent.py | 6 +- ironic/tests/unit/drivers/test_base.py | 66 +++++++++---------- ironic/tests/unit/objects/test_node.py | 4 +- ironic/tests/unit/objects/test_objects.py | 2 +- 12 files changed, 112 insertions(+), 112 deletions(-) diff --git a/ironic/tests/unit/api/v1/test_nodes.py b/ironic/tests/unit/api/v1/test_nodes.py index 07e6228753..9a100a8ce9 100644 --- a/ironic/tests/unit/api/v1/test_nodes.py +++ b/ironic/tests/unit/api/v1/test_nodes.py @@ -2518,59 +2518,59 @@ 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, - "not of type 'array'", - api_node._check_clean_steps, clean_steps) + 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, - "not of type 'object'", - api_node._check_clean_steps, clean_steps) + 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, - 'unexpected', - api_node._check_clean_steps, clean_steps) + 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, - 'interface', - api_node._check_clean_steps, clean_steps) + 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, - 'step', - api_node._check_clean_steps, clean_steps) + 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, - "not of type 'string'", - api_node._check_clean_steps, clean_steps) + 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, - 'is too short', - api_node._check_clean_steps, clean_steps) + 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, - 'is not one of', - api_node._check_clean_steps, clean_steps) + 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, - 'args', - api_node._check_clean_steps, clean_steps) + self.assertRaisesRegex(exception.InvalidParameterValue, + 'args', + api_node._check_clean_steps, clean_steps) def test__check_clean_steps_valid(self): clean_steps = [{"step": "upgrade_firmware", "interface": "deploy"}] diff --git a/ironic/tests/unit/common/test_fsm.py b/ironic/tests/unit/common/test_fsm.py index e1dc416f9e..9f0844c2ed 100644 --- a/ironic/tests/unit/common/test_fsm.py +++ b/ironic/tests/unit/common/test_fsm.py @@ -51,12 +51,12 @@ class FSMTest(base.TestCase): self.fsm._validate_target_state('working') # target doesn't exist - self.assertRaisesRegexp(excp.InvalidState, "does not exist", - self.fsm._validate_target_state, 'new state') + 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.fsm._validate_target_state, 'daydream') + self.assertRaisesRegex(excp.InvalidState, "stable", + self.fsm._validate_target_state, 'daydream') def test_initialize(self): # no start state diff --git a/ironic/tests/unit/common/test_utils.py b/ironic/tests/unit/common/test_utils.py index 9296632749..4b372a08e1 100644 --- a/ironic/tests/unit/common/test_utils.py +++ b/ironic/tests/unit/common/test_utils.py @@ -718,16 +718,16 @@ class GetUpdatedCapabilitiesTestCase(base.TestCase): self.assertEqual(65535, port) def test_validate_network_port_fail(self): - self.assertRaisesRegexp(exception.InvalidParameterValue, - 'Port "65536" is out of range.', - utils.validate_network_port, - '65536') - self.assertRaisesRegexp(exception.InvalidParameterValue, - 'fake_port "-1" is out of range.', - utils.validate_network_port, - '-1', - 'fake_port') - self.assertRaisesRegexp(exception.InvalidParameterValue, - 'Port "invalid" is not a valid integer.', - utils.validate_network_port, - 'invalid') + self.assertRaisesRegex(exception.InvalidParameterValue, + 'Port "65536" is out of range.', + utils.validate_network_port, + '65536') + self.assertRaisesRegex(exception.InvalidParameterValue, + 'fake_port "-1" is out of range.', + utils.validate_network_port, + '-1', + 'fake_port') + self.assertRaisesRegex(exception.InvalidParameterValue, + 'Port "invalid" is not a valid integer.', + utils.validate_network_port, + 'invalid') diff --git a/ironic/tests/unit/conductor/test_base_manager.py b/ironic/tests/unit/conductor/test_base_manager.py index 5ddf549cbb..4416f86f56 100644 --- a/ironic/tests/unit/conductor/test_base_manager.py +++ b/ironic/tests/unit/conductor/test_base_manager.py @@ -155,8 +155,8 @@ class StartStopTestCase(mgr_utils.ServiceSetUpMixin, tests_db_base.DbTestCase): def test_prevent_double_start(self): self._start_service() - self.assertRaisesRegexp(RuntimeError, 'already running', - self.service.init_host) + self.assertRaisesRegex(RuntimeError, 'already running', + self.service.init_host) @mock.patch.object(base_manager, 'LOG') def test_warning_on_low_workers_pool(self, log_mock): diff --git a/ironic/tests/unit/conductor/test_utils.py b/ironic/tests/unit/conductor/test_utils.py index 0ce9ac6723..f4bcf412da 100644 --- a/ironic/tests/unit/conductor/test_utils.py +++ b/ironic/tests/unit/conductor/test_utils.py @@ -526,10 +526,10 @@ class NodeCleaningStepsTestCase(base.DbTestCase): {'step': 'bad_step', 'interface': 'deploy'}] with task_manager.acquire(self.context, node.uuid) as task: - self.assertRaisesRegexp(exception.InvalidParameterValue, - "does not support.*bad_step", - conductor_utils._validate_user_clean_steps, - task, user_steps) + self.assertRaisesRegex(exception.InvalidParameterValue, + "does not support.*bad_step", + conductor_utils._validate_user_clean_steps, + task, user_steps) mock_steps.assert_called_once_with(task, enabled=False, sort=False) @mock.patch.object(conductor_utils, '_get_cleaning_steps') @@ -541,10 +541,10 @@ class NodeCleaningStepsTestCase(base.DbTestCase): {'step': 'erase_disks', 'interface': 'deploy'}] with task_manager.acquire(self.context, node.uuid) as task: - self.assertRaisesRegexp(exception.InvalidParameterValue, - "update_firmware.*invalid.*arg1", - conductor_utils._validate_user_clean_steps, - task, user_steps) + self.assertRaisesRegex(exception.InvalidParameterValue, + "update_firmware.*invalid.*arg1", + conductor_utils._validate_user_clean_steps, + task, user_steps) mock_steps.assert_called_once_with(task, enabled=False, sort=False) @mock.patch.object(conductor_utils, '_get_cleaning_steps') @@ -555,10 +555,10 @@ class NodeCleaningStepsTestCase(base.DbTestCase): {'step': 'build_raid', 'interface': 'deploy'}] with task_manager.acquire(self.context, node.uuid) as task: - self.assertRaisesRegexp(exception.InvalidParameterValue, - "build_raid.*missing.*arg1", - conductor_utils._validate_user_clean_steps, - task, user_steps) + self.assertRaisesRegex(exception.InvalidParameterValue, + "build_raid.*missing.*arg1", + conductor_utils._validate_user_clean_steps, + task, user_steps) mock_steps.assert_called_once_with(task, enabled=False, sort=False) diff --git a/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py b/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py index a041376310..498ccd7d9b 100644 --- a/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py +++ b/ironic/tests/unit/drivers/modules/ilo/test_firmware_processor.py @@ -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) diff --git a/ironic/tests/unit/drivers/modules/oneview/test_common.py b/ironic/tests/unit/drivers/modules/oneview/test_common.py index 71d18fecb1..81d1fa1112 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_common.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_common.py @@ -56,15 +56,15 @@ class OneViewCommonTestCase(db_base.DbTestCase): "capabilities": ("enclosure_group_uri:fake_eg_uri," "server_profile_template_uri:fake_spt_uri") } - with self.assertRaisesRegexp(exception.MissingParameterValue, - "server_hardware_type_uri"): + 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, - "server_hardware_uri"): + with self.assertRaisesRegex(exception.MissingParameterValue, + "server_hardware_uri"): common.verify_node_info(self.node) def test_verify_node_info_missing_spt(self): @@ -73,8 +73,8 @@ class OneViewCommonTestCase(db_base.DbTestCase): "enclosure_group_uri:fake_eg_uri") self.node.properties = properties - with self.assertRaisesRegexp(exception.MissingParameterValue, - "server_profile_template_uri"): + with self.assertRaisesRegex(exception.MissingParameterValue, + "server_profile_template_uri"): common.verify_node_info(self.node) def test_verify_node_info_missing_sh(self): @@ -90,8 +90,8 @@ class OneViewCommonTestCase(db_base.DbTestCase): self.node.properties = properties self.node.driver_info = driver_info - with self.assertRaisesRegexp(exception.MissingParameterValue, - "server_hardware_uri"): + with self.assertRaisesRegex(exception.MissingParameterValue, + "server_hardware_uri"): common.verify_node_info(self.node) def test_verify_node_info_missing_sht(self): @@ -104,8 +104,8 @@ class OneViewCommonTestCase(db_base.DbTestCase): self.node.properties = properties self.node.driver_info = driver_info - with self.assertRaisesRegexp(exception.MissingParameterValue, - "server_hardware_type_uri"): + with self.assertRaisesRegex(exception.MissingParameterValue, + "server_hardware_type_uri"): common.verify_node_info(self.node) def test_get_oneview_info(self): @@ -255,8 +255,8 @@ class OneViewCommonTestCase(db_base.DbTestCase): ) def test__verify_node_info_missing_values_empty_string(self): - with self.assertRaisesRegexp(exception.MissingParameterValue, - "'properties:a', 'properties:b'"): + with self.assertRaisesRegex(exception.MissingParameterValue, + "'properties:a', 'properties:b'"): common._verify_node_info("properties", {"a": '', "b": None, "c": "something"}, ["a", "b", "c"]) diff --git a/ironic/tests/unit/drivers/modules/oneview/test_management.py b/ironic/tests/unit/drivers/modules/oneview/test_management.py index 214893c97a..0199c6fdb8 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_management.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_management.py @@ -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, diff --git a/ironic/tests/unit/drivers/modules/test_agent.py b/ironic/tests/unit/drivers/modules/test_agent.py index 1f0f3cc12b..ea16bcdaa3 100644 --- a/ironic/tests/unit/drivers/modules/test_agent.py +++ b/ironic/tests/unit/drivers/modules/test_agent.py @@ -425,9 +425,9 @@ 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, - 'image_https_proxy.*image_no_proxy', - task.driver.deploy.validate, task) + self.assertRaisesRegex(exception.InvalidParameterValue, + 'image_https_proxy.*image_no_proxy', + task.driver.deploy.validate, task) pxe_boot_validate_mock.assert_called_once_with( task.driver.boot, task) show_mock.assert_called_once_with(self.context, 'fake-image') diff --git a/ironic/tests/unit/drivers/test_base.py b/ironic/tests/unit/drivers/test_base.py index 0343683733..3276023ca2 100644 --- a/ironic/tests/unit/drivers/test_base.py +++ b/ironic/tests/unit/drivers/test_base.py @@ -125,47 +125,47 @@ class CleanStepDecoratorTestCase(base.TestCase): 'arg2': {'description': 'desc2'}}) def test__validate_argsinfo_not_dict(self): - self.assertRaisesRegexp(exception.InvalidParameterValue, - 'argsinfo.+dictionary', - driver_base._validate_argsinfo, 'not-a-dict') + 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, - 'Argument.+dictionary', - driver_base._validate_argsinfo, - {'arg1': 'not-a-dict'}) + 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, - 'description', - driver_base._validate_argsinfo, - {'arg1': {}}) + self.assertRaisesRegex(exception.InvalidParameterValue, + 'description', + driver_base._validate_argsinfo, + {'arg1': {}}) def test__validate_argsinfo_arg_missing_description(self): - self.assertRaisesRegexp(exception.InvalidParameterValue, - 'description', - driver_base._validate_argsinfo, - {'arg1': {'required': True}}) + self.assertRaisesRegex(exception.InvalidParameterValue, + 'description', + driver_base._validate_argsinfo, + {'arg1': {'required': True}}) def test__validate_argsinfo_arg_description_invalid(self): - self.assertRaisesRegexp(exception.InvalidParameterValue, - 'string', - driver_base._validate_argsinfo, - {'arg1': {'description': True}}) + self.assertRaisesRegex(exception.InvalidParameterValue, + 'string', + driver_base._validate_argsinfo, + {'arg1': {'description': True}}) def test__validate_argsinfo_arg_required_invalid(self): - self.assertRaisesRegexp(exception.InvalidParameterValue, - 'Boolean', - driver_base._validate_argsinfo, - {'arg1': {'description': 'desc1', - 'required': 'maybe'}}) + 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, - 'invalid', - driver_base._validate_argsinfo, - {'arg1': {'description': 'desc1', - 'unknown': 'bad'}}) + self.assertRaisesRegex(exception.InvalidParameterValue, + 'invalid', + driver_base._validate_argsinfo, + {'arg1': {'description': 'desc1', + 'unknown': 'bad'}}) def test_clean_step_priority_only(self): d = driver_base.clean_step(priority=10) @@ -188,8 +188,8 @@ class CleanStepDecoratorTestCase(base.TestCase): def test_clean_step_bad_priority(self): d = driver_base.clean_step(priority='hi') - self.assertRaisesRegexp(exception.InvalidParameterValue, 'priority', - d, self.method) + self.assertRaisesRegex(exception.InvalidParameterValue, 'priority', + d, self.method) self.assertTrue(self.method._is_clean_step) self.assertFalse(hasattr(self.method, '_clean_step_priority')) self.assertFalse(hasattr(self.method, '_clean_step_abortable')) @@ -197,8 +197,8 @@ 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', - d, self.method) + self.assertRaisesRegex(exception.InvalidParameterValue, 'abortable', + d, self.method) self.assertTrue(self.method._is_clean_step) self.assertEqual(0, self.method._clean_step_priority) self.assertFalse(hasattr(self.method, '_clean_step_abortable')) diff --git a/ironic/tests/unit/objects/test_node.py b/ironic/tests/unit/objects/test_node.py index cca57db0d5..b7ef8073ab 100644 --- a/ironic/tests/unit/objects/test_node.py +++ b/ironic/tests/unit/objects/test_node.py @@ -163,8 +163,8 @@ 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, - ".*local_gb=5G, cpus=-1$", node.save) + self.assertRaisesRegex(exception.InvalidParameterValue, + ".*local_gb=5G, cpus=-1$", node.save) mock_get_node.assert_called_once_with(uuid) def test__validate_property_values_success(self): diff --git a/ironic/tests/unit/objects/test_objects.py b/ironic/tests/unit/objects/test_objects.py index 1a4528b61c..1564466c24 100644 --- a/ironic/tests/unit/objects/test_objects.py +++ b/ironic/tests/unit/objects/test_objects.py @@ -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')