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.

general.py 3.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # 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 {text,json,pdf}]
  36. [--latitude LATITUDE] [--longitude LONGITUDE] [--date DATE]
  37. [--timezone TIMEZONE] [--no-colors] [--output OUTPUT]
  38. [--no-graph] [--debug]
  39. Compute the ephemerides and the events for a given date and a given position
  40. on Earth.
  41. %s:
  42. -h, --help show this help message and exit
  43. --version, -v Show the program version
  44. --format {text,json,pdf}, -f {text,json,pdf}
  45. The format to output the information to
  46. --latitude LATITUDE, -lat LATITUDE
  47. The observer's latitude on Earth. Can also be set in
  48. the KOSMORRO_LATITUDE environment variable.
  49. --longitude LONGITUDE, -lon LONGITUDE
  50. The observer's longitude on Earth. Can also be set in
  51. the KOSMORRO_LONGITUDE environment variable.
  52. --date DATE, -d DATE The date for which the ephemerides must be calculated.
  53. Can be in the YYYY-MM-DD format or an interval in the
  54. "[+-]YyMmDd" format (with Y, M, and D numbers).
  55. Defaults to current date.
  56. --timezone TIMEZONE, -t TIMEZONE
  57. The timezone to display the hours in (e.g. 2 for UTC+2
  58. or -3 for UTC-3). Can also be set in the
  59. KOSMORRO_TIMEZONE 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 PDF format.
  67. --debug Show debugging messages
  68. By default, only the events will be computed for today. To compute also the
  69. ephemerides, latitude and longitude arguments are needed.
  70. """
  71. % options_header
  72. )