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.
 
 
 
 

216 lignes
6.0 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_tex_output():
  151. tmpdir = tempfile.mkdtemp()
  152. i = 1
  153. for args in [["--format=tex"], []]:
  154. args.append(f"--output={tmpdir}/document_{i}.tex")
  155. result = execute(
  156. KOSMORRO + ["--position=50.5876,3.0624", "--date=2020-01-27"] + args
  157. )
  158. assert result.is_successful()
  159. assert result.stdout == ""
  160. assert result.stderr == ""
  161. assert path.exists(f"{tmpdir}/document_{i}.tex")
  162. i += 1
  163. def test_pdf_output():
  164. if platform != "linux":
  165. # Consider it works everywhere if it does at least on Linux
  166. return
  167. tmp_dir = tempfile.mkdtemp()
  168. result = execute(
  169. KOSMORRO
  170. + [
  171. "--position=50.5876,3.0624",
  172. "-d2020-01-27",
  173. "--format=pdf",
  174. f"--output={tmp_dir}/document.pdf",
  175. ]
  176. )
  177. if environ.get("TEXLIVE_INSTALLED") is None:
  178. assert not result.is_successful()
  179. assert (
  180. result.stdout
  181. == "Save the planet and paper!\nConsider printing your PDF document only if really necessary, and use the other side of the sheet.\n"
  182. )
  183. assert (
  184. result.stderr
  185. == "Building PDF was not possible, because some dependencies are not installed.\nPlease look at the documentation at https://kosmorro.space/cli/generate-pdf/ for more information.\n"
  186. )
  187. # return
  188. #
  189. # disabled for now, waiting for the new pdf generator
  190. #
  191. # assert result.is_successful()
  192. # assert (
  193. # result.stdout
  194. # == """Save the planet and paper!
  195. # Consider printing your PDF document only if really necessary, and use the other side of the sheet.
  196. # """
  197. # ""
  198. # )
  199. #
  200. # assert path.exists(f"{tmp_dir}/document.pdf")