Skip to content

Commit

Permalink
Clean up error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dbader committed Jan 21, 2019
1 parent 3726589 commit 84447c0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions schedule/__init__.py
Expand Up @@ -373,20 +373,20 @@ def at(self, time_str):
"""
if (self.unit not in ('days', 'hours', 'minutes')
and not self.start_day):
raise ScheduleValueError('Invalid unit.')
raise ScheduleValueError('Invalid unit')
if not isinstance(time_str, str):
raise TypeError('at() should be passed a string.')
raise TypeError('at() should be passed a string')
if self.unit == 'days' or self.start_day:
if not re.match(r'^([0-2]\d:)?[0-5]\d:[0-5]\d$', time_str):
raise ScheduleValueError('Invalid time format.')
raise ScheduleValueError('Invalid time format')
if self.unit == 'hours':
if not re.match(r'^([0-5]\d)?:[0-5]\d$', time_str):
raise ScheduleValueError(('Invalid time format for'
' an hourly job.'))
' an hourly job'))
if self.unit == 'minutes':
if not re.match(r'^:[0-5]\d$', time_str):
raise ScheduleValueError(('Invalid time format for'
' a minutely job.'))
' a minutely job'))
time_values = time_str.split(':')
if len(time_values) == 3:
hour, minute, second = time_values
Expand All @@ -400,7 +400,7 @@ def at(self, time_str):
if self.unit == 'days' or self.start_day:
hour = int(hour)
if not (0 <= hour <= 23):
raise ScheduleValueError('Invalid number of hours.')
raise ScheduleValueError('Invalid number of hours')
elif self.unit == 'hours':
hour = 0
elif self.unit == 'minutes':
Expand Down Expand Up @@ -473,11 +473,11 @@ def _schedule_next_run(self):
Compute the instant when this job should run next.
"""
if self.unit not in ('seconds', 'minutes', 'hours', 'days', 'weeks'):
raise ScheduleValueError('Invalid unit.')
raise ScheduleValueError('Invalid unit')

if self.latest is not None:
if not (self.latest >= self.interval):
raise ScheduleError('`latest` is greater than `interval`.')
raise ScheduleError('`latest` is greater than `interval`')
interval = random.randint(self.interval, self.latest)
else:
interval = self.interval
Expand All @@ -497,7 +497,7 @@ def _schedule_next_run(self):
'sunday'
)
if self.start_day not in weekdays:
raise ScheduleValueError('Invalid start day.')
raise ScheduleValueError('Invalid start day')
weekday = weekdays.index(self.start_day)
days_ahead = weekday - self.next_run.weekday()
if days_ahead <= 0: # Target day already happened this week
Expand All @@ -507,7 +507,7 @@ def _schedule_next_run(self):
if (self.unit not in ('days', 'hours', 'minutes')
and self.start_day is None):
raise ScheduleValueError(('Invalid unit without'
' specifying start day.'))
' specifying start day'))
kwargs = {
'second': self.at_time.second,
'microsecond': 0
Expand Down

0 comments on commit 84447c0

Please sign in to comment.