From 4dbfe7a82cfe5c3d84e5e37989afdb3558f23e54 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 8 Apr 2022 21:35:55 +0200 Subject: [PATCH] feat: dispatch transmit args to actions --- bopytex/scheduler.py | 2 +- test/test_scheduler.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bopytex/scheduler.py b/bopytex/scheduler.py index 1fadec7..3b39bd3 100644 --- a/bopytex/scheduler.py +++ b/bopytex/scheduler.py @@ -20,7 +20,7 @@ class Scheduler: def dispatch(self, task): """ Do a task """ - ans = self.actions[task.action](task.deps) + ans = self.actions[task.action](task.deps, task.args) return ans def __next__(self): diff --git a/test/test_scheduler.py b/test/test_scheduler.py index e994d50..ce7b1c6 100644 --- a/test/test_scheduler.py +++ b/test/test_scheduler.py @@ -3,14 +3,15 @@ from bopytex.scheduler import Scheduler def test_schedule_append(): - actions = {"DO": lambda _: "done"} + actions = {"DO": lambda deps, args: "done"} scheduler = Scheduler(actions) tasks = [Task(action="DO", args={}, deps=[])] scheduler.append(tasks) assert scheduler.tasks == tasks + def test_schedule_dispatch(): - actions = {"DO": lambda _: "done"} + actions = {"DO": lambda deps, args: "done"} scheduler = Scheduler(actions) task = Task(action="DO", args={}, deps=[]) result = scheduler.dispatch(task) @@ -18,10 +19,20 @@ def test_schedule_dispatch(): def test_schedule_one_task(): - actions = {"DO": lambda _: "done"} + actions = {"DO": lambda deps, args: "done"} scheduler = Scheduler(actions) scheduler.append([Task(action="DO", args={}, deps=[])]) result = scheduler.__next__() assert result == "done" assert scheduler.tasks == [] assert scheduler.done == ["done"] + + +def test_schedule_one_task_with_args(): + actions = {"DO": lambda deps, args: f"{args['task']} done"} + scheduler = Scheduler(actions) + scheduler.append([Task(action="DO", args={"task": "one"}, deps=[])]) + result = scheduler.__next__() + assert result == "one done" + assert scheduler.tasks == [] + assert scheduler.done == ["one done"]