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

67 lines
3.1 KiB

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