def test_power_cycle_usb_port_device_does_not_turn_off(self): # Return the same device all the time - i.e., it does not turn off. self.usb_device_collector_mock.get_devices_by_spec = mock.Mock( return_value=[USB_DEVICE]) action = actions.PowerCycleUsbPort([USB_DEVICE_SPEC], 0) self.assertRaises(actions.TimeoutError, lambda: action.execute(self.context_with_mocks))
def test_power_cycle_usb_port(self): device = usb_device.UsbDevice('v', 'p', 'prod', ['if'], 1, 2, 1) self.usb_device_collector_mock.get_devices_by_spec = mock.Mock( side_effect=[[device, device], [device], [device, device]]) action = actions.PowerCycleUsbPort([USB_DEVICE_SPEC], 0, lambda x: [x[0]]) action.execute(self.context_with_mocks) self.usb_port_manager_mock.set_port_power.assert_has_calls( [mock.call([(1, 2)], False), mock.call([(1, 2)], True)])
def test_power_cycle_usb_port_device_does_not_turn_on(self): self.usb_device_collector_mock.get_devices_by_spec = mock.Mock( side_effect=[[USB_DEVICE, USB_DEVICE], [], [USB_DEVICE]]) action = actions.PowerCycleUsbPort([USB_DEVICE_SPEC], 0) self.assertRaises(actions.TimeoutError, lambda: action.execute(self.context_with_mocks))