No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

88 líneas
3.4 KiB

  1. #!/usr/bin/env python3
  2. from sys import version_info
  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")
  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. python_version = (version_info.major, version_info.minor)
  27. for arg in ["--help", "-h"]:
  28. result = execute(KOSMORRO + [arg])
  29. assert result.is_successful()
  30. # Options header has changed from "optional arguments" to "options" in Python 3.10.
  31. options_header = (
  32. "options" if python_version == (3, 10) else "optional arguments"
  33. )
  34. assert (
  35. result.stdout
  36. == """usage: kosmorro [-h] [--version] [--format {text,json,pdf}]
  37. [--latitude LATITUDE] [--longitude LONGITUDE] [--date DATE]
  38. [--timezone TIMEZONE] [--no-colors] [--output OUTPUT]
  39. [--no-graph] [--debug]
  40. Compute the ephemerides and the events for a given date and a given position
  41. on Earth.
  42. %s:
  43. -h, --help show this help message and exit
  44. --version, -v Show the program version
  45. --format {text,json,pdf}, -f {text,json,pdf}
  46. The format to output the information to
  47. --latitude LATITUDE, -lat LATITUDE
  48. The observer's latitude on Earth. Can also be set in
  49. the KOSMORRO_LATITUDE environment variable.
  50. --longitude LONGITUDE, -lon LONGITUDE
  51. The observer's longitude on Earth. Can also be set in
  52. the KOSMORRO_LONGITUDE environment variable.
  53. --date DATE, -d DATE The date for which the ephemerides must be calculated.
  54. Can be in the YYYY-MM-DD format or an interval in the
  55. "[+-]YyMmDd" format (with Y, M, and D numbers).
  56. Defaults to current date.
  57. --timezone TIMEZONE, -t TIMEZONE
  58. The timezone to display the hours in (e.g. 2 for UTC+2
  59. or -3 for UTC-3). Can also be set in the
  60. KOSMORRO_TIMEZONE environment variable.
  61. --no-colors Disable the colors in the console.
  62. --output OUTPUT, -o OUTPUT
  63. A file to export the output to. If not given, the
  64. standard output is used. This argument is needed for
  65. PDF format.
  66. --no-graph Do not generate a graph to represent the rise and set
  67. times in the PDF format.
  68. --debug Show debugging messages
  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. % options_header
  73. )