Browse Source

test:update legacy tests for events.py. update: update enum.py and events.py to match black coding style.

pull/24/head
Tung Lam Nguyen Le 3 years ago
committed by Jérôme Deuchnord
parent
commit
f1d2c29c5f
3 changed files with 22 additions and 14 deletions
  1. +2
    -0
      kosmorrolib/enum.py
  2. +17
    -11
      kosmorrolib/events.py
  3. +3
    -3
      tests/events.py

+ 2
- 0
kosmorrolib/enum.py View File

@@ -15,12 +15,14 @@ class MoonPhaseType(Enum):
LAST_QUARTER = 7 LAST_QUARTER = 7
WANING_CRESCENT = 8 WANING_CRESCENT = 8



class SeasonType(Enum): class SeasonType(Enum):
MARCH_EQUINOX = 0 MARCH_EQUINOX = 0
JUNE_SOLSTICE = 1 JUNE_SOLSTICE = 1
SEPTEMBER_EQUINOX = 2 SEPTEMBER_EQUINOX = 2
DECEMBER_SOLSTICE = 3 DECEMBER_SOLSTICE = 3



class EventType(Enum): class EventType(Enum):
"""An enumeration for the supported event types.""" """An enumeration for the supported event types."""




+ 17
- 11
kosmorrolib/events.py View File

@@ -195,13 +195,13 @@ def _search_maximal_elongations(
) )


for i, time in enumerate(times): for i, time in enumerate(times):
elongation = elongations[i]
elongation = round(elongations[i],1)
events.append( events.append(
Event( Event(
EventType.MAXIMAL_ELONGATION, EventType.MAXIMAL_ELONGATION,
[aster], [aster],
translate_to_timezone(time.utc_datetime(), timezone), translate_to_timezone(time.utc_datetime(), timezone),
details={ 'deg': elongation},
details={"deg": f"{elongation}°"},
) )
) )


@@ -263,7 +263,9 @@ def _search_moon_perigee(start_time: Time, end_time: Time, timezone: int) -> [Ev
return events return events




def _search_earth_season_change(start_time: Time, end_time: Time, timezone: int) -> [Event]:
def _search_earth_season_change(
start_time: Time, end_time: Time, timezone: int
) -> [Event]:
"""Function to find earth season change event. """Function to find earth season change event.


**Warning:** this is an internal function, not intended for use by end-developers. **Warning:** this is an internal function, not intended for use by end-developers.
@@ -284,18 +286,22 @@ def _search_earth_season_change(start_time: Time, end_time: Time, timezone: int)
[] []
""" """
events = [] events = []
event_time, event_id = almanac.find_discrete(start_time,end_time,almanac.seasons(get_skf_objects()))
event_time, event_id = almanac.find_discrete(
start_time, end_time, almanac.seasons(get_skf_objects())
)
if len(event_time) == 0: if len(event_time) == 0:
return [] return []
events.append(Event(
EventType.SEASON_CHANGE,
[],
translate_to_timezone(event_time.utc_datetime()[0], timezone),
details={'season':SeasonType(event_id[0])}))
events.append(
Event(
EventType.SEASON_CHANGE,
[],
translate_to_timezone(event_time.utc_datetime()[0], timezone),
details={"season": SeasonType(event_id[0])},
)
)
return events return events





def get_events(for_date: date = date.today(), timezone: int = 0) -> [Event]: def get_events(for_date: date = date.today(), timezone: int = 0) -> [Event]:
"""Calculate and return a list of events for the given date, adjusted to the given timezone if any. """Calculate and return a list of events for the given date, adjusted to the given timezone if any.


@@ -340,7 +346,7 @@ def get_events(for_date: date = date.today(), timezone: int = 0) -> [Event]:
_search_maximal_elongations, _search_maximal_elongations,
_search_moon_apogee, _search_moon_apogee,
_search_moon_perigee, _search_moon_perigee,
_search_earth_season_change
_search_earth_season_change,
]: ]:
found_events.append(fun(start_time, end_time, timezone)) found_events.append(fun(start_time, end_time, timezone))




+ 3
- 3
tests/events.py View File

@@ -74,7 +74,7 @@ EXPECTED_EVENTS = [
EventType.MAXIMAL_ELONGATION, EventType.MAXIMAL_ELONGATION,
[ASTERS[2]], [ASTERS[2]],
datetime(2020, 2, 10, 13, 46), datetime(2020, 2, 10, 13, 46),
details="18.2°",
details={'deg':"18.2°"},
), ),
Event(EventType.MOON_PERIGEE, [ASTERS[1]], datetime(2020, 2, 10, 20, 34)), Event(EventType.MOON_PERIGEE, [ASTERS[1]], datetime(2020, 2, 10, 20, 34)),
], ],
@@ -86,14 +86,14 @@ EXPECTED_EVENTS = [
EventType.MAXIMAL_ELONGATION, EventType.MAXIMAL_ELONGATION,
[ASTERS[2]], [ASTERS[2]],
datetime(2020, 3, 24, 1, 56), datetime(2020, 3, 24, 1, 56),
details="27.8°",
details={'deg':"27.8°"},
), ),
Event(EventType.MOON_APOGEE, [ASTERS[1]], datetime(2020, 3, 24, 15, 39)), Event(EventType.MOON_APOGEE, [ASTERS[1]], datetime(2020, 3, 24, 15, 39)),
Event( Event(
EventType.MAXIMAL_ELONGATION, EventType.MAXIMAL_ELONGATION,
[ASTERS[3]], [ASTERS[3]],
datetime(2020, 3, 24, 21, 58), datetime(2020, 3, 24, 21, 58),
details="46.1°",
details={'deg':"46.1°"},
), ),
], ],
), ),


Loading…
Cancel
Save