Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

125 строки
6.0 KiB

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