소스 검색

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 15 년 전
부모
커밋
abbc12e04d
2개의 변경된 파일25개의 추가작업 그리고 1개의 파일을 삭제
  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))