Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@ def seconds(self):
self.unit = "seconds"
return self

@property
def millisecond(self):
if self.interval != 1:
raise IntervalError("Use milliseconds instead of millisecond")
return self.milliseconds

@property
def milliseconds(self):
self.unit = "milliseconds"
return self

@property
def minute(self):
if self.interval != 1:
Expand Down Expand Up @@ -703,9 +714,9 @@ def _schedule_next_run(self) -> None:
"""
Compute the instant when this job should run next.
"""
if self.unit not in ("seconds", "minutes", "hours", "days", "weeks"):
if self.unit not in ("milliseconds", "seconds", "minutes", "hours", "days", "weeks"):
raise ScheduleValueError(
"Invalid unit (valid units are `seconds`, `minutes`, `hours`, "
"Invalid unit (valid units are `millisecond`, `seconds`, `minutes`, `hours`, "
"`days`, and `weeks`)"
)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup


SCHEDULE_VERSION = "1.2.0"
SCHEDULE_VERSION = "1.2.1"
SCHEDULE_DOWNLOAD_URL = "https://github.com/dbader/schedule/tarball/" + SCHEDULE_VERSION


Expand Down
16 changes: 13 additions & 3 deletions test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ class mock_datetime:
Monkey-patch datetime for predictable results
"""

def __init__(self, year, month, day, hour, minute, second=0):
def __init__(self, year, month, day, hour, minute, second=0, microsecond=0):
self.year = year
self.month = month
self.day = day
self.hour = hour
self.minute = minute
self.second = second
self.microsecond = microsecond
self.original_datetime = None

def __enter__(self):
Expand All @@ -59,13 +60,14 @@ def now(cls):
self.hour,
self.minute,
self.second,
self.microsecond,
)

self.original_datetime = datetime.datetime
datetime.datetime = MockDate

return MockDate(
self.year, self.month, self.day, self.hour, self.minute, self.second
self.year, self.month, self.day, self.hour, self.minute, self.second, self.microsecond,
)

def __exit__(self, *args, **kwargs):
Expand All @@ -77,6 +79,7 @@ def setUp(self):
schedule.clear()

def test_time_units(self):
assert every().milliseconds.unit == "milliseconds"
assert every().seconds.unit == "seconds"
assert every().minutes.unit == "minutes"
assert every().hours.unit == "hours"
Expand Down Expand Up @@ -211,6 +214,7 @@ def test_next_run_with_tag(self):
assert schedule.next_run("tag4") is None

def test_singular_time_units_match_plural_units(self):
assert every().millisecond.unit == every().milliseconds.unit
assert every().second.unit == every().seconds.unit
assert every().minute.unit == every().minutes.unit
assert every().hour.unit == every().hours.unit
Expand Down Expand Up @@ -438,9 +442,15 @@ def test_at_time_minute(self):
self.assertRaises(TypeError, every().minute.at, 2)

def test_next_run_time(self):
with mock_datetime(2010, 1, 6, 12, 15):
with mock_datetime(2010, 1, 6, 12, 15, 22, 45000):
mock_job = make_mock_job()
assert schedule.next_run() is None
assert every().millisecond.do(mock_job).next_run.microsecond == 46000
assert every(100).milliseconds.do(mock_job).next_run.microsecond == 145000
assert every().second.do(mock_job).next_run.second == 23
assert every(3).seconds.do(mock_job).next_run.second == 25
assert every().second.do(mock_job).next_run.second == 23
assert every(3).seconds.do(mock_job).next_run.second == 25
assert every().minute.do(mock_job).next_run.minute == 16
assert every(5).minutes.do(mock_job).next_run.minute == 20
assert every().hour.do(mock_job).next_run.hour == 13
Expand Down