Procházet zdrojové kódy

Fix for isoweekday()'s return value.

Its return values are in the range 1..7 (instead of the expected range 0..6).
This is backed up by three extra unit tests.
Vincent Driessen před 15 roky
rodič
revize
abbc12e04d
2 změnil soubory, kde provedl 25 přidání a 1 odebrání
  1. 1 1
      celery/task/schedules.py
  2. 24 0
      celery/tests/test_task.py

+ 1 - 1
celery/task/schedules.py

@@ -217,7 +217,7 @@ class crontab(schedule):
         last = now - last_run_at
         due, when = False, 1
         if last.days > 0 or last.seconds > 60:
-            due = now.isoweekday() in self.day_of_week and \
+            due = now.isoweekday() % 7 in self.day_of_week and \
                   now.hour in self.hour and \
                   now.minute in self.minute
         return due, when

+ 24 - 0
celery/tests/test_task.py

@@ -636,6 +636,30 @@ class test_crontab_is_due(unittest.TestCase):
         self.assertFalse(due)
         self.assertEquals(remaining, 1)
 
+    # 29th of May 2010 is a saturday
+    @patch_crontab_nowfun(HourlyPeriodic, datetime(2010, 5, 29, 10, 30))
+    def test_execution_is_due_on_saturday(self):
+        last_ran = datetime.now() - timedelta(seconds=61)
+        due, remaining = EveryMinutePeriodic().is_due(last_ran)
+        self.assertTrue(due)
+        self.assertEquals(remaining, 1)
+
+    # 30th of May 2010 is a sunday
+    @patch_crontab_nowfun(HourlyPeriodic, datetime(2010, 5, 30, 10, 30))
+    def test_execution_is_due_on_sunday(self):
+        last_ran = datetime.now() - timedelta(seconds=61)
+        due, remaining = EveryMinutePeriodic().is_due(last_ran)
+        self.assertTrue(due)
+        self.assertEquals(remaining, 1)
+
+    # 31st of May 2010 is a monday
+    @patch_crontab_nowfun(HourlyPeriodic, datetime(2010, 5, 31, 10, 30))
+    def test_execution_is_due_on_monday(self):
+        last_ran = datetime.now() - timedelta(seconds=61)
+        due, remaining = EveryMinutePeriodic().is_due(last_ran)
+        self.assertTrue(due)
+        self.assertEquals(remaining, 1)
+
     @patch_crontab_nowfun(HourlyPeriodic, datetime(2010, 5, 10, 10, 30))
     def test_every_hour_execution_is_due(self):
         due, remaining = HourlyPeriodic().is_due(datetime(2010, 5, 10, 6, 30))