forked from sdispater/pytzdata
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_tz_file.py
More file actions
40 lines (27 loc) · 931 Bytes
/
Copy pathtest_tz_file.py
File metadata and controls
40 lines (27 loc) · 931 Bytes
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
# -*- coding: utf-8 -*-
import os
import pytest
from pytzdata import tz_file, set_directory
from pytzdata.exceptions import TimezoneNotFound
def setup_module(module):
if 'PYTZDATA_TZDATADIR' in os.environ:
del os.environ['PYTZDATA_TZDATADIR']
set_directory()
def teardown_module(module):
if 'PYTZDATA_TZDATADIR' in os.environ:
del os.environ['PYTZDATA_TZDATADIR']
set_directory()
def test_tz_file():
here = os.path.realpath(os.path.dirname(__file__))
filepath = os.path.realpath(
os.path.join(here, '..', 'pytzdata', 'zoneinfo', 'Europe', 'Paris')
)
with open(filepath) as f1:
with tz_file('Europe/Paris') as f2:
assert f1.name == f2.name
def test_tz_file_not_found():
with pytest.raises(TimezoneNotFound):
tz_file('Invalid')
def test_tz_file_invalid_name():
with pytest.raises(ValueError):
tz_file('Europe/../Paris')