Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

134 linhas
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.is_successful()
  29. assert result.successful
  30. if python_version.major == 3 and python_version.minor < 13:
  31. assert (
  32. result.stdout
  33. == """usage: kosmorro [-h] [--version] [--format {txt,json,pdf,tex}]
  34. [--position POSITION] [--date DATE] [--timezone TIMEZONE]
  35. [--no-colors] [--output OUTPUT] [--no-graph] [--debug]
  36. [--completion COMPLETION]
  37. Compute the ephemerides and the events for a given date and a given position
  38. on Earth.
  39. options:
  40. -h, --help show this help message and exit
  41. --version, -v Show the program version
  42. --format {txt,json,pdf,tex}, -f {txt,json,pdf,tex}
  43. The format to output the information to. If not
  44. provided, the output format will be inferred from the
  45. file extension of the output file.
  46. --position POSITION, -p POSITION
  47. The observer's position on Earth, in the
  48. "{latitude},{longitude}" format. Can also be set in
  49. the KOSMORRO_POSITION environment variable.
  50. --date DATE, -d DATE The date for which the ephemerides must be calculated.
  51. Can be in the YYYY-MM-DD format or an interval in the
  52. "[+-]YyMmDd" format (with Y, M, and D numbers).
  53. Defaults to current date.
  54. --timezone TIMEZONE, -t TIMEZONE
  55. The timezone to use to display the hours. It can be
  56. either a number (e.g. 1 for UTC+1) or a timezone name
  57. (e.g. Europe/Paris). See https://en.wikipedia.org/wiki
  58. /List_of_tz_database_time_zones to find your timezone.
  59. Can also be set in the TZ environment variable.
  60. --no-colors Disable the colors in the console.
  61. --output OUTPUT, -o OUTPUT
  62. A file to export the output to. If not given, the
  63. standard output is used. This argument is needed for
  64. PDF format.
  65. --no-graph Do not generate a graph to represent the rise and set
  66. times in the LaTeX or PDF file.
  67. --debug Show debugging messages
  68. --completion COMPLETION
  69. Print a script allowing completion for your shell
  70. By default, only the events will be computed for today. To compute also the
  71. ephemerides, latitude and longitude arguments are needed.
  72. """
  73. )
  74. else:
  75. assert (
  76. result.stdout
  77. == """usage: kosmorro [-h] [--version] [--format {txt,json,pdf,tex}]
  78. [--position POSITION] [--date DATE] [--timezone TIMEZONE]
  79. [--no-colors] [--output OUTPUT] [--no-graph] [--debug]
  80. [--completion COMPLETION]
  81. Compute the ephemerides and the events for a given date and a given position
  82. on Earth.
  83. options:
  84. -h, --help show this help message and exit
  85. --version, -v Show the program version
  86. --format, -f {txt,json,pdf,tex}
  87. The format to output the information to. If not
  88. provided, the output format will be inferred from the
  89. file extension of the output file.
  90. --position, -p POSITION
  91. The observer's position on Earth, in the
  92. "{latitude},{longitude}" format. Can also be set in
  93. the KOSMORRO_POSITION environment variable.
  94. --date, -d DATE The date for which the ephemerides must be calculated.
  95. Can be in the YYYY-MM-DD format or an interval in the
  96. "[+-]YyMmDd" format (with Y, M, and D numbers).
  97. Defaults to current date.
  98. --timezone, -t TIMEZONE
  99. The timezone to use to display the hours. It can be
  100. either a number (e.g. 1 for UTC+1) or a timezone name
  101. (e.g. Europe/Paris). See https://en.wikipedia.org/wiki
  102. /List_of_tz_database_time_zones to find your timezone.
  103. Can also be set in the TZ environment variable.
  104. --no-colors Disable the colors in the console.
  105. --output, -o OUTPUT A file to export the output to. If not given, the
  106. standard output is used. This argument is needed for
  107. PDF format.
  108. --no-graph Do not generate a graph to represent the rise and set
  109. times in the LaTeX or PDF file.
  110. --debug Show debugging messages
  111. --completion COMPLETION
  112. Print a script allowing completion for your shell
  113. By default, only the events will be computed for today. To compute also the
  114. ephemerides, latitude and longitude arguments are needed.
  115. """
  116. )