您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

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