def test_start(self): data_items = [[1] * 10, [1] * 20, [1] * 5, []] def input_file_read_side_effect(arg): self.assertEqual(arg, rw_handles.READ_CHUNKSIZE) data = data_items[input_file_read_side_effect.i] input_file_read_side_effect.i += 1 return data input_file_read_side_effect.i = 0 input_file = mock.Mock() input_file.read.side_effect = input_file_read_side_effect output_file = mock.Mock() rw_task = image_transfer.FileReadWriteTask(input_file, output_file) rw_task.start() self.assertTrue(rw_task.wait()) self.assertEqual(len(data_items), input_file.read.call_count) exp_calls = [] for i in range(0, len(data_items)): exp_calls.append(mock.call(data_items[i])) self.assertEqual(exp_calls, output_file.write.call_args_list) self.assertEqual(len(data_items), input_file.update_progress.call_count) self.assertEqual(len(data_items), output_file.update_progress.call_count)
def test_start_with_read_exception(self): input_file = mock.Mock() input_file.read.side_effect = RuntimeError() output_file = mock.Mock() rw_task = image_transfer.FileReadWriteTask(input_file, output_file) rw_task.start() self.assertRaises(exceptions.ImageTransferException, rw_task.wait) input_file.read.assert_called_once_with(rw_handles.READ_CHUNKSIZE)