Skip to content

Commit bd43a11

Browse files
committed
tz test shouldn't be sensitive to locale
use tzoffset instead of gettz to avoid sensitivity to test context
1 parent ec912d0 commit bd43a11

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

jupyter_client/tests/test_jsonutil.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
from datetime import timedelta
99
import json
1010

11+
try:
12+
from unittest import mock
13+
except ImportError:
14+
# py2
15+
import mock
16+
1117
import nose.tools as nt
1218

13-
from dateutil.tz import tzlocal, gettz
19+
from dateutil.tz import tzlocal, tzoffset
1420
from jupyter_client import jsonutil
1521
from jupyter_client.session import utcnow
1622

@@ -55,8 +61,11 @@ def test_parse_ms_precision():
5561

5662
def test_date_default():
5763
naive = datetime.datetime.now()
58-
data = dict(naive=naive, utc=utcnow(), withtz=naive.replace(tzinfo=gettz('CEST')))
59-
jsondata = json.dumps(data, default=jsonutil.date_default)
64+
local = tzoffset('Local', -8 * 3600)
65+
other = tzoffset('Other', 2 * 3600)
66+
data = dict(naive=naive, utc=utcnow(), withtz=naive.replace(tzinfo=other))
67+
with mock.patch.object(jsonutil, 'tzlocal', lambda : local):
68+
jsondata = json.dumps(data, default=jsonutil.date_default)
6069
nt.assert_in("Z", jsondata)
6170
nt.assert_equal(jsondata.count("Z"), 1)
6271
extracted = jsonutil.extract_dates(json.loads(jsondata))

0 commit comments

Comments
 (0)