Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. )
  28. @data_provider(expected_events_provider)
  29. def test_search_events(self, d: date, expected_events: [Event]):
  30. actual_events = events.search_events(d)
  31. self.assertEqual(len(expected_events), len(actual_events),
  32. 'Expected %d elements, got %d for date %s.' % (len(expected_events),
  33. len(actual_events),
  34. d.isoformat()))
  35. for i, expected_event in enumerate(expected_events):
  36. actual_event = actual_events[i]
  37. # Remove unnecessary precision (seconds and microseconds)
  38. actual_event.start_time = datetime(actual_event.start_time.year,
  39. actual_event.start_time.month,
  40. actual_event.start_time.day,
  41. actual_event.start_time.hour,
  42. actual_event.start_time.minute)
  43. self.assertEqual(expected_event.__dict__, actual_event.__dict__)
  44. if __name__ == '__main__':
  45. unittest.main()