def test_adapter_results_with_posttask(tmpdir): temp_path = tmpdir.mkdir("test") post_task = SimpleSubtask("Ending") builder = TaskBuilder(SimpleTaskBuilder(), temp_path) builder.set_posttask(subtask=post_task) builder.add_subtask(subtask=SimpleSubtask("First")) builder.add_subtask(subtask=SimpleSubtask("Second")) new_task = builder.build_task() with worker.ToolJobManager() as manager: for subtask in new_task.subtasks: adapted_tool = speedwagon.worker.SubtaskJobAdapter(subtask) manager.add_job(adapted_tool, adapted_tool.settings) manager.start() results = list() for r in manager.get_results(): results.append(r.data) assert len(results) == 3 assert "First" == results[0] assert "Second" == results[1] assert "Ending" == results[2] shutil.rmtree(tmpdir) shortcut = os.path.join(tmpdir.dirname, "test_adapter_results_with_postcurrent") os.unlink(shortcut)
def test_posttask_builder(tmpdir): temp_path = tmpdir.mkdir("test") posttask = SimpleSubtask("ending") builder = TaskBuilder(SimpleTaskBuilder(), temp_path) builder.add_subtask(subtask=SimpleSubtask("First")) builder.add_subtask(subtask=SimpleSubtask("Second")) builder.set_posttask(posttask) task = builder.build_task() assert task.posttask == posttask shutil.rmtree(tmpdir) shortcut = os.path.join(tmpdir.dirname, "test_posttask_buildercurrent") os.unlink(shortcut)
def test_adapter_results_with_posttask(tmpdir): temp_path = tmpdir.mkdir("test") post_task = SimpleSubtask("Ending") builder = TaskBuilder(SimpleTaskBuilder(), temp_path) builder.set_posttask(subtask=post_task) builder.add_subtask(subtask=SimpleSubtask("First")) builder.add_subtask(subtask=SimpleSubtask("Second")) new_task = builder.build_task() queued_order = [] with worker.ToolJobManager() as manager: for subtask in new_task.subtasks: adapted_tool = speedwagon.worker.SubtaskJobAdapter(subtask) manager.add_job(adapted_tool, adapted_tool.settings) for message in manager._pending_jobs.queue: print(message) queued_order.append(message.args['message']) manager.start() # Fuzz this time.sleep(1) results = list() for r in manager.get_results(): results.append(r.data) assert len(results) == 3 assert "First" == results[0], "results = {}, queued_order={}".format( results, queued_order) assert "Second" == results[1] assert "Ending" == results[2] shutil.rmtree(tmpdir) shortcut = \ os.path.join(tmpdir.dirname, "test_adapter_results_with_postcurrent") if os.path.exists(shortcut): os.unlink(shortcut)