177 lines
4.9 KiB

  1. #!/usr/bin/env python3
  2. from importlib.metadata import version
  3. from .utils import (
  4. execute,
  5. KOSMORRO,
  6. )
  7. from os import path
  8. def test_json_output():
  9. result = execute(
  10. KOSMORRO + ["--position=50.5876,3.0624", "-d2020-01-27", "--format=json"]
  11. )
  12. assert result.is_successful()
  13. assert (
  14. result.stdout
  15. == """{
  16. "ephemerides": [
  17. {
  18. "object": {
  19. "identifier": "SUN",
  20. "type": "STAR",
  21. "radius": 696342
  22. },
  23. "rise_time": "2020-01-27T07:31:00",
  24. "culmination_time": "2020-01-27T12:01:00",
  25. "set_time": "2020-01-27T16:30:00"
  26. },
  27. {
  28. "object": {
  29. "identifier": "MOON",
  30. "type": "SATELLITE",
  31. "radius": 1737.4
  32. },
  33. "rise_time": "2020-01-27T09:06:00",
  34. "culmination_time": "2020-01-27T14:09:00",
  35. "set_time": "2020-01-27T19:13:00"
  36. },
  37. {
  38. "object": {
  39. "identifier": "MERCURY",
  40. "type": "PLANET",
  41. "radius": 2439.7
  42. },
  43. "rise_time": "2020-01-27T08:10:00",
  44. "culmination_time": "2020-01-27T12:49:00",
  45. "set_time": "2020-01-27T17:28:00"
  46. },
  47. {
  48. "object": {
  49. "identifier": "VENUS",
  50. "type": "PLANET",
  51. "radius": 6051.8
  52. },
  53. "rise_time": "2020-01-27T09:01:00",
  54. "culmination_time": "2020-01-27T14:35:00",
  55. "set_time": "2020-01-27T20:10:00"
  56. },
  57. {
  58. "object": {
  59. "identifier": "MARS",
  60. "type": "PLANET",
  61. "radius": 3396.2
  62. },
  63. "rise_time": "2020-01-27T04:19:00",
  64. "culmination_time": "2020-01-27T08:23:00",
  65. "set_time": "2020-01-27T12:28:00"
  66. },
  67. {
  68. "object": {
  69. "identifier": "JUPITER",
  70. "type": "PLANET",
  71. "radius": 71492
  72. },
  73. "rise_time": "2020-01-27T06:15:00",
  74. "culmination_time": "2020-01-27T10:18:00",
  75. "set_time": "2020-01-27T14:21:00"
  76. },
  77. {
  78. "object": {
  79. "identifier": "SATURN",
  80. "type": "PLANET",
  81. "radius": 60268
  82. },
  83. "rise_time": "2020-01-27T06:56:00",
  84. "culmination_time": "2020-01-27T11:09:00",
  85. "set_time": "2020-01-27T15:22:00"
  86. },
  87. {
  88. "object": {
  89. "identifier": "URANUS",
  90. "type": "PLANET",
  91. "radius": 25559
  92. },
  93. "rise_time": "2020-01-27T10:21:00",
  94. "culmination_time": "2020-01-27T17:25:00",
  95. "set_time": "2020-01-27T00:33:00"
  96. },
  97. {
  98. "object": {
  99. "identifier": "NEPTUNE",
  100. "type": "PLANET",
  101. "radius": 24764
  102. },
  103. "rise_time": "2020-01-27T09:01:00",
  104. "culmination_time": "2020-01-27T14:36:00",
  105. "set_time": "2020-01-27T20:10:00"
  106. },
  107. {
  108. "object": {
  109. "identifier": "PLUTO",
  110. "type": "PLANET",
  111. "radius": 1185
  112. },
  113. "rise_time": "2020-01-27T06:57:00",
  114. "culmination_time": "2020-01-27T11:04:00",
  115. "set_time": "2020-01-27T15:11:00"
  116. }
  117. ],
  118. "moon_phase": {
  119. "phase": "NEW_MOON",
  120. "time": "2020-01-24T21:41:59.705921+00:00",
  121. "next": {
  122. "phase": "FIRST_QUARTER",
  123. "time": "2020-02-02T01:41:40.282275+00:00"
  124. }
  125. },
  126. "events": [
  127. {
  128. "objects": [
  129. {
  130. "identifier": "VENUS",
  131. "type": "PLANET",
  132. "radius": 6051.8
  133. },
  134. {
  135. "identifier": "NEPTUNE",
  136. "type": "PLANET",
  137. "radius": 24764
  138. }
  139. ],
  140. "EventType": "CONJUNCTION",
  141. "starts_at": "2020-01-27T20:00:23.242750+00:00",
  142. "ends_at": null,
  143. "details": null
  144. }
  145. ]
  146. }
  147. """
  148. )
  149. def test_latex_output():
  150. result = execute(
  151. KOSMORRO + ["--position=50.5876,3.0624", "-d2020-01-27", "--format=tex"]
  152. )
  153. assert result.successful
  154. with open(
  155. path.join(path.dirname(__file__), "outputs", "2020-01-27-with-position.tex")
  156. ) as expected_output:
  157. expected_output = (
  158. expected_output.read()
  159. .replace(
  160. "__PROJECT_PATH__",
  161. path.join(path.dirname(path.dirname(__file__)), "kosmorro"),
  162. )
  163. .replace(
  164. "__APP_VERSION__",
  165. version("kosmorro"),
  166. )
  167. )
  168. assert result.stdout == expected_output