From 289e7e68c0c0a08bebe82e9223801a240faafb7e Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 29 Apr 2024 07:13:53 +0200 Subject: [PATCH] fix bug where the `cron` method is not returning the action this is problematic as one would not be able to add to cron rules to the same function, or any other decorator for that matter. --- pyproject.toml | 2 +- sched2.py | 2 ++ test_sched2.py | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index af458f8..10e3235 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sched2" -version = "0.8.0" +version = "0.8.1" description = "Event scheduler 2" authors = ["Pedro Rodrigues "] license = "MIT" diff --git a/sched2.py b/sched2.py index fc85bc1..b112447 100644 --- a/sched2.py +++ b/sched2.py @@ -125,6 +125,8 @@ def cron_runner(action): delay = 60 - self.timefunc() % 60 self.enter(delay, 0, cron_runner, (action,)) + return action + return cron_runner @property diff --git a/test_sched2.py b/test_sched2.py index 66c4119..b852e1f 100644 --- a/test_sched2.py +++ b/test_sched2.py @@ -21,6 +21,26 @@ def action(mocker): return mocker.Mock(return_value=False) +def test_repeat_method_returns_action(scheduler, action): + repeat_return_value = scheduler.repeat(1, 1, action, immediate=False) + assert repeat_return_value is action + + +def test_every_decorator_method_returns_action(scheduler, action): + every_return_value = scheduler.every(1)(action) + assert every_return_value is action + + +def test_cron_decorator_method_returns_action(scheduler, action): + cron_return_value = scheduler.cron("* * * * *")(action) + assert cron_return_value is action + + +def test_on_decorator_method_returns_action(scheduler, action): + on_return_value = scheduler.on("event")(action) + assert on_return_value is action + + def test_repeat_adds_a_single_event(scheduler, action): # starts empty assert len(scheduler.queue) == 0