forked from sdispater/pytzdata
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_set_directory.py
More file actions
61 lines (37 loc) · 1.45 KB
/
Copy pathtest_set_directory.py
File metadata and controls
61 lines (37 loc) · 1.45 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
# -*- coding: utf-8 -*-
import os
import pytest
from pytzdata import set_directory, tz_path, TimezoneNotFound
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'tz')
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_set_directory():
set_directory(fixtures_path)
assert tz_path('Europe/Paris') == os.path.join(fixtures_path, 'Europe/Paris')
with pytest.raises(TimezoneNotFound):
tz_path('America/New_York')
here = os.path.realpath(os.path.dirname(__file__))
filepath = os.path.realpath(
os.path.join(here, '..', 'pytzdata', 'zoneinfo', 'America', 'New_York')
)
set_directory()
assert tz_path('America/New_York') == filepath
def test_env_variable():
os.environ['PYTZDATA_TZDATADIR'] = fixtures_path
set_directory()
assert tz_path('Europe/Paris') == os.path.join(fixtures_path, 'Europe/Paris')
with pytest.raises(TimezoneNotFound):
tz_path('America/New_York')
del os.environ['PYTZDATA_TZDATADIR']
here = os.path.realpath(os.path.dirname(__file__))
filepath = os.path.realpath(
os.path.join(here, '..', 'pytzdata', 'zoneinfo', 'America', 'New_York')
)
set_directory()
assert tz_path('America/New_York') == filepath