summaryrefslogtreecommitdiffstats
path: root/tests/tz/zoneinfo
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/tz/zoneinfo/__init__.py0
-rw-r--r--tests/tz/zoneinfo/test_posix_timezone.py65
-rw-r--r--tests/tz/zoneinfo/test_reader.py46
3 files changed, 111 insertions, 0 deletions
diff --git a/tests/tz/zoneinfo/__init__.py b/tests/tz/zoneinfo/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/tz/zoneinfo/__init__.py
diff --git a/tests/tz/zoneinfo/test_posix_timezone.py b/tests/tz/zoneinfo/test_posix_timezone.py
new file mode 100644
index 0000000..41a6458
--- /dev/null
+++ b/tests/tz/zoneinfo/test_posix_timezone.py
@@ -0,0 +1,65 @@
+from pendulum.tz.zoneinfo.posix_timezone import JPosixTransition
+from pendulum.tz.zoneinfo.posix_timezone import MPosixTransition
+from pendulum.tz.zoneinfo.posix_timezone import posix_spec
+
+
+def test_posix_spec_m():
+ spec = "CET-1CEST,M3.5.0,M10.5.0/3"
+ tz = posix_spec(spec)
+
+ assert tz.std_abbr == "CET"
+ assert tz.std_offset == 3600
+ assert tz.dst_abbr == "CEST"
+ assert tz.dst_offset == 7200
+
+ assert isinstance(tz.dst_start, MPosixTransition)
+ assert tz.dst_start.month == 3
+ assert tz.dst_start.week == 5
+ assert tz.dst_start.weekday == 0
+ assert tz.dst_start.offset == 7200
+
+ assert isinstance(tz.dst_end, MPosixTransition)
+ assert tz.dst_end.month == 10
+ assert tz.dst_end.week == 5
+ assert tz.dst_end.weekday == 0
+ assert tz.dst_end.offset == 3 * 3600
+
+
+def test_posix_spec_m_no_abbr():
+ spec = "<+12>-12<+13>,M11.1.0,M1.2.1/147"
+ tz = posix_spec(spec)
+
+ assert tz.std_abbr == "+12"
+ assert tz.std_offset == 12 * 3600
+ assert tz.dst_abbr == "+13"
+ assert tz.dst_offset == 13 * 3600
+
+ assert isinstance(tz.dst_start, MPosixTransition)
+ assert tz.dst_start.month == 11
+ assert tz.dst_start.week == 1
+ assert tz.dst_start.weekday == 0
+ assert tz.dst_start.offset == 7200
+
+ assert isinstance(tz.dst_end, MPosixTransition)
+ assert tz.dst_end.month == 1
+ assert tz.dst_end.week == 2
+ assert tz.dst_end.weekday == 1
+ assert tz.dst_end.offset == 147 * 3600
+
+
+def test_posix_spec_j_no_abbr():
+ spec = "<+0330>-3:30<+0430>,J80/0,J264/0"
+ tz = posix_spec(spec)
+
+ assert tz.std_abbr == "+0330"
+ assert tz.std_offset == 3 * 3600 + 30 * 60
+ assert tz.dst_abbr == "+0430"
+ assert tz.dst_offset == 4 * 3600 + 30 * 60
+
+ assert isinstance(tz.dst_start, JPosixTransition)
+ assert tz.dst_start.day == 80
+ assert tz.dst_start.offset == 0
+
+ assert isinstance(tz.dst_end, JPosixTransition)
+ assert tz.dst_end.day == 264
+ assert tz.dst_end.offset == 0
diff --git a/tests/tz/zoneinfo/test_reader.py b/tests/tz/zoneinfo/test_reader.py
new file mode 100644
index 0000000..a19ba9a
--- /dev/null
+++ b/tests/tz/zoneinfo/test_reader.py
@@ -0,0 +1,46 @@
+import os
+
+import pytest
+
+from pendulum.tz.zoneinfo.exceptions import InvalidTimezone
+from pendulum.tz.zoneinfo.exceptions import InvalidZoneinfoFile
+from pendulum.tz.zoneinfo.reader import Reader
+from pendulum.tz.zoneinfo.timezone import Timezone
+
+
+def test_read_for_bad_timezone():
+ reader = Reader()
+ with pytest.raises(InvalidTimezone):
+ reader.read_for("---NOT A TIMEZONE---")
+
+
+def test_read_for_valid():
+ reader = Reader()
+
+ tz = reader.read_for("America/Toronto")
+ assert isinstance(tz, Timezone)
+
+
+def test_read():
+ reader = Reader()
+ local_path = os.path.join(os.path.split(__file__)[0], "..", "..")
+ tz_file = os.path.join(local_path, "fixtures", "tz", "Paris")
+ tz = reader.read(tz_file)
+
+ assert len(tz.transitions) > 0
+
+
+def test_read_invalid():
+ reader = Reader()
+ local_path = os.path.join(os.path.split(__file__)[0], "..")
+ tz_file = os.path.join(local_path, "fixtures", "tz", "NOT_A_TIMEZONE")
+
+ with pytest.raises(InvalidZoneinfoFile):
+ reader.read(tz_file)
+
+
+def test_set_transitions_for_no_transition_database_file():
+ reader = Reader()
+ tz = reader.read_for("Etc/UTC")
+
+ assert len(tz.transitions) == 1