Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import unittest
  2. from datetime import date
  3. from kosmorrolib.data import AsterEphemerides, Planet, MoonPhase, Event
  4. from kosmorrolib.dumper import JsonDumper, TextDumper
  5. from kosmorrolib.core import get_timescale
  6. class DumperTestCase(unittest.TestCase):
  7. def setUp(self) -> None:
  8. self.maxDiff = None
  9. def test_json_dumper_returns_correct_json(self):
  10. data = self._get_data()
  11. self.assertEqual('{\n'
  12. ' "moon_phase": {\n'
  13. ' "next_phase_date": "2019-10-21T00:00:00Z",\n'
  14. ' "phase": "FULL_MOON",\n'
  15. ' "date": "2019-10-14T00:00:00Z"\n'
  16. ' },\n'
  17. ' "events": [\n'
  18. ' {\n'
  19. ' "event_type": "OPPOSITION",\n'
  20. ' "objects": [\n'
  21. ' "Mars"\n'
  22. ' ],\n'
  23. ' "start_time": "2018-07-27T05:12:00Z",\n'
  24. ' "end_time": null\n'
  25. ' }\n'
  26. ' ],\n'
  27. ' "ephemerides": [\n'
  28. ' {\n'
  29. ' "object": "Mars",\n'
  30. ' "details": {\n'
  31. ' "rise_time": null,\n'
  32. ' "culmination_time": null,\n'
  33. ' "set_time": null\n'
  34. ' }\n'
  35. ' }\n'
  36. ' ]\n'
  37. '}', JsonDumper(data,
  38. [Event('OPPOSITION', [Planet('Mars', 'MARS')],
  39. get_timescale().utc(2018, 7, 27, 5, 12))]
  40. ).to_string())
  41. def test_text_dumper_without_events(self):
  42. ephemerides = self._get_data()
  43. self.assertEqual('Monday October 14, 2019\n\n'
  44. 'Object Rise time Culmination time Set time\n'
  45. '-------- ----------- ------------------ ----------\n'
  46. 'Mars - - -\n\n'
  47. 'Moon phase: Full Moon\n'
  48. 'Last Quarter on Monday October 21, 2019 at 00:00\n\n'
  49. 'Note: All the hours are given in UTC.',
  50. TextDumper(ephemerides, [], date=date(2019, 10, 14)).to_string())
  51. def test_text_dumper_with_events(self):
  52. ephemerides = self._get_data()
  53. self.assertEqual('Monday October 14, 2019\n\n'
  54. 'Object Rise time Culmination time Set time\n'
  55. '-------- ----------- ------------------ ----------\n'
  56. 'Mars - - -\n\n'
  57. 'Moon phase: Full Moon\n'
  58. 'Last Quarter on Monday October 21, 2019 at 00:00\n\n'
  59. 'Expected events:\n\n'
  60. '05:12 Mars is in opposition\n\n'
  61. 'Note: All the hours are given in UTC.',
  62. TextDumper(ephemerides, [Event('OPPOSITION',
  63. [Planet('Mars', 'MARS')],
  64. get_timescale().utc(2018, 7, 27, 5, 12))
  65. ], date=date(2019, 10, 14)).to_string())
  66. def test_text_dumper_without_ephemerides_and_with_events(self):
  67. ephemerides = self._get_data(False)
  68. self.assertEqual('Monday October 14, 2019\n\n'
  69. 'Moon phase: Full Moon\n'
  70. 'Last Quarter on Monday October 21, 2019 at 00:00\n\n'
  71. 'Expected events:\n\n'
  72. '05:12 Mars is in opposition\n\n'
  73. 'Note: All the hours are given in UTC.',
  74. TextDumper(ephemerides, [Event('OPPOSITION',
  75. [Planet('Mars', 'MARS')],
  76. get_timescale().utc(2018, 7, 27, 5, 12))
  77. ], date=date(2019, 10, 14)).to_string())
  78. @staticmethod
  79. def _get_data(has_ephemerides: bool = True):
  80. return {
  81. 'moon_phase': MoonPhase('FULL_MOON', get_timescale().utc(2019, 10, 14), get_timescale().utc(2019, 10, 21)),
  82. 'details': [Planet('Mars', 'MARS', AsterEphemerides(None, None, None))] if has_ephemerides else []
  83. }
  84. if __name__ == '__main__':
  85. unittest.main()