Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

84 linhas
3.8 KiB

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