27 lines
811 B
Python
27 lines
811 B
Python
"""Timezone detection tests."""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
|
|
|
from fenris import tz_util
|
|
|
|
|
|
def test_relative_localtime_symlink_returns_zoneinfo_key(tmp_path, monkeypatch):
|
|
zoneinfo = tmp_path / "usr" / "share" / "zoneinfo" / "Asia" / "Kolkata"
|
|
zoneinfo.parent.mkdir(parents=True)
|
|
zoneinfo.write_bytes(b"zoneinfo")
|
|
localtime = tmp_path / "etc" / "localtime"
|
|
localtime.parent.mkdir()
|
|
localtime.symlink_to("../usr/share/zoneinfo/Asia/Kolkata")
|
|
|
|
real_path = tz_util.Path
|
|
monkeypatch.setattr(
|
|
tz_util,
|
|
"Path",
|
|
lambda path: localtime if path == "/etc/localtime" else real_path(path),
|
|
)
|
|
monkeypatch.delenv("TZ", raising=False)
|
|
|
|
assert tz_util.detect_system_tz() == "Asia/Kolkata"
|