25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

events.py 3.9 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import unittest
  2. from datetime import date, datetime
  3. from unittest_data_provider import data_provider
  4. from kosmorrolib import events
  5. from kosmorrolib.data import Event, ASTERS
  6. from kosmorrolib.enum import EventType
  7. from kosmorrolib.exceptions import OutOfRangeDateError
  8. class EventTestCase(unittest.TestCase):
  9. def setUp(self) -> None:
  10. self.maxDiff = None
  11. expected_events_provider = lambda: (
  12. (date(2020, 2, 7), []),
  13. (date(2020, 10, 13), [Event(EventType.OPPOSITION, [ASTERS[4]], datetime(2020, 10, 13, 23, 25))]),
  14. (date(2022, 12, 8), [Event(EventType.CONJUNCTION, [ASTERS[1], ASTERS[4]], datetime(2022, 12, 8, 4, 18)),
  15. Event(EventType.OPPOSITION, [ASTERS[4]], datetime(2022, 12, 8, 5, 41))]),
  16. (date(2025, 1, 16), [Event(EventType.OPPOSITION, [ASTERS[4]], datetime(2025, 1, 16, 2, 38))]),
  17. (date(2027, 2, 19), [Event(EventType.MOON_PERIGEE, [ASTERS[1]], datetime(2027, 2, 19, 7, 38)),
  18. Event(EventType.OPPOSITION, [ASTERS[4]], datetime(2027, 2, 19, 15, 50))]),
  19. (date(2020, 1, 2), [Event(EventType.MOON_APOGEE, [ASTERS[1]], datetime(2020, 1, 2, 1, 32)),
  20. Event(EventType.CONJUNCTION, [ASTERS[2], ASTERS[5]], datetime(2020, 1, 2, 16, 41))]),
  21. (date(2020, 1, 12), [Event(EventType.CONJUNCTION, [ASTERS[2], ASTERS[6]], datetime(2020, 1, 12, 9, 51)),
  22. Event(EventType.CONJUNCTION, [ASTERS[2], ASTERS[9]], datetime(2020, 1, 12, 10, 13)),
  23. Event(EventType.CONJUNCTION, [ASTERS[6], ASTERS[9]], datetime(2020, 1, 12, 16, 57))]),
  24. (date(2020, 2, 10), [Event(EventType.MAXIMAL_ELONGATION, [ASTERS[2]], datetime(2020, 2, 10, 13, 46), details='18.2°'),
  25. Event(EventType.MOON_PERIGEE, [ASTERS[1]], datetime(2020, 2, 10, 20, 34))]),
  26. (date(2020, 3, 24), [Event(EventType.MAXIMAL_ELONGATION, [ASTERS[2]], datetime(2020, 3, 24, 1, 56), details='27.8°'),
  27. Event(EventType.MOON_APOGEE, [ASTERS[1]], datetime(2020, 3, 24, 15, 39)),
  28. Event(EventType.MAXIMAL_ELONGATION, [ASTERS[3]], datetime(2020, 3, 24, 21, 58), details='46.1°')]),
  29. (date(2005, 6, 16), [Event(EventType.OCCULTATION, [ASTERS[1], ASTERS[5]], datetime(2005, 6, 16, 6, 31))]),
  30. (date(2020, 4, 7), [Event(EventType.MOON_PERIGEE, [ASTERS[1]], datetime(2020, 4, 7, 18, 14))]),
  31. (date(2020, 1, 29), [Event(EventType.MOON_APOGEE, [ASTERS[1]], datetime(2020, 1, 29, 21, 32))])
  32. )
  33. @data_provider(expected_events_provider)
  34. def test_search_events(self, d: date, expected_events: [Event]):
  35. actual_events = events.search_events(d)
  36. self.assertEqual(len(expected_events), len(actual_events),
  37. 'Expected %d elements, got %d for date %s.\n%s' % (len(expected_events),
  38. len(actual_events),
  39. d.isoformat(),
  40. actual_events))
  41. for i, expected_event in enumerate(expected_events):
  42. actual_event = actual_events[i]
  43. # Remove unnecessary precision (seconds and microseconds)
  44. actual_event.start_time = datetime(actual_event.start_time.year,
  45. actual_event.start_time.month,
  46. actual_event.start_time.day,
  47. actual_event.start_time.hour,
  48. actual_event.start_time.minute)
  49. self.assertEqual(expected_event.__dict__, actual_event.__dict__)
  50. def test_get_events_raises_exception_on_out_of_date_range(self):
  51. with self.assertRaises(OutOfRangeDateError):
  52. events.search_events(date(1789, 5, 5))
  53. if __name__ == '__main__':
  54. unittest.main()