A library that computes the ephemerides.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

events.py 4.4 KiB

3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. (
  11. date(2020, 10, 13),
  12. [Event(EventType.OPPOSITION, [ASTERS[4]], datetime(2020, 10, 13, 23, 25))],
  13. ),
  14. (
  15. date(2022, 12, 8),
  16. [
  17. Event(
  18. EventType.CONJUNCTION,
  19. [ASTERS[1], ASTERS[4]],
  20. datetime(2022, 12, 8, 4, 18),
  21. ),
  22. Event(EventType.OPPOSITION, [ASTERS[4]], datetime(2022, 12, 8, 5, 41)),
  23. ],
  24. ),
  25. (
  26. date(2025, 1, 16),
  27. [Event(EventType.OPPOSITION, [ASTERS[4]], datetime(2025, 1, 16, 2, 38))],
  28. ),
  29. (
  30. date(2027, 2, 19),
  31. [
  32. Event(EventType.MOON_PERIGEE, [ASTERS[1]], datetime(2027, 2, 19, 7, 38)),
  33. Event(EventType.OPPOSITION, [ASTERS[4]], datetime(2027, 2, 19, 15, 50)),
  34. ],
  35. ),
  36. (
  37. date(2020, 1, 2),
  38. [
  39. Event(EventType.MOON_APOGEE, [ASTERS[1]], datetime(2020, 1, 2, 1, 32)),
  40. Event(
  41. EventType.CONJUNCTION,
  42. [ASTERS[2], ASTERS[5]],
  43. datetime(2020, 1, 2, 16, 41),
  44. ),
  45. ],
  46. ),
  47. (
  48. date(2020, 1, 12),
  49. [
  50. Event(
  51. EventType.CONJUNCTION,
  52. [ASTERS[2], ASTERS[6]],
  53. datetime(2020, 1, 12, 9, 51),
  54. ),
  55. Event(
  56. EventType.CONJUNCTION,
  57. [ASTERS[2], ASTERS[9]],
  58. datetime(2020, 1, 12, 10, 13),
  59. ),
  60. Event(
  61. EventType.CONJUNCTION,
  62. [ASTERS[6], ASTERS[9]],
  63. datetime(2020, 1, 12, 16, 57),
  64. ),
  65. ],
  66. ),
  67. (
  68. date(2020, 2, 10),
  69. [
  70. Event(
  71. EventType.MAXIMAL_ELONGATION,
  72. [ASTERS[2]],
  73. datetime(2020, 2, 10, 13, 46),
  74. details="18.2°",
  75. ),
  76. Event(EventType.MOON_PERIGEE, [ASTERS[1]], datetime(2020, 2, 10, 20, 34)),
  77. ],
  78. ),
  79. (
  80. date(2020, 3, 24),
  81. [
  82. Event(
  83. EventType.MAXIMAL_ELONGATION,
  84. [ASTERS[2]],
  85. datetime(2020, 3, 24, 1, 56),
  86. details="27.8°",
  87. ),
  88. Event(EventType.MOON_APOGEE, [ASTERS[1]], datetime(2020, 3, 24, 15, 39)),
  89. Event(
  90. EventType.MAXIMAL_ELONGATION,
  91. [ASTERS[3]],
  92. datetime(2020, 3, 24, 21, 58),
  93. details="46.1°",
  94. ),
  95. ],
  96. ),
  97. (
  98. date(2005, 6, 16),
  99. [
  100. Event(
  101. EventType.OCCULTATION,
  102. [ASTERS[1], ASTERS[5]],
  103. datetime(2005, 6, 16, 6, 31),
  104. )
  105. ],
  106. ),
  107. (
  108. date(2020, 4, 7),
  109. [Event(EventType.MOON_PERIGEE, [ASTERS[1]], datetime(2020, 4, 7, 18, 14))],
  110. ),
  111. (
  112. date(2020, 1, 29),
  113. [Event(EventType.MOON_APOGEE, [ASTERS[1]], datetime(2020, 1, 29, 21, 32))],
  114. ),
  115. ]
  116. class EventTestCase(unittest.TestCase):
  117. def setUp(self) -> None:
  118. self.maxDiff = None
  119. @parameterized.expand(EXPECTED_EVENTS)
  120. def test_search_events(self, d: date, expected_events: [Event]):
  121. actual_events = events.get_events(d)
  122. self.assertEqual(
  123. len(expected_events),
  124. len(actual_events),
  125. "Expected %d elements, got %d for date %s.\n%s"
  126. % (len(expected_events), len(actual_events), d.isoformat(), actual_events),
  127. )
  128. for i, expected_event in enumerate(expected_events):
  129. actual_event = actual_events[i]
  130. # Remove unnecessary precision (seconds and microseconds)
  131. actual_event.start_time = datetime(
  132. actual_event.start_time.year,
  133. actual_event.start_time.month,
  134. actual_event.start_time.day,
  135. actual_event.start_time.hour,
  136. actual_event.start_time.minute,
  137. )
  138. self.assertEqual(expected_event.__dict__, actual_event.__dict__)
  139. def test_get_events_raises_exception_on_out_of_date_range(self):
  140. with self.assertRaises(OutOfRangeDateError):
  141. events.get_events(date(1789, 5, 5))
  142. if __name__ == "__main__":
  143. unittest.main()