You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

84 lines
3.2 KiB

  1. #!/usr/bin/env python3
  2. from sys import version_info as python_version
  3. from .test_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. # Options header has changed from "optional arguments" to "options" in Python 3.10.
  30. options_header = (
  31. "optional arguments" if python_version.minor < 10 else "options"
  32. )
  33. assert (
  34. result.stdout
  35. == """usage: kosmorro [-h] [--version] [--format {txt,json,tex}]
  36. [--position POSITION] [--date DATE] [--timezone TIMEZONE]
  37. [--no-colors] [--output OUTPUT] [--no-graph] [--debug]
  38. Compute the ephemerides and the events for a given date and a given position
  39. on Earth.
  40. %s:
  41. -h, --help show this help message and exit
  42. --version, -v Show the program version
  43. --format {txt,json,tex}, -f {txt,json,tex}
  44. The format to output the information to. If not
  45. provided, the output format will be inferred from the
  46. file extension of the output file.
  47. --position POSITION, -p POSITION
  48. The observer's position on Earth, in the
  49. "{latitude},{longitude}" format. Can also be set in
  50. the KOSMORRO_POSITION environment variable.
  51. --date DATE, -d DATE The date for which the ephemerides must be calculated.
  52. Can be in the YYYY-MM-DD format or an interval in the
  53. "[+-]YyMmDd" format (with Y, M, and D numbers).
  54. Defaults to current date.
  55. --timezone TIMEZONE, -t TIMEZONE
  56. The timezone to display the hours in (e.g. 2 for UTC+2
  57. or -3 for UTC-3). Can also be set in the
  58. KOSMORRO_TIMEZONE 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.
  63. --no-graph Do not generate a graph to represent the rise and set
  64. times in the LaTeX file.
  65. --debug Show debugging messages
  66. By default, only the events will be computed for today. To compute also the
  67. ephemerides, latitude and longitude arguments are needed.
  68. """
  69. % options_header
  70. )