A library that computes the ephemerides.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

126 lignes
6.0 KiB

  1. import unittest
  2. from kosmorrolib.enum import MoonPhaseType
  3. from .testutils import expect_assertions
  4. from kosmorrolib import ephemerides
  5. from kosmorrolib.data import Position, MoonPhase
  6. from datetime import date
  7. from kosmorrolib.exceptions import OutOfRangeDateError
  8. class EphemeridesTestCase(unittest.TestCase):
  9. def test_get_ephemerides_for_aster_returns_correct_hours(self):
  10. position = Position(0, 0)
  11. eph = ephemerides.get_ephemerides(date=date(2019, 11, 18), position=position)
  12. @expect_assertions(self.assertRegex, num=3)
  13. def do_assertions(assert_regex):
  14. for ephemeris in eph:
  15. if ephemeris.object.skyfield_name == "SUN":
  16. assert_regex(ephemeris.rise_time.isoformat(), "^2019-11-18T05:41:")
  17. assert_regex(
  18. ephemeris.culmination_time.isoformat(), "^2019-11-18T11:45:"
  19. )
  20. assert_regex(ephemeris.set_time.isoformat(), "^2019-11-18T17:48:")
  21. break
  22. do_assertions()
  23. ###################################################################################################################
  24. ### MOON PHASE TESTS ###
  25. ###################################################################################################################
  26. def test_moon_phase_new_moon(self):
  27. phase = ephemerides.get_moon_phase(date(2019, 11, 25))
  28. self.assertEqual(MoonPhaseType.WANING_CRESCENT, phase.phase_type)
  29. self.assertIsNone(phase.time)
  30. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-26T")
  31. phase = ephemerides.get_moon_phase(date(2019, 11, 26))
  32. self.assertEqual(MoonPhaseType.NEW_MOON, phase.phase_type)
  33. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-12-04T")
  34. phase = ephemerides.get_moon_phase(date(2019, 11, 27))
  35. self.assertEqual(MoonPhaseType.WAXING_CRESCENT, phase.phase_type)
  36. self.assertIsNone(phase.time)
  37. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-12-04T")
  38. def test_moon_phase_first_crescent(self):
  39. phase = ephemerides.get_moon_phase(date(2019, 11, 3))
  40. self.assertEqual(MoonPhaseType.WAXING_CRESCENT, phase.phase_type)
  41. self.assertIsNone(phase.time)
  42. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-04T")
  43. phase = ephemerides.get_moon_phase(date(2019, 11, 4))
  44. self.assertEqual(MoonPhaseType.FIRST_QUARTER, phase.phase_type)
  45. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-12T")
  46. phase = ephemerides.get_moon_phase(date(2019, 11, 5))
  47. self.assertEqual(MoonPhaseType.WAXING_GIBBOUS, phase.phase_type)
  48. self.assertIsNone(phase.time)
  49. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-12T")
  50. def test_moon_phase_full_moon(self):
  51. phase = ephemerides.get_moon_phase(date(2019, 11, 11))
  52. self.assertEqual(MoonPhaseType.WAXING_GIBBOUS, phase.phase_type)
  53. self.assertIsNone(phase.time)
  54. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-12T")
  55. phase = ephemerides.get_moon_phase(date(2019, 11, 12))
  56. self.assertEqual(MoonPhaseType.FULL_MOON, phase.phase_type)
  57. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-19T")
  58. phase = ephemerides.get_moon_phase(date(2019, 11, 13))
  59. self.assertEqual(MoonPhaseType.WANING_GIBBOUS, phase.phase_type)
  60. self.assertIsNone(phase.time)
  61. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-19T")
  62. def test_moon_phase_last_quarter(self):
  63. phase = ephemerides.get_moon_phase(date(2019, 11, 18))
  64. self.assertEqual(MoonPhaseType.WANING_GIBBOUS, phase.phase_type)
  65. self.assertIsNone(phase.time)
  66. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-19T")
  67. phase = ephemerides.get_moon_phase(date(2019, 11, 19))
  68. self.assertEqual(MoonPhaseType.LAST_QUARTER, phase.phase_type)
  69. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-26T")
  70. phase = ephemerides.get_moon_phase(date(2019, 11, 20))
  71. self.assertEqual(MoonPhaseType.WANING_CRESCENT, phase.phase_type)
  72. self.assertIsNone(phase.time)
  73. self.assertRegexpMatches(phase.next_phase_date.isoformat(), "^2019-11-26T")
  74. def test_moon_phase_prediction(self):
  75. phase = MoonPhase(MoonPhaseType.NEW_MOON, None, None)
  76. self.assertEqual(MoonPhaseType.FIRST_QUARTER, phase.get_next_phase())
  77. phase = MoonPhase(MoonPhaseType.WAXING_CRESCENT, None, None)
  78. self.assertEqual(MoonPhaseType.FIRST_QUARTER, phase.get_next_phase())
  79. phase = MoonPhase(MoonPhaseType.FIRST_QUARTER, None, None)
  80. self.assertEqual(MoonPhaseType.FULL_MOON, phase.get_next_phase())
  81. phase = MoonPhase(MoonPhaseType.WAXING_GIBBOUS, None, None)
  82. self.assertEqual(MoonPhaseType.FULL_MOON, phase.get_next_phase())
  83. phase = MoonPhase(MoonPhaseType.FULL_MOON, None, None)
  84. self.assertEqual(MoonPhaseType.LAST_QUARTER, phase.get_next_phase())
  85. phase = MoonPhase(MoonPhaseType.WANING_GIBBOUS, None, None)
  86. self.assertEqual(MoonPhaseType.LAST_QUARTER, phase.get_next_phase())
  87. phase = MoonPhase(MoonPhaseType.LAST_QUARTER, None, None)
  88. self.assertEqual(MoonPhaseType.NEW_MOON, phase.get_next_phase())
  89. phase = MoonPhase(MoonPhaseType.WANING_CRESCENT, None, None)
  90. self.assertEqual(MoonPhaseType.NEW_MOON, phase.get_next_phase())
  91. def test_get_ephemerides_raises_exception_on_out_of_date_range(self):
  92. with self.assertRaises(OutOfRangeDateError):
  93. ephemerides.get_ephemerides(Position(0, 0), date(1789, 5, 5))
  94. def test_get_moon_phase_raises_exception_on_out_of_date_range(self):
  95. with self.assertRaises(OutOfRangeDateError):
  96. ephemerides.get_moon_phase(date(1789, 5, 5))
  97. if __name__ == "__main__":
  98. unittest.main()