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

61 lines
2.6 KiB

  1. import unittest
  2. from datetime import date
  3. from kosmorrolib import events
  4. from kosmorrolib.data import Event
  5. from kosmorrolib.core import get_timescale
  6. class MyTestCase(unittest.TestCase):
  7. def test_event_only_accepts_valid_values(self):
  8. with self.assertRaises(ValueError):
  9. Event('SUPERNOVA', None, get_timescale().now())
  10. def test_find_oppositions(self):
  11. # Test case: Mars opposition
  12. # Source of the information: https://promenade.imcce.fr/en/pages6/887.html#mar
  13. o1 = (events.search_events(date(2020, 10, 13)), '^2020-10-13T23:25')
  14. o2 = (events.search_events(date(2022, 12, 8)), '^2022-12-08T05:41')
  15. o3 = (events.search_events(date(2025, 1, 16)), '^2025-01-16T02:38')
  16. o4 = (events.search_events(date(2027, 2, 19)), '^2027-02-19T15:50')
  17. for (o, expected_date) in [o1, o2, o3, o4]:
  18. self.assertEqual(1, len(o), 'Expected 1 event for %s, got %d' % (expected_date, len(o)))
  19. self.assertEqual('OPPOSITION', o[0].event_type)
  20. self.assertEqual('MARS', o[0].objects[0].skyfield_name)
  21. self.assertRegex(o[0].start_time.utc_iso(), expected_date)
  22. self.assertIsNone(o[0].end_time)
  23. self.assertEqual('Mars is in opposition', o[0].get_description())
  24. def test_find_conjunctions(self):
  25. # Test case: Mars opposition
  26. # Source of the information: https://promenade.imcce.fr/en/pages6/887.html#mar
  27. c1 = (events.search_events(date(2020, 1, 2)), [(['MERCURY', 'JUPITER BARYCENTER'], '^2020-01-02T15:20')])
  28. c2 = (events.search_events(date(2020, 1, 12)), [(['MERCURY', 'SATURN BARYCENTER'], '^2020-01-12T04:34'),
  29. (['MERCURY', 'PLUTO BARYCENTER'], '^2020-01-12T06:56')])
  30. for (c, expected_dates) in [c1, c2]:
  31. self.assertEqual(len(expected_dates), len(c),
  32. 'Expected %d event(s) for %s, got %d' % (len(expected_dates), expected_dates, len(c)))
  33. i = 0
  34. for conjunction in c:
  35. self.assertEqual('CONJUNCTION', conjunction.event_type)
  36. objects, expected_date = expected_dates[i]
  37. j = 0
  38. self.assertRegex(conjunction.start_time.utc_iso(), expected_date)
  39. for object in objects:
  40. self.assertEqual(object, conjunction.objects[j].skyfield_name)
  41. j += 1
  42. self.assertIsNone(conjunction.end_time)
  43. self.assertRegex(conjunction.get_description(), ' are in conjunction$')
  44. i += 1
  45. if __name__ == '__main__':
  46. unittest.main()