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