-
-
Notifications
You must be signed in to change notification settings - Fork 426
Expand file tree
/
Copy pathtest_local_timezone.py
More file actions
66 lines (47 loc) · 2.04 KB
/
test_local_timezone.py
File metadata and controls
66 lines (47 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from __future__ import annotations
import os
import sys
import pytest
from pendulum.tz.local_timezone import _get_unix_timezone
from pendulum.tz.local_timezone import _get_windows_timezone
from pendulum.tz.local_timezone import get_local_timezone
from pendulum.tz.timezone import Timezone
@pytest.mark.skipif(
sys.platform == "win32", reason="Test only available for UNIX systems"
)
def test_unix_symlink():
# A ZONE setting in the target path of a symbolic linked localtime,
# f ex systemd distributions
local_path = os.path.join(os.path.split(__file__)[0], "..")
tz = _get_unix_timezone(_root=os.path.join(local_path, "fixtures", "tz", "symlink"))
assert tz.name == "Europe/Paris"
@pytest.mark.skipif(
sys.platform == "win32", reason="Test only available for UNIX systems"
)
def test_unix_clock():
# A ZONE setting in the target path of a symbolic linked localtime,
# f ex systemd distributions
local_path = os.path.join(os.path.split(__file__)[0], "..")
tz = _get_unix_timezone(_root=os.path.join(local_path, "fixtures", "tz", "clock"))
assert tz.name == "Europe/Zurich"
@pytest.mark.skipif(sys.platform != "win32", reason="Test only available for Windows")
def test_windows_timezone():
timezone = _get_windows_timezone()
assert timezone is not None
@pytest.mark.skipif(
sys.platform == "win32", reason="Test only available for UNIX systems"
)
def test_unix_etc_timezone_dir():
# Should not fail if `/etc/timezone` is a folder
local_path = os.path.join(os.path.split(__file__)[0], "..")
root_path = os.path.join(local_path, "fixtures", "tz", "timezone_dir")
tz = _get_unix_timezone(_root=root_path)
assert tz.name == "Europe/Paris"
@pytest.mark.skipif(
sys.platform == "win32", reason="Test only available for UNIX systems"
)
def test_unix_respects_TZ_env_var(monkeypatch): # noqa: N802
monkeypatch.setattr("pendulum.tz.local_timezone._local_timezone", None)
monkeypatch.setenv("TZ", "Europe/Paris")
tz = get_local_timezone()
assert tz == Timezone("Europe/Paris")