No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

88 líneas
4.2 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.isoformat(), 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.isoformat(), 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. def test_find_maximal_elongation(self):
  46. e = events.search_events(date(2020, 2, 10))
  47. self.assertEquals(1, len(e), 'Expected 1 events, got %d.' % len(e))
  48. e = e[0]
  49. self.assertEquals('MAXIMAL_ELONGATION', e.event_type)
  50. self.assertEquals(1, len(e.objects))
  51. self.assertEquals('MERCURY', e.objects[0].skyfield_name)
  52. self.assertEqual('18.2°', e.details)
  53. self.assertEquals((2020, 2, 10, 13, 46), (e.start_time.year, e.start_time.month, e.start_time.day,
  54. e.start_time.hour, e.start_time.minute))
  55. e = events.search_events(date(2020, 3, 24))
  56. self.assertEquals(2, len(e), 'Expected 2 events, got %d.' % len(e))
  57. self.assertEquals('MAXIMAL_ELONGATION', e[0].event_type)
  58. self.assertEquals(1, len(e[0].objects))
  59. self.assertEquals('MERCURY', e[0].objects[0].skyfield_name)
  60. self.assertEqual('27.8°', e[0].details)
  61. self.assertEquals((2020, 3, 24, 1, 56), (e[0].start_time.year, e[0].start_time.month, e[0].start_time.day,
  62. e[0].start_time.hour, e[0].start_time.minute))
  63. self.assertEquals('MAXIMAL_ELONGATION', e[1].event_type)
  64. self.assertEquals(1, len(e[1].objects))
  65. self.assertEquals('VENUS', e[1].objects[0].skyfield_name)
  66. self.assertEqual('46.1°', e[1].details)
  67. self.assertEquals((2020, 3, 24, 21, 58), (e[1].start_time.year, e[1].start_time.month, e[1].start_time.day,
  68. e[1].start_time.hour, e[1].start_time.minute))
  69. if __name__ == '__main__':
  70. unittest.main()