Debian Codegraph @

tests/test_localtime.py

raw
1 import os
2 import sys
3 from unittest.mock import Mock
4
5 import pytest
6
7 from babel.localtime import _helpers, get_localzone
8
9
10 @pytest.mark.skipif(
11 sys.platform == "win32",
12 reason="Issue 1092 is not applicable on Windows",
13 )
14 def test_issue_1092_without_pytz(monkeypatch):
15 pytest.importorskip("zoneinfo", reason="zoneinfo is not available")
16 monkeypatch.setenv("TZ", "/UTC") # Malformed timezone name.
17 # In case pytz _is_ also installed, we want to pretend it's not, so patch it out...
18 monkeypatch.setattr(_helpers, "pytz", None)
19 with pytest.raises(LookupError):
20 get_localzone()
21
22
23 @pytest.mark.skipif(
24 sys.platform == "win32",
25 reason="Issue 1092 is not applicable on Windows",
26 )
27 def test_issue_1092_with_pytz(monkeypatch):
28 pytest.importorskip("pytz", reason="pytz is not installed")
29 monkeypatch.setenv("TZ", "/UTC") # Malformed timezone name.
30 with pytest.raises(LookupError):
31 get_localzone()
32
33
34 @pytest.mark.skipif(
35 sys.platform == "win32",
36 reason="Issue 990 is not applicable on Windows",
37 )
38 def test_issue_990(monkeypatch):
39 monkeypatch.setenv("TZ", "")
40 fake_readlink = Mock(return_value="/usr/share/zoneinfo////UTC") # Double slash, oops!
41 monkeypatch.setattr(os, "readlink", fake_readlink)
42 from babel.localtime._unix import _get_localzone
43 assert _get_localzone() is not None
44 fake_readlink.assert_called_with("/etc/localtime")