From 49158176040706953088be70fe1ae9b5c868344f Mon Sep 17 00:00:00 2001 From: Ruby Loo Date: Thu, 9 Jun 2016 10:35:53 -0400 Subject: [PATCH] Replace dict.get(key) with dict[key] in unit tests This replaces dict.get(key) with dict[key] since these are tests and we should strive to be as clear/exact as we can. In particular, we shouldn't be doing self.assertIsNone(dict.get(key)) since it will pass if 1. the value is None or 2. if the key isn't in the dict. Change-Id: I7b399a5f0a53f50a5ebb7febfe4f5c763bed7597 Partial-Bug: #1590808 --- .../unit/drivers/modules/test_deploy_utils.py | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/ironic/tests/unit/drivers/modules/test_deploy_utils.py b/ironic/tests/unit/drivers/modules/test_deploy_utils.py index c654f1392c..4080cff77e 100644 --- a/ironic/tests/unit/drivers/modules/test_deploy_utils.py +++ b/ironic/tests/unit/drivers/modules/test_deploy_utils.py @@ -1720,12 +1720,12 @@ class AgentMethodsTestCase(db_base.DbTestCase): with task_manager.acquire( self.context, self.node.uuid, shared=False) as task: utils.agent_add_clean_params(task) - self.assertEqual(2, task.node.driver_internal_info.get( - 'agent_erase_devices_iterations')) - self.assertEqual(False, task.node.driver_internal_info.get( - 'agent_erase_devices_zeroize')) - self.assertEqual(True, task.node.driver_internal_info.get( - 'agent_continue_if_ata_erase_failed')) + self.assertEqual(2, task.node.driver_internal_info[ + 'agent_erase_devices_iterations']) + self.assertEqual(False, task.node.driver_internal_info[ + 'agent_erase_devices_zeroize']) + self.assertEqual(True, task.node.driver_internal_info[ + 'agent_continue_if_ata_erase_failed']) @mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.delete_cleaning_ports', autospec=True) @@ -1789,10 +1789,10 @@ class AgentMethodsTestCase(db_base.DbTestCase): utils.prepare_inband_cleaning(task, manage_boot=manage_boot)) prepare_cleaning_ports_mock.assert_called_once_with(task) power_mock.assert_called_once_with(task, states.REBOOT) - self.assertEqual(1, task.node.driver_internal_info.get( - 'agent_erase_devices_iterations')) - self.assertEqual(True, task.node.driver_internal_info.get( - 'agent_erase_devices_zeroize')) + self.assertEqual(1, task.node.driver_internal_info[ + 'agent_erase_devices_iterations']) + self.assertEqual(True, task.node.driver_internal_info[ + 'agent_erase_devices_zeroize']) if manage_boot: prepare_ramdisk_mock.assert_called_once_with( mock.ANY, mock.ANY, {'a': 'b', 'c': 'd'}) @@ -2022,7 +2022,7 @@ class ValidateParametersTestCase(db_base.DbTestCase): ) info = utils.get_image_instance_info(node) - self.assertIsNotNone(info.get('image_source')) + self.assertIsNotNone(info['image_source']) return info def test__get_img_instance_info_good(self): @@ -2036,8 +2036,8 @@ class ValidateParametersTestCase(db_base.DbTestCase): info = self._test__get_img_instance_info(instance_info=instance_info) - self.assertIsNotNone(info.get('ramdisk')) - self.assertIsNotNone(info.get('kernel')) + self.assertIsNotNone(info['ramdisk']) + self.assertIsNotNone(info['kernel']) def test__get_img_instance_info_non_glance_image_missing_kernel(self): instance_info = INST_INFO_DICT.copy() @@ -2086,10 +2086,10 @@ class InstanceInfoTestCase(db_base.DbTestCase): driver_internal_info=DRV_INTERNAL_INFO_DICT ) info = utils.parse_instance_info(node) - self.assertIsNotNone(info.get('image_source')) - self.assertIsNotNone(info.get('root_gb')) - self.assertEqual(0, info.get('ephemeral_gb')) - self.assertIsNone(info.get('configdrive')) + self.assertIsNotNone(info['image_source']) + self.assertIsNotNone(info['root_gb']) + self.assertEqual(0, info['ephemeral_gb']) + self.assertIsNone(info['configdrive']) def test_parse_instance_info_missing_instance_source(self): # make sure error is raised when info is missing @@ -2138,8 +2138,8 @@ class InstanceInfoTestCase(db_base.DbTestCase): driver_internal_info=DRV_INTERNAL_INFO_DICT, ) data = utils.parse_instance_info(node) - self.assertEqual(ephemeral_gb, data.get('ephemeral_gb')) - self.assertEqual(ephemeral_fmt, data.get('ephemeral_format')) + self.assertEqual(ephemeral_gb, data['ephemeral_gb']) + self.assertEqual(ephemeral_fmt, data['ephemeral_format']) def test_parse_instance_info_unicode_swap_mb(self): swap_mb = u'10' @@ -2151,7 +2151,7 @@ class InstanceInfoTestCase(db_base.DbTestCase): driver_internal_info=DRV_INTERNAL_INFO_DICT, ) data = utils.parse_instance_info(node) - self.assertEqual(swap_mb_int, data.get('swap_mb')) + self.assertEqual(swap_mb_int, data['swap_mb']) def test_parse_instance_info_invalid_ephemeral_gb(self): info = dict(INST_INFO_DICT) @@ -2192,7 +2192,7 @@ class InstanceInfoTestCase(db_base.DbTestCase): driver_internal_info=DRV_INTERNAL_INFO_DICT, ) data = utils.parse_instance_info(node) - self.assertTrue(data.get('preserve_ephemeral')) + self.assertTrue(data['preserve_ephemeral']) def test_parse_instance_info_valid_preserve_ephemeral_false(self): info = dict(INST_INFO_DICT) @@ -2205,7 +2205,7 @@ class InstanceInfoTestCase(db_base.DbTestCase): driver_internal_info=DRV_INTERNAL_INFO_DICT, ) data = utils.parse_instance_info(node) - self.assertFalse(data.get('preserve_ephemeral')) + self.assertFalse(data['preserve_ephemeral']) def test_parse_instance_info_invalid_preserve_ephemeral(self): info = dict(INST_INFO_DICT) @@ -2311,11 +2311,11 @@ class InstanceInfoTestCase(db_base.DbTestCase): driver_internal_info=driver_internal_info, ) instance_info = utils.parse_instance_info(node) - self.assertIsNotNone(instance_info.get('image_source')) - self.assertIsNotNone(instance_info.get('root_gb')) - self.assertEqual(0, instance_info.get('swap_mb')) - self.assertEqual(0, instance_info.get('ephemeral_gb')) - self.assertIsNone(instance_info.get('configdrive')) + self.assertIsNotNone(instance_info['image_source']) + self.assertIsNotNone(instance_info['root_gb']) + self.assertEqual(0, instance_info['swap_mb']) + self.assertEqual(0, instance_info['ephemeral_gb']) + self.assertIsNone(instance_info['configdrive']) def test_parse_instance_info_whole_disk_image_missing_root(self): info = dict(INST_INFO_DICT)