25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

ephemerides.py 5.3 KiB

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