test_timezones.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. """The committed zone list behind the bootstrap module's timezone check."""
  2. import re
  3. from pathlib import Path
  4. LIST = Path(__file__).resolve().parents[1] / "modules" / "twingate-bootstrap" / "timezones.txt"
  5. SHAPE = re.compile(r"^(UTC|[A-Za-z_]+(/[A-Za-z0-9_+-]+){1,2})$")
  6. def names():
  7. return LIST.read_text(encoding="utf-8").splitlines()
  8. def test_the_list_is_sorted_unique_and_has_the_default():
  9. n = names()
  10. assert n == sorted(set(n))
  11. assert "America/New_York" in n and "UTC" in n
  12. assert len(n) > 300 # guards against passing on an empty or truncated file
  13. def test_no_name_can_carry_a_line_break_or_yaml_character():
  14. assert "\r" not in LIST.read_text(encoding="utf-8")
  15. assert all(re.fullmatch(r"[A-Za-z0-9_+/-]+", x) for x in names())
  16. def test_the_shape_check_still_applies_on_top_of_the_list():
  17. # Names without an Area/ prefix (EST, Zulu) are listed but rejected by the shape check.
  18. assert any(not SHAPE.match(x) for x in names())
  19. assert sum(1 for x in names() if SHAPE.match(x)) > 300