How to use _is_instance_mock method in autotest

Best Python code snippet using autotest_python

test_management.py

Source:test_management.py Github

copy

Full Screen

...37 shared=True) as task:38 task.driver.management.validate(task)39 mock_parse_driver_info.assert_called_once_with(task.node)40 def test_get_supported_boot_devices(self):41 if not mock._is_instance_mock(ibmc_client):42 mock.patch.object(ibmc_client, 'connect', autospec=True).start()43 connect_ibmc = ibmc_client.connect44 conn = self.mock_ibmc_conn(connect_ibmc)45 # mock return value46 _supported_boot_devices = list(mappings.GET_BOOT_DEVICE_MAP)47 conn.system.get.return_value = mock.Mock(48 boot_source_override=mock.Mock(49 supported_boot_devices=_supported_boot_devices50 )51 )52 with task_manager.acquire(self.context, self.node.uuid,53 shared=True) as task:54 supported_boot_devices = (55 task.driver.management.get_supported_boot_devices(task))56 connect_ibmc.assert_called_with(**self.ibmc)57 expect = sorted(list(mappings.GET_BOOT_DEVICE_MAP.values()))58 self.assertEqual(expect, sorted(supported_boot_devices))59 def test_set_boot_device(self):60 if not mock._is_instance_mock(ibmc_client):61 mock.patch.object(ibmc_client, 'connect', autospec=True).start()62 connect_ibmc = ibmc_client.connect63 conn = self.mock_ibmc_conn(connect_ibmc)64 # mock return value65 conn.system.set_boot_source.return_value = None66 with task_manager.acquire(self.context, self.node.uuid,67 shared=False) as task:68 device_mapping = [69 (boot_devices.PXE, constants.BOOT_SOURCE_TARGET_PXE),70 (boot_devices.DISK, constants.BOOT_SOURCE_TARGET_HDD),71 (boot_devices.CDROM, constants.BOOT_SOURCE_TARGET_CD),72 (boot_devices.BIOS,73 constants.BOOT_SOURCE_TARGET_BIOS_SETUP),74 ('floppy', constants.BOOT_SOURCE_TARGET_FLOPPY),75 ]76 persistent_mapping = [77 (True, constants.BOOT_SOURCE_ENABLED_CONTINUOUS),78 (False, constants.BOOT_SOURCE_ENABLED_ONCE)79 ]80 data_source = list(itertools.product(device_mapping,81 persistent_mapping))82 for (device, persistent) in data_source:83 task.driver.management.set_boot_device(84 task, device[0], persistent=persistent[0])85 connect_ibmc.assert_called_with(**self.ibmc)86 conn.system.set_boot_source.assert_called_once_with(87 device[1],88 enabled=persistent[1])89 # Reset mocks90 connect_ibmc.reset_mock()91 conn.system.set_boot_source.reset_mock()92 def test_set_boot_device_fail(self):93 if not mock._is_instance_mock(ibmc_client):94 mock.patch.object(ibmc_client, 'connect', autospec=True).start()95 connect_ibmc = ibmc_client.connect96 conn = self.mock_ibmc_conn(connect_ibmc)97 # mock return value98 conn.system.set_boot_source.side_effect = (99 ibmc_error.IBMCClientError100 )101 with task_manager.acquire(self.context, self.node.uuid,102 shared=False) as task:103 self.assertRaisesRegex(104 exception.IBMCError, 'set iBMC boot device',105 task.driver.management.set_boot_device, task,106 boot_devices.PXE)107 connect_ibmc.assert_called_with(**self.ibmc)108 conn.system.set_boot_source.assert_called_once_with(109 constants.BOOT_SOURCE_TARGET_PXE,110 enabled=constants.BOOT_SOURCE_ENABLED_ONCE)111 def test_get_boot_device(self):112 if not mock._is_instance_mock(ibmc_client):113 mock.patch.object(ibmc_client, 'connect', autospec=True).start()114 connect_ibmc = ibmc_client.connect115 conn = self.mock_ibmc_conn(connect_ibmc)116 # mock return value117 conn.system.get.return_value = mock.Mock(118 boot_source_override=mock.Mock(119 target=constants.BOOT_SOURCE_TARGET_PXE,120 enabled=constants.BOOT_SOURCE_ENABLED_CONTINUOUS121 )122 )123 with task_manager.acquire(self.context, self.node.uuid,124 shared=True) as task:125 result_boot_device = task.driver.management.get_boot_device(task)126 conn.system.get.assert_called_once()127 connect_ibmc.assert_called_once_with(**self.ibmc)128 expected = {'boot_device': boot_devices.PXE,129 'persistent': True}130 self.assertEqual(expected, result_boot_device)131 def test_get_supported_boot_modes(self):132 with task_manager.acquire(self.context, self.node.uuid,133 shared=True) as task:134 supported_boot_modes = (135 task.driver.management.get_supported_boot_modes(task))136 self.assertEqual(list(mappings.SET_BOOT_MODE_MAP),137 supported_boot_modes)138 def test_set_boot_mode(self):139 if not mock._is_instance_mock(ibmc_client):140 mock.patch.object(ibmc_client, 'connect', autospec=True).start()141 connect_ibmc = ibmc_client.connect142 conn = self.mock_ibmc_conn(connect_ibmc)143 # mock system boot source override return value144 conn.system.get.return_value = mock.Mock(145 boot_source_override=mock.Mock(146 target=constants.BOOT_SOURCE_TARGET_PXE,147 enabled=constants.BOOT_SOURCE_ENABLED_CONTINUOUS148 )149 )150 conn.system.set_boot_source.return_value = None151 with task_manager.acquire(self.context, self.node.uuid,152 shared=False) as task:153 expected_values = [154 (boot_modes.LEGACY_BIOS, constants.BOOT_SOURCE_MODE_BIOS),155 (boot_modes.UEFI, constants.BOOT_SOURCE_MODE_UEFI)156 ]157 for ironic_boot_mode, ibmc_boot_mode in expected_values:158 task.driver.management.set_boot_mode(task,159 mode=ironic_boot_mode)160 conn.system.get.assert_called_once()161 connect_ibmc.assert_called_with(**self.ibmc)162 conn.system.set_boot_source.assert_called_once_with(163 constants.BOOT_SOURCE_TARGET_PXE,164 enabled=constants.BOOT_SOURCE_ENABLED_CONTINUOUS,165 mode=ibmc_boot_mode)166 # Reset167 connect_ibmc.reset_mock()168 conn.system.set_boot_source.reset_mock()169 conn.system.get.reset_mock()170 def test_set_boot_mode_fail(self):171 if not mock._is_instance_mock(ibmc_client):172 mock.patch.object(ibmc_client, 'connect', autospec=True).start()173 connect_ibmc = ibmc_client.connect174 conn = self.mock_ibmc_conn(connect_ibmc)175 # mock system boot source override return value176 conn.system.get.return_value = mock.Mock(177 boot_source_override=mock.Mock(178 target=constants.BOOT_SOURCE_TARGET_PXE,179 enabled=constants.BOOT_SOURCE_ENABLED_CONTINUOUS180 )181 )182 conn.system.set_boot_source.side_effect = (183 ibmc_error.IBMCClientError184 )185 with task_manager.acquire(self.context, self.node.uuid,186 shared=False) as task:187 expected_values = [188 (boot_modes.LEGACY_BIOS, constants.BOOT_SOURCE_MODE_BIOS),189 (boot_modes.UEFI, constants.BOOT_SOURCE_MODE_UEFI)190 ]191 for ironic_boot_mode, ibmc_boot_mode in expected_values:192 self.assertRaisesRegex(193 exception.IBMCError, 'set iBMC boot mode',194 task.driver.management.set_boot_mode, task,195 ironic_boot_mode)196 conn.system.set_boot_source.assert_called_once_with(197 constants.BOOT_SOURCE_TARGET_PXE,198 enabled=constants.BOOT_SOURCE_ENABLED_CONTINUOUS,199 mode=ibmc_boot_mode)200 conn.system.get.assert_called_once()201 connect_ibmc.assert_called_with(**self.ibmc)202 # Reset203 connect_ibmc.reset_mock()204 conn.system.set_boot_source.reset_mock()205 conn.system.get.reset_mock()206 def test_get_boot_mode(self):207 if not mock._is_instance_mock(ibmc_client):208 mock.patch.object(ibmc_client, 'connect', autospec=True).start()209 connect_ibmc = ibmc_client.connect210 conn = self.mock_ibmc_conn(connect_ibmc)211 # mock system boot source override return value212 conn.system.get.return_value = mock.Mock(213 boot_source_override=mock.Mock(214 target=constants.BOOT_SOURCE_TARGET_PXE,215 enabled=constants.BOOT_SOURCE_ENABLED_CONTINUOUS,216 mode=constants.BOOT_SOURCE_MODE_BIOS,217 )218 )219 with task_manager.acquire(self.context, self.node.uuid,220 shared=True) as task:221 response = task.driver.management.get_boot_mode(task)222 conn.system.get.assert_called_once()223 connect_ibmc.assert_called_with(**self.ibmc)224 expected = boot_modes.LEGACY_BIOS225 self.assertEqual(expected, response)226 def test_get_sensors_data(self):227 with task_manager.acquire(self.context, self.node.uuid,228 shared=True) as task:229 self.assertRaises(NotImplementedError,230 task.driver.management.get_sensors_data, task)231 def test_inject_nmi(self):232 if not mock._is_instance_mock(ibmc_client):233 mock.patch.object(ibmc_client, 'connect', autospec=True).start()234 connect_ibmc = ibmc_client.connect235 conn = self.mock_ibmc_conn(connect_ibmc)236 # mock system boot source override return value237 conn.system.reset.return_value = None238 with task_manager.acquire(self.context, self.node.uuid,239 shared=False) as task:240 task.driver.management.inject_nmi(task)241 connect_ibmc.assert_called_with(**self.ibmc)242 conn.system.reset.assert_called_once_with(constants.RESET_NMI)243 def test_inject_nmi_fail(self):244 if not mock._is_instance_mock(ibmc_client):245 mock.patch.object(ibmc_client, 'connect', autospec=True).start()246 connect_ibmc = ibmc_client.connect247 conn = self.mock_ibmc_conn(connect_ibmc)248 # mock system boot source override return value249 conn.system.reset.side_effect = (250 ibmc_error.IBMCClientError251 )252 with task_manager.acquire(self.context, self.node.uuid,253 shared=False) as task:254 self.assertRaisesRegex(255 exception.IBMCError, 'inject iBMC NMI',256 task.driver.management.inject_nmi, task)257 connect_ibmc.assert_called_with(**self.ibmc)258 conn.system.reset.assert_called_once_with(constants.RESET_NMI)

Full Screen

Full Screen

_fluent.py

Source:_fluent.py Github

copy

Full Screen

...31 return retval32 class When(object):33 def __init__(self, mock_fn):34 self._mock_fn = mock_fn35 if not _is_instance_mock(self._mock_fn):36 raise RuntimeError("mock_fn must be an instance of Mock")37 if not isinstance(self._mock_fn.side_effect, _Stub):38 if self._mock_fn.side_effect is not None:39 raise RuntimeError("Mock '%s' already has a side_effect set defined" % self._mock_fn)40 self._mock_fn.side_effect = _Stub()41 if not isinstance(self._mock_fn.side_effect._results, list): #pylint: disable=protected-access42 self._mock_fn.side_effect._results = list(self._mock_fn.side_effect._results) #pylint: disable=protected-access43 def called_with(self, *args, **kwargs):44 return CalledWith(self._mock_fn.side_effect._results, call(*args, **kwargs)) #pylint: disable=protected-access45 class CalledWith(object):46 def __init__(self, results, key):47 self._results = results48 self._key = key49 self._list = None...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful