def test_serialize_mpi_bcast_task_to_from_file(): task = Task(mpi_bcast, 'x') filename = 'mpi_bcast_task.task' serialize(task, file=filename) assert os.path.exists(filename) deserialized_task = deserialize(file=filename) assert deserialized_task.compute() == task.compute() os.remove(filename)
def test_serialize_local_task(): def local_test_func(x, y=3): return x, y task = Task(local_test_func, 4) serialized_task = serialize(task) deserialized_task = deserialize(serialized_task) assert deserialized_task.compute() == task.compute()
def wrapped_func(*args, **kwargs): task_file = '{}.task'.format(func.__name__) result_file = '{}.result'.format(func.__name__) task = Task(func, *args, **kwargs) serialize(task, file=task_file) launch_mpirun_task_file(task_file, result_file, **self.kwargs) results = deserialize(file=result_file) self._remove_file(task_file) self._remove_file(result_file) exception = self._get_first_exception(results) if exception: exception.reraise() else: return self._collect_results(results)
def test_mpirun_task_file_parallel(): task_file = 'parallel_main_test_func.task' result_file = 'parallel_main_test_func.result' task = Task(main_test_func, 1) serialize(task, file=task_file) assert os.path.exists(task_file) launch_mpirun_task_file(task_file, result_file, np=2) assert os.path.exists(result_file) results = deserialize(file=result_file) assert results == [(1, 2), (1, 2)] if os.path.exists(task_file): os.remove(task_file) if os.path.exists(result_file): os.remove(result_file)
def test_serialize_lambda_task(): task = Task(lambda x: x, 1) serialized_task = serialize(task) deserialized_task = deserialize(serialized_task) assert deserialized_task.compute() == task.compute()
def test_serialize_mpi_bcast_task(): task = Task(mpi_bcast, 'x') serialized_task = serialize(task) deserialized_task = deserialize(serialized_task) assert deserialized_task.compute() == task.compute()
def test_serialize_main_task(): task = Task(main_test_func, 1, 'a', x='y') serialized_task = serialize(task) deserialized_task = deserialize(serialized_task) assert deserialized_task.compute() == task.compute()
def test_task_func_not_callable_raises_exception(): with pytest.raises(ValueError): Task(1, 'x')
def test_lambda_task(): task = Task(lambda x: x, 1) assert task.compute() == 1
def test_mpi_bcast_task(): task = Task(mpi_bcast, 'x') assert task.compute() == mpi_bcast('x')
def test_local_func_task(): def local_test_func(x, y=3): return x, y task = Task(local_test_func, 4) assert task.compute() == local_test_func(4)
def test_main_func_task(): task = Task(main_test_func, 1, 'a', x='y') assert task.compute() == main_test_func(1, 'a', x='y')