def test_cleanup_on_stop(self, input_device, source_remove, io_add_watch, list_devices): list_devices.return_value = [self.dev] mock_device = mock.MagicMock() mock_device.fd = 'N/A' mock_device.fn = self.dev mock_device.phys = 'Mock' mock_device.name = 'Mock Device' input_device.return_value = mock_device a = agent.EvtDevAgent(self.core, self.path, [], self.vol_step_size, self.refresh_period) input_device.assert_called_with(self.dev) a.stop() mock_device.close.assert_called_with()
def test_fd_io_error(self, input_device, source_remove, io_add_watch, list_devices, timeout_add): list_devices.return_value = [self.dev] mock_device = mock.MagicMock() mock_device.fd = 'N/A' mock_device.fn = self.dev mock_device.phys = 'Mock' mock_device.name = 'Mock Device' input_device.return_value = mock_device a = agent.EvtDevAgent(self.core, self.path, [], self.vol_step_size, self.refresh_period) io_add_watch.assert_called() io_callback = io_add_watch.call_args_list[0][0][2] io_exception = IOError('Mocked IO Error') mock_device.read_one.side_effect = io_exception value = io_callback('NA', 'NA', mock_device) self.assertTrue(value) a.stop()
def setUp(self): self.dev_dir = '/dev/input' self.device_prefix = 'event' self.num_devs = 1 self.device_names = [self.device_prefix + str(i) for i in range(8888, 8888+self.num_devs)] self.vol_step_size = 10 self.refresh = 0.1 self.core = mock.Mock() config = {'list_devices.return_value': self.device_names} patcher = mock.patch('evdev.util', **config) self.mock_list_devices = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch('evdev.device.InputDevice', MockedInputDevice) self.mock_input_device = patcher.start() self.addCleanup(patcher.stop) self.devices = map(ProxyInputDevice, self.device_names) self.agent = agent.EvtDevAgent(self.core, self.dev_dir, self.device_names, self.vol_step_size, self.refresh)