選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

132 行
5.8 KiB

  1. #!/usr/bin/env python3
  2. from sys import version_info as python_version
  3. from .utils import (
  4. execute,
  5. KOSMORRO,
  6. CURRENT_MOON_PHASE_PATTERN,
  7. NEXT_MOON_PHASE_PATTERN,
  8. )
  9. from datetime import date
  10. from babel.dates import format_date
  11. def test_run_without_argument():
  12. result = execute(KOSMORRO)
  13. assert result.successful
  14. stdout = result.stdout.split("\n")
  15. print(stdout)
  16. # It always starts with the current date, an empty line and the current and next Moon date:
  17. assert stdout[0] == format_date(date.today(), "full", "EN")
  18. assert stdout[1] == ""
  19. assert CURRENT_MOON_PHASE_PATTERN.match(stdout[2])
  20. assert NEXT_MOON_PHASE_PATTERN.match(stdout[3])
  21. # It always finishes with an empty line, a note about UTC timezone and an empty line:
  22. assert stdout[-3] == ""
  23. assert stdout[-2] == "Note: All the hours are given in UTC."
  24. assert stdout[-1] == ""
  25. def test_help_message():
  26. for arg in ["--help", "-h"]:
  27. result = execute(KOSMORRO + [arg])
  28. assert result.successful
  29. if python_version.major == 3 and python_version.minor < 13:
  30. assert (
  31. result.stdout
  32. == """usage: kosmorro [-h] [--version] [--format {txt,json,pdf,tex}]
  33. [--position POSITION] [--date DATE] [--timezone TIMEZONE]
  34. [--no-colors] [--output OUTPUT] [--no-graph] [--debug]
  35. [--completion COMPLETION]
  36. Compute the ephemerides and the events for a given date and a given position
  37. on Earth.
  38. options:
  39. -h, --help show this help message and exit
  40. --version, -v Show the program version
  41. --format {txt,json,pdf,tex}, -f {txt,json,pdf,tex}
  42. The format to output the information to. If not
  43. provided, the output format will be inferred from the
  44. file extension of the output file.
  45. --position POSITION, -p POSITION
  46. The observer's position on Earth, in the
  47. "{latitude},{longitude}" format. Can also be set in
  48. the KOSMORRO_POSITION environment variable.
  49. --date DATE, -d DATE The date for which the ephemerides must be calculated.
  50. Can be in the YYYY-MM-DD format or an interval in the
  51. "[+-]YyMmDd" format (with Y, M, and D numbers).
  52. Defaults to current date.
  53. --timezone TIMEZONE, -t TIMEZONE
  54. The timezone to use to display the hours. It can be
  55. either a number (e.g. 1 for UTC+1) or a timezone name
  56. (e.g. Europe/Paris). See https://en.wikipedia.org/wiki
  57. /List_of_tz_database_time_zones to find your timezone.
  58. Can also be set in the TZ environment variable.
  59. --no-colors Disable the colors in the console.
  60. --output OUTPUT, -o OUTPUT
  61. A file to export the output to. If not given, the
  62. standard output is used. This argument is needed for
  63. PDF format.
  64. --no-graph Do not generate a graph to represent the rise and set
  65. times in the LaTeX or PDF file.
  66. --debug Show debugging messages
  67. --completion COMPLETION
  68. Print a script allowing completion for your shell
  69. By default, only the events will be computed for today. To compute also the
  70. ephemerides, latitude and longitude arguments are needed.
  71. """
  72. )
  73. else:
  74. assert (
  75. result.stdout
  76. == """usage: kosmorro [-h] [--version] [--format {txt,json,pdf,tex}]
  77. [--position POSITION] [--date DATE] [--timezone TIMEZONE]
  78. [--no-colors] [--output OUTPUT] [--no-graph] [--debug]
  79. [--completion COMPLETION]
  80. Compute the ephemerides and the events for a given date and a given position
  81. on Earth.
  82. options:
  83. -h, --help show this help message and exit
  84. --version, -v Show the program version
  85. --format, -f {txt,json,pdf,tex}
  86. The format to output the information to. If not
  87. provided, the output format will be inferred from the
  88. file extension of the output file.
  89. --position, -p POSITION
  90. The observer's position on Earth, in the
  91. "{latitude},{longitude}" format. Can also be set in
  92. the KOSMORRO_POSITION environment variable.
  93. --date, -d DATE The date for which the ephemerides must be calculated.
  94. Can be in the YYYY-MM-DD format or an interval in the
  95. "[+-]YyMmDd" format (with Y, M, and D numbers).
  96. Defaults to current date.
  97. --timezone, -t TIMEZONE
  98. The timezone to use to display the hours. It can be
  99. either a number (e.g. 1 for UTC+1) or a timezone name
  100. (e.g. Europe/Paris). See https://en.wikipedia.org/wiki
  101. /List_of_tz_database_time_zones to find your timezone.
  102. Can also be set in the TZ environment variable.
  103. --no-colors Disable the colors in the console.
  104. --output, -o OUTPUT A file to export the output to. If not given, the
  105. standard output is used. This argument is needed for
  106. PDF format.
  107. --no-graph Do not generate a graph to represent the rise and set
  108. times in the LaTeX or PDF file.
  109. --debug Show debugging messages
  110. --completion COMPLETION
  111. Print a script allowing completion for your shell
  112. By default, only the events will be computed for today. To compute also the
  113. ephemerides, latitude and longitude arguments are needed.
  114. """
  115. )