Skip to content

Commit

Permalink
fix bug where the cron method is not returning the action
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
medecau committed Apr 29, 2024
1 parent 14ddf9a commit 289e7e6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sched2"
version = "0.8.0"
version = "0.8.1"
description = "Event scheduler 2"
authors = ["Pedro Rodrigues <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 2 additions & 0 deletions sched2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test_sched2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 289e7e6

Please sign in to comment.