Skip to content

Commit

Permalink
Improve representation of scheduled one-time-jobs (attzonko#255)
Browse files Browse the repository at this point in the history
* Test textual representation of scheduled one-time-jobs

* Add a better repr to OneTimeJob

(cherry picked from commit 69caeb4)
  • Loading branch information
unode authored Sep 2, 2021
1 parent 30a7a92 commit d6f5d52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mmpy_bot/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class OneTimeJob(schedule.Job):
def _schedule_next_run(self):
pass

def __repr__(self):
txt = super().__repr__()
# One time jobs always read "Every 0 None at ..."
# due undefined self.interval (0) and self.unit (None)
return txt.replace("Every 0 None", "Once")

def set_next_run(self, next_time: datetime):
if not isinstance(next_time, datetime):
raise AssertionError("The next_time parameter should be a datetime object.")
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def test_once_single_call():

schedule.once().do(mock)

assert repr(schedule.jobs[0]).startswith("Once at")

for _ in range(10):
schedule.run_pending()
time.sleep(0.05)
Expand Down

0 comments on commit d6f5d52

Please sign in to comment.