Sfoglia il codice sorgente

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 2 anni fa
committed by Jérôme Deuchnord
parent
commit
f1d2c29c5f
3 ha cambiato i file con 22 aggiunte e 14 eliminazioni
  1. +2
    -0
      kosmorrolib/enum.py
  2. +17
    -11
      kosmorrolib/events.py
  3. +3
    -3
      tests/events.py

+ 2
- 0
kosmorrolib/enum.py Vedi File

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


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


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



+ 17
- 11
kosmorrolib/events.py Vedi File

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

for i, time in enumerate(times):
elongation = elongations[i]
elongation = round(elongations[i],1)
events.append(
Event(
EventType.MAXIMAL_ELONGATION,
[aster],
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


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.

**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 = []
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:
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



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.

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



+ 3
- 3
tests/events.py Vedi File

@@ -74,7 +74,7 @@ EXPECTED_EVENTS = [
EventType.MAXIMAL_ELONGATION,
[ASTERS[2]],
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)),
],
@@ -86,14 +86,14 @@ EXPECTED_EVENTS = [
EventType.MAXIMAL_ELONGATION,
[ASTERS[2]],
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.MAXIMAL_ELONGATION,
[ASTERS[3]],
datetime(2020, 3, 24, 21, 58),
details="46.1°",
details={'deg':"46.1°"},
),
],
),


Caricamento…
Annulla
Salva