Prechádzať zdrojové kódy

Fixed exception caused by next_transit receiving an unexpected argument. (#4103)

* Fixed exception caused by next_transit receiving an unexpected argument.

* Fixing inconsistent style.

* Adding tests for solar methods to determine if they accept the use_center argument or not.

* Fixing flake8 errors.
DDevine 7 rokov pred
rodič
commit
b47d12dd2d
2 zmenil súbory, kde vykonal 22 pridanie a 5 odobranie
  1. 11 5
      celery/schedules.py
  2. 11 0
      t/unit/app/test_schedules.py

+ 11 - 5
celery/schedules.py

@@ -728,7 +728,7 @@ class solar(BaseSchedule):
         'dawn_nautical': True,
         'dawn_civil': True,
         'sunrise': False,
-        'solar_noon': True,
+        'solar_noon': False,
         'sunset': False,
         'dusk_civil': True,
         'dusk_nautical': True,
@@ -783,10 +783,16 @@ class solar(BaseSchedule):
         last_run_at_utc = localize(last_run_at, timezone.utc)
         self.cal.date = last_run_at_utc
         try:
-            next_utc = getattr(self.cal, self.method)(
-                self.ephem.Sun(),
-                start=last_run_at_utc, use_center=self.use_center,
-            )
+            if self.use_center:
+                next_utc = getattr(self.cal, self.method)(
+                    self.ephem.Sun(),
+                    start=last_run_at_utc, use_center=self.use_center
+                )
+            else:
+                next_utc = getattr(self.cal, self.method)(
+                    self.ephem.Sun(), start=last_run_at_utc
+                )
+
         except self.ephem.CircumpolarError:  # pragma: no cover
             # Sun won't rise/set today.  Check again tomorrow
             # (specifically, after the next anti-transit).

+ 11 - 0
t/unit/app/test_schedules.py

@@ -74,6 +74,17 @@ class test_solar:
         with pytest.raises(ValueError):
             solar('asdqwewqew', 60, 60, app=self.app)
 
+    def test_event_uses_center(self):
+        s = solar('solar_noon', 60, 60, app=self.app)
+        for ev, is_center in s._use_center_l.items():
+            s.method = s._methods[ev]
+            s.is_center = s._use_center_l[ev]
+            try:
+                s.remaining_estimate(datetime.utcnow())
+            except TypeError:
+                pytest.fail("{0} was called with 'use_center' which is not a \
+                    valid keyword for the function.".format(s.method))
+
 
 class test_schedule: