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.
 
 
 
 

119 line
3.9 KiB

  1. #!/usr/bin/env python3
  2. import pytest
  3. from .utils import (
  4. execute,
  5. KOSMORRO,
  6. )
  7. def timezone_with_command_line_arg_input():
  8. yield [
  9. "--timezone=1",
  10. "-d2020-01-27",
  11. ], "Note: All the hours are given in the UTC+1.0 timezone."
  12. yield [
  13. "--timezone=Europe/Paris",
  14. "-d2020-01-27",
  15. ], "Note: All the hours are given in the UTC+1.0 timezone."
  16. # Paris is at UTC+2 in July:
  17. yield [
  18. "--timezone=Europe/Paris",
  19. "-d2020-07-27",
  20. ], "Note: All the hours are given in the UTC+2.0 timezone."
  21. yield [
  22. "--timezone=-5",
  23. "-d2020-01-27",
  24. ], "Note: All the hours are given in the UTC-5.0 timezone."
  25. yield [
  26. "--timezone=America/Chicago",
  27. "-d2020-01-27",
  28. ], "Note: All the hours are given in the UTC-6.0 timezone."
  29. # Chicago is at UTC+6 in July:
  30. yield [
  31. "--timezone=America/Chicago",
  32. "-d2020-07-27",
  33. ], "Note: All the hours are given in the UTC-5.0 timezone."
  34. @pytest.mark.parametrize(
  35. "args, expected_stdout_line", timezone_with_command_line_arg_input()
  36. )
  37. def test_timezone_with_command_line_arg(args, expected_stdout_line):
  38. result = execute(KOSMORRO + args)
  39. assert result.successful
  40. assert expected_stdout_line in result.stdout
  41. def timezone_with_env_var_input():
  42. yield {"TZ": "1"}, [
  43. "-d2020-01-27"
  44. ], "Note: All the hours are given in the UTC+1.0 timezone."
  45. yield {"TZ": "Europe/Paris"}, [
  46. "-d2020-01-27"
  47. ], "Note: All the hours are given in the UTC+1.0 timezone."
  48. yield {"TZ": "Europe/Paris"}, [
  49. "-d2020-07-27"
  50. ], "Note: All the hours are given in the UTC+2.0 timezone."
  51. yield {"TZ": "-5"}, [
  52. "-d2020-01-27"
  53. ], "Note: All the hours are given in the UTC-5.0 timezone."
  54. yield {"TZ": "America/Chicago"}, [
  55. "-d2020-01-27"
  56. ], "Note: All the hours are given in the UTC-6.0 timezone."
  57. yield {"TZ": "America/Chicago"}, [
  58. "-d2020-07-27"
  59. ], "Note: All the hours are given in the UTC-5.0 timezone."
  60. @pytest.mark.parametrize(
  61. "environment, args, expected_stdout_line", timezone_with_env_var_input()
  62. )
  63. def test_timezone_with_env_var(environment, args, expected_stdout_line):
  64. result = execute(KOSMORRO + args, environment=environment)
  65. assert result.successful
  66. assert expected_stdout_line in result.stdout
  67. def test_timezone_with_env_var_and_command_line_arg():
  68. result = execute(
  69. KOSMORRO + ["--timezone=3", "-d2020-01-27"], environment={"TZ": "Europe/Paris"}
  70. )
  71. assert result.successful
  72. assert "Note: All the hours are given in the UTC+3.0 timezone." in result.stdout
  73. def timezone_with_deprecated_env_var_input():
  74. yield {"KOSMORRO_TIMEZONE": "1"}, [
  75. "-d2020-01-27"
  76. ], "Note: All the hours are given in the UTC+1.0 timezone."
  77. yield {"KOSMORRO_TIMEZONE": "Europe/Paris"}, [
  78. "-d2020-01-27"
  79. ], "Note: All the hours are given in the UTC+1.0 timezone."
  80. yield {"KOSMORRO_TIMEZONE": "Europe/Paris"}, [
  81. "-d2020-07-27"
  82. ], "Note: All the hours are given in the UTC+2.0 timezone."
  83. yield {"KOSMORRO_TIMEZONE": "-5"}, [
  84. "-d2020-01-27"
  85. ], "Note: All the hours are given in the UTC-5.0 timezone."
  86. yield {"KOSMORRO_TIMEZONE": "America/Chicago"}, [
  87. "-d2020-01-27"
  88. ], "Note: All the hours are given in the UTC-6.0 timezone."
  89. yield {"KOSMORRO_TIMEZONE": "America/Chicago"}, [
  90. "-d2020-07-27"
  91. ], "Note: All the hours are given in the UTC-5.0 timezone."
  92. @pytest.mark.parametrize(
  93. "environment, args, expected_stdout_line", timezone_with_deprecated_env_var_input()
  94. )
  95. def test_timezone_with_deprecated_env_var(environment, args, expected_stdout_line):
  96. result = execute(KOSMORRO + args, environment=environment)
  97. assert result.successful
  98. assert (
  99. "Environment variable KOSMORRO_TIMEZONE is deprecated. Use TZ instead, which is more standard."
  100. in result.stderr
  101. )
  102. assert expected_stdout_line in result.stdout