Explorar o código

Raise a ValueError on invalid weekday literals.

Vincent Driessen %!s(int64=15) %!d(string=hai) anos
pai
achega
b852fd1c1b
Modificáronse 2 ficheiros con 10 adicións e 1 borrados
  1. 4 1
      celery/task/schedules.py
  2. 6 0
      celery/tests/test_task.py

+ 4 - 1
celery/task/schedules.py

@@ -81,7 +81,10 @@ class crontab_parser(object):
         try:
             i = int(toks[0])
         except ValueError:
-            i = weekday(toks[0])
+            try:
+                i = weekday(toks[0])
+            except KeyError:
+                raise ValueError("Invalid weekday literal '%s'." % toks[0])
         return [i]
 
     @staticmethod

+ 6 - 0
celery/tests/test_task.py

@@ -618,6 +618,12 @@ class test_crontab_is_due(unittest.TestCase):
         c = crontab(day_of_week='*/2')
         self.assertEquals(c.day_of_week, set([0,2,4,6]))
 
+    def test_crontab_spec_invalid_dow(self):
+        self.assertRaises(ValueError, crontab, day_of_week='fooday-barday')
+        self.assertRaises(ValueError, crontab, day_of_week='1,4,foo')
+        self.assertRaises(ValueError, crontab, day_of_week='7')
+        self.assertRaises(ValueError, crontab, day_of_week='12')
+
     def test_every_minute_execution_is_due(self):
         last_ran = datetime.now() - timedelta(seconds=61)
         due, remaining = EveryMinutePeriodic().is_due(last_ran)