You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

87 line
4.2 KiB

  1. import unittest
  2. from kosmorrolib.ephemerides import EphemeridesComputer
  3. from kosmorrolib.core import get_skf_objects
  4. from kosmorrolib.data import Star, Position
  5. from datetime import date
  6. class EphemeridesComputerTestCase(unittest.TestCase):
  7. def test_get_ephemerides_for_aster_returns_correct_hours(self):
  8. position = Position(0, 0)
  9. position.observation_planet = get_skf_objects()['earth']
  10. star = EphemeridesComputer.get_asters_ephemerides_for_aster(Star('Sun', skyfield_name='sun'),
  11. date=date(2019, 11, 18),
  12. position=position)
  13. self.assertEqual('2019-11-18T05:41:31Z', star.ephemerides.rise_time.utc_iso())
  14. self.assertEqual('2019-11-18T11:45:02Z', star.ephemerides.culmination_time.utc_iso())
  15. self.assertEqual('2019-11-18T17:48:39Z', star.ephemerides.set_time.utc_iso())
  16. ###################################################################################################################
  17. ### MOON PHASE TESTS ###
  18. ###################################################################################################################
  19. def test_moon_phase_new_moon(self):
  20. phase = EphemeridesComputer.get_moon_phase(2019, 11, 25)
  21. self.assertEqual('WANING_CRESCENT', phase.identifier)
  22. self.assertIsNone(phase.time)
  23. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-26T')
  24. phase = EphemeridesComputer.get_moon_phase(2019, 11, 26)
  25. self.assertEqual('NEW_MOON', phase.identifier)
  26. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-12-04T')
  27. phase = EphemeridesComputer.get_moon_phase(2019, 11, 27)
  28. self.assertEqual('WAXING_CRESCENT', phase.identifier)
  29. self.assertIsNone(phase.time)
  30. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-12-04T')
  31. def test_moon_phase_first_crescent(self):
  32. phase = EphemeridesComputer.get_moon_phase(2019, 11, 3)
  33. self.assertEqual('WAXING_CRESCENT', phase.identifier)
  34. self.assertIsNone(phase.time)
  35. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-04T')
  36. phase = EphemeridesComputer.get_moon_phase(2019, 11, 4)
  37. self.assertEqual('FIRST_QUARTER', phase.identifier)
  38. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-12T')
  39. phase = EphemeridesComputer.get_moon_phase(2019, 11, 5)
  40. self.assertEqual('WAXING_GIBBOUS', phase.identifier)
  41. self.assertIsNone(phase.time)
  42. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-12T')
  43. def test_moon_phase_full_moon(self):
  44. phase = EphemeridesComputer.get_moon_phase(2019, 11, 11)
  45. self.assertEqual('WAXING_GIBBOUS', phase.identifier)
  46. self.assertIsNone(phase.time)
  47. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-12T')
  48. phase = EphemeridesComputer.get_moon_phase(2019, 11, 12)
  49. self.assertEqual('FULL_MOON', phase.identifier)
  50. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-19T')
  51. phase = EphemeridesComputer.get_moon_phase(2019, 11, 13)
  52. self.assertEqual('WANING_GIBBOUS', phase.identifier)
  53. self.assertIsNone(phase.time)
  54. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-19T')
  55. def test_moon_phase_last_quarter(self):
  56. phase = EphemeridesComputer.get_moon_phase(2019, 11, 18)
  57. self.assertEqual('WANING_GIBBOUS', phase.identifier)
  58. self.assertIsNone(phase.time)
  59. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-19T')
  60. phase = EphemeridesComputer.get_moon_phase(2019, 11, 19)
  61. self.assertEqual('LAST_QUARTER', phase.identifier)
  62. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-26T')
  63. phase = EphemeridesComputer.get_moon_phase(2019, 11, 20)
  64. self.assertEqual('WANING_CRESCENT', phase.identifier)
  65. self.assertIsNone(phase.time)
  66. self.assertRegexpMatches(phase.next_phase_date.utc_iso(), '^2019-11-26T')
  67. if __name__ == '__main__':
  68. unittest.main()