Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

122 řádky
5.7 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 datetime import date
  6. from kosmorrolib.exceptions import OutOfRangeDateError
  7. class EphemeridesTestCase(unittest.TestCase):
  8. def test_get_ephemerides_for_aster_returns_correct_hours(self):
  9. position = Position(0, 0, EARTH)
  10. eph = ephemerides.get_ephemerides(date=date(2019, 11, 18),
  11. 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(ephemeris.culmination_time.isoformat(), '^2019-11-18T11:45:')
  18. assert_regex(ephemeris.set_time.isoformat(), '^2019-11-18T17:48:')
  19. break
  20. do_assertions()
  21. ###################################################################################################################
  22. ### MOON PHASE TESTS ###
  23. ###################################################################################################################
  24. def test_moon_phase_new_moon(self):
  25. phase = ephemerides.get_moon_phase(date(2019, 11, 25))
  26. self.assertEqual('WANING_CRESCENT', phase.identifier)
  27. self.assertIsNone(phase.time)
  28. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-26T')
  29. phase = ephemerides.get_moon_phase(date(2019, 11, 26))
  30. self.assertEqual('NEW_MOON', phase.identifier)
  31. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-12-04T')
  32. phase = ephemerides.get_moon_phase(date(2019, 11, 27))
  33. self.assertEqual('WAXING_CRESCENT', phase.identifier)
  34. self.assertIsNone(phase.time)
  35. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-12-04T')
  36. def test_moon_phase_first_crescent(self):
  37. phase = ephemerides.get_moon_phase(date(2019, 11, 3))
  38. self.assertEqual('WAXING_CRESCENT', phase.identifier)
  39. self.assertIsNone(phase.time)
  40. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-04T')
  41. phase = ephemerides.get_moon_phase(date(2019, 11, 4))
  42. self.assertEqual('FIRST_QUARTER', phase.identifier)
  43. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-12T')
  44. phase = ephemerides.get_moon_phase(date(2019, 11, 5))
  45. self.assertEqual('WAXING_GIBBOUS', phase.identifier)
  46. self.assertIsNone(phase.time)
  47. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-12T')
  48. def test_moon_phase_full_moon(self):
  49. phase = ephemerides.get_moon_phase(date(2019, 11, 11))
  50. self.assertEqual('WAXING_GIBBOUS', phase.identifier)
  51. self.assertIsNone(phase.time)
  52. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-12T')
  53. phase = ephemerides.get_moon_phase(date(2019, 11, 12))
  54. self.assertEqual('FULL_MOON', phase.identifier)
  55. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-19T')
  56. phase = ephemerides.get_moon_phase(date(2019, 11, 13))
  57. self.assertEqual('WANING_GIBBOUS', phase.identifier)
  58. self.assertIsNone(phase.time)
  59. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-19T')
  60. def test_moon_phase_last_quarter(self):
  61. phase = ephemerides.get_moon_phase(date(2019, 11, 18))
  62. self.assertEqual('WANING_GIBBOUS', phase.identifier)
  63. self.assertIsNone(phase.time)
  64. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-19T')
  65. phase = ephemerides.get_moon_phase(date(2019, 11, 19))
  66. self.assertEqual('LAST_QUARTER', phase.identifier)
  67. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-26T')
  68. phase = ephemerides.get_moon_phase(date(2019, 11, 20))
  69. self.assertEqual('WANING_CRESCENT', phase.identifier)
  70. self.assertIsNone(phase.time)
  71. self.assertRegexpMatches(phase.next_phase_date.isoformat(), '^2019-11-26T')
  72. def test_moon_phase_prediction(self):
  73. phase = MoonPhase('NEW_MOON', None, None)
  74. self.assertEqual('First Quarter', phase.get_next_phase_name())
  75. phase = MoonPhase('WAXING_CRESCENT', None, None)
  76. self.assertEqual('First Quarter', phase.get_next_phase_name())
  77. phase = MoonPhase('FIRST_QUARTER', None, None)
  78. self.assertEqual('Full Moon', phase.get_next_phase_name())
  79. phase = MoonPhase('WAXING_GIBBOUS', None, None)
  80. self.assertEqual('Full Moon', phase.get_next_phase_name())
  81. phase = MoonPhase('FULL_MOON', None, None)
  82. self.assertEqual('Last Quarter', phase.get_next_phase_name())
  83. phase = MoonPhase('WANING_GIBBOUS', None, None)
  84. self.assertEqual('Last Quarter', phase.get_next_phase_name())
  85. phase = MoonPhase('LAST_QUARTER', None, None)
  86. self.assertEqual('New Moon', phase.get_next_phase_name())
  87. phase = MoonPhase('WANING_CRESCENT', None, None)
  88. self.assertEqual('New Moon', phase.get_next_phase_name())
  89. def test_get_ephemerides_raises_exception_on_out_of_date_range(self):
  90. with self.assertRaises(OutOfRangeDateError):
  91. ephemerides.get_ephemerides(date(1789, 5, 5), Position(0, 0, EARTH))
  92. def test_get_moon_phase_raises_exception_on_out_of_date_range(self):
  93. with self.assertRaises(OutOfRangeDateError):
  94. ephemerides.get_moon_phase(date(1789, 5, 5))
  95. if __name__ == '__main__':
  96. unittest.main()