Skip to content

Commit b808597

Browse files
authored
Merge pull request #12 from pganssle/fix_build_windows
Fix windows build and add tests
2 parents 0f5464e + 790bd7d commit b808597

File tree

4 files changed

+148
-2
lines changed

4 files changed

+148
-2
lines changed

.github/workflows/tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: tzdata contents
2+
3+
on: [push]
4+
5+
jobs:
6+
tests:
7+
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
python-version: [2.7, 3.6, 3.7, 3.8]
12+
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
13+
env:
14+
TOXENV: py
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: ${{ matrix.python-version }} - ${{ matrix.os }}
19+
uses: actions/setup-python@v1
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
python -m pip install --upgrade tox
26+
- name: Run tests
27+
run: |
28+
tox
29+
30+
other:
31+
runs-on: "ubuntu-latest"
32+
strategy:
33+
matrix:
34+
toxenv: ["build", "pytype"]
35+
env:
36+
TOXENV: ${{ matrix.toxenv }}
37+
38+
steps:
39+
- uses: actions/checkout@v2
40+
- name: ${{ matrix.toxenv }}
41+
uses: actions/setup-python@v1
42+
with:
43+
python-version: 3.8
44+
- name: Install tox
45+
run: |
46+
python -m pip install --upgrade pip
47+
python -m pip install --upgrade tox
48+
- name: Run action
49+
run: |
50+
tox

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
recursive-include src/tzdata/ *
1+
recursive-include src/tzdata *

tests/test_contents.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import sys
2+
3+
import pytest
4+
5+
try:
6+
from importlib import resources
7+
except ImportError:
8+
import importlib_resources as resources
9+
10+
11+
if sys.version_info < (3, 6):
12+
# pytest-subtests does not support Python < 3.6, but having the tests
13+
# separated into clean subtests is nice but not required, so we will create
14+
# a stub that does nothing but at least doesn't fail for lack of a fixture.
15+
import contextlib
16+
17+
class _SubTestStub:
18+
@contextlib.contextmanager
19+
def test(self, **kwargs):
20+
yield
21+
22+
_sub_test_stub = _SubTestStub()
23+
24+
@pytest.fixture
25+
def subtests():
26+
yield _sub_test_stub
27+
28+
29+
def get_magic(zone_name):
30+
components = zone_name.split("/")
31+
package_name = ".".join(["tzdata.zoneinfo"] + components[:-1])
32+
resource_name = components[-1]
33+
34+
with resources.open_binary(package_name, resource_name) as f:
35+
return f.read(4)
36+
37+
38+
@pytest.mark.parametrize(
39+
"zone_name",
40+
[
41+
"Africa/Cairo",
42+
"Africa/Casablanca",
43+
"Africa/Lome",
44+
"America/Argentina/San_Luis",
45+
"America/Denver",
46+
"America/Los_Angeles",
47+
"America/New_York",
48+
"America/Thunder_Bay",
49+
"Antarctica/South_Pole",
50+
"Asia/Calcutta",
51+
"Asia/Damascus",
52+
"Asia/Seoul",
53+
"Atlantic/Reykjavik",
54+
"Australia/Perth",
55+
"Egypt",
56+
"Etc/GMT-9",
57+
"Europe/Dublin",
58+
"Europe/London",
59+
"Europe/Prague",
60+
"Hongkong",
61+
"Indian/Cocos",
62+
"Indian/Mayotte",
63+
"Mexico/BajaNorte",
64+
"Pacific/Guam",
65+
"Pacific/Kiritimati",
66+
"US/Eastern",
67+
"UTC",
68+
],
69+
)
70+
def test_zone_valid(zone_name):
71+
"""Test an assortment of hard-coded zone names.
72+
73+
This test checks that the zone resource can be loaded and that it starts
74+
with the 4-byte magic indicating a TZif file.
75+
"""
76+
magic = get_magic(zone_name)
77+
assert magic == b"TZif"
78+
79+
80+
def test_load_zones(subtests):
81+
with resources.open_text("tzdata", "zones") as f:
82+
zones = [z.strip() for z in f]
83+
84+
for zone in zones:
85+
with subtests.test(zone=zone):
86+
magic = get_magic(zone)
87+
assert magic == b"TZif"

tox.ini

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ minversion = 3.3.0
33
isolated_build = True
44
skip_missing_interpreters = true
55

6+
[testenv]
7+
description = Test that the tzdata contents are accessible
8+
deps =
9+
pytest
10+
pytest-subtests; python_version>='3.6'
11+
importlib_resources; python_version<'3.7'
12+
commands =
13+
pytest {toxinidir} {posargs}
14+
615
[testenv:update]
716
description = Update the tzdata contents
817
skip_install = True
@@ -30,7 +39,7 @@ deps =
3039
commands =
3140
black .
3241
isort update.py
33-
42+
isort --atomic -rc tests
3443

3544
[testenv:build]
3645
description = Build a wheel and source distribution

0 commit comments

Comments
 (0)