Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

194 lignes
5.4 KiB

  1. #!/usr/bin/env python3
  2. from .utils import (
  3. execute,
  4. KOSMORRO,
  5. )
  6. import tempfile
  7. from os import path, environ
  8. from sys import platform
  9. def test_json_output():
  10. result = execute(
  11. KOSMORRO + ["--position=50.5876,3.0624", "-d2020-01-27", "--format=json"]
  12. )
  13. assert result.is_successful()
  14. assert (
  15. result.stdout
  16. == """{
  17. "ephemerides": [
  18. {
  19. "object": {
  20. "identifier": "SUN",
  21. "type": "STAR",
  22. "radius": 696342
  23. },
  24. "rise_time": "2020-01-27T07:31:00",
  25. "culmination_time": "2020-01-27T12:01:00",
  26. "set_time": "2020-01-27T16:30:00"
  27. },
  28. {
  29. "object": {
  30. "identifier": "MOON",
  31. "type": "SATELLITE",
  32. "radius": 1737.4
  33. },
  34. "rise_time": "2020-01-27T09:06:00",
  35. "culmination_time": "2020-01-27T14:09:00",
  36. "set_time": "2020-01-27T19:13:00"
  37. },
  38. {
  39. "object": {
  40. "identifier": "MERCURY",
  41. "type": "PLANET",
  42. "radius": 2439.7
  43. },
  44. "rise_time": "2020-01-27T08:10:00",
  45. "culmination_time": "2020-01-27T12:49:00",
  46. "set_time": "2020-01-27T17:28:00"
  47. },
  48. {
  49. "object": {
  50. "identifier": "VENUS",
  51. "type": "PLANET",
  52. "radius": 6051.8
  53. },
  54. "rise_time": "2020-01-27T09:01:00",
  55. "culmination_time": "2020-01-27T14:35:00",
  56. "set_time": "2020-01-27T20:10:00"
  57. },
  58. {
  59. "object": {
  60. "identifier": "MARS",
  61. "type": "PLANET",
  62. "radius": 3396.2
  63. },
  64. "rise_time": "2020-01-27T04:19:00",
  65. "culmination_time": "2020-01-27T08:23:00",
  66. "set_time": "2020-01-27T12:28:00"
  67. },
  68. {
  69. "object": {
  70. "identifier": "JUPITER",
  71. "type": "PLANET",
  72. "radius": 71492
  73. },
  74. "rise_time": "2020-01-27T06:15:00",
  75. "culmination_time": "2020-01-27T10:18:00",
  76. "set_time": "2020-01-27T14:21:00"
  77. },
  78. {
  79. "object": {
  80. "identifier": "SATURN",
  81. "type": "PLANET",
  82. "radius": 60268
  83. },
  84. "rise_time": "2020-01-27T06:56:00",
  85. "culmination_time": "2020-01-27T11:09:00",
  86. "set_time": "2020-01-27T15:22:00"
  87. },
  88. {
  89. "object": {
  90. "identifier": "URANUS",
  91. "type": "PLANET",
  92. "radius": 25559
  93. },
  94. "rise_time": "2020-01-27T10:21:00",
  95. "culmination_time": "2020-01-27T17:25:00",
  96. "set_time": "2020-01-27T00:33:00"
  97. },
  98. {
  99. "object": {
  100. "identifier": "NEPTUNE",
  101. "type": "PLANET",
  102. "radius": 24764
  103. },
  104. "rise_time": "2020-01-27T09:01:00",
  105. "culmination_time": "2020-01-27T14:36:00",
  106. "set_time": "2020-01-27T20:10:00"
  107. },
  108. {
  109. "object": {
  110. "identifier": "PLUTO",
  111. "type": "PLANET",
  112. "radius": 1185
  113. },
  114. "rise_time": "2020-01-27T06:57:00",
  115. "culmination_time": "2020-01-27T11:04:00",
  116. "set_time": "2020-01-27T15:11:00"
  117. }
  118. ],
  119. "moon_phase": {
  120. "phase": "NEW_MOON",
  121. "time": "2020-01-24T21:41:59.705921+00:00",
  122. "next": {
  123. "phase": "FIRST_QUARTER",
  124. "time": "2020-02-02T01:41:40.282275+00:00"
  125. }
  126. },
  127. "events": [
  128. {
  129. "objects": [
  130. {
  131. "identifier": "VENUS",
  132. "type": "PLANET",
  133. "radius": 6051.8
  134. },
  135. {
  136. "identifier": "NEPTUNE",
  137. "type": "PLANET",
  138. "radius": 24764
  139. }
  140. ],
  141. "EventType": "CONJUNCTION",
  142. "starts_at": "2020-01-27T20:00:23.242750+00:00",
  143. "ends_at": null,
  144. "details": null
  145. }
  146. ]
  147. }
  148. """
  149. )
  150. def test_pdf_output():
  151. if platform != "linux":
  152. # Consider it works everywhere if it does at least on Linux
  153. return
  154. tmp_dir = tempfile.mkdtemp()
  155. result = execute(
  156. KOSMORRO
  157. + [
  158. "--position=50.5876,3.0624",
  159. "-d2020-01-27",
  160. "--format=pdf",
  161. f"--output={tmp_dir}/document.pdf",
  162. ]
  163. )
  164. if environ.get("TEXLIVE_INSTALLED") is None:
  165. assert not result.is_successful()
  166. assert (
  167. result.stdout
  168. == """Save the planet and paper!
  169. Consider printing your PDF document only if really necessary, and use the other side of the sheet.
  170. Building PDF was not possible, because some dependencies are not installed.
  171. Please look at the documentation at https://kosmorro.space/cli/generate-pdf/ for more information.
  172. """
  173. )
  174. return
  175. assert result.is_successful()
  176. assert (
  177. result.stdout
  178. == """Save the planet and paper!
  179. Consider printing your PDF document only if really necessary, and use the other side of the sheet.
  180. """
  181. ""
  182. )
  183. assert path.exists(f"{tmp_dir}/document.pdf")