From 0e6cab357690614791ab4ca0da0ac65dbb803041 Mon Sep 17 00:00:00 2001 From: "Eugene M. Kim" Date: Wed, 14 Jun 2017 13:06:26 -0700 Subject: [PATCH] Rewrite test_jsonify_aware_datetimes without pytz --- tests/test_helpers.py | 15 +++++++-------- tox.ini | 1 - 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 9e679746..b1418b81 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -23,7 +23,6 @@ from werkzeug.http import parse_cache_control_header, parse_options_header from werkzeug.http import http_date from flask._compat import StringIO, text_type from flask.helpers import get_debug_flag, make_response -from pytz import timezone def has_encoding(name): @@ -178,14 +177,14 @@ class TestJSON(object): assert rv.mimetype == 'application/json' assert flask.json.loads(rv.data)['x'] == http_date(d.timetuple()) - @pytest.mark.parametrize('tzname', ('UTC', 'PST8PDT', 'Asia/Seoul')) - def test_jsonify_aware_datetimes(self, tzname): + @pytest.mark.parametrize('tz', (('UTC', 0), ('PST', -8), ('KST', 9))) + def test_jsonify_aware_datetimes(self, tz): """Test if aware datetime.datetime objects are converted into GMT.""" - dt_naive = datetime.datetime(2017, 1, 1, 12, 34, 56) - dt_aware = timezone(tzname).localize(dt_naive) - dt_as_gmt = dt_aware.astimezone(timezone('GMT')) - expected = dt_as_gmt.strftime('"%a, %d %b %Y %H:%M:%S %Z"') - assert flask.json.JSONEncoder().encode(dt_aware) == expected + tzinfo = datetime.timezone(datetime.timedelta(hours=tz[1]), name=tz[0]) + dt = datetime.datetime(2017, 1, 1, 12, 34, 56, tzinfo=tzinfo) + gmt = datetime.timezone(datetime.timedelta(), name='GMT') + expected = dt.astimezone(gmt).strftime('"%a, %d %b %Y %H:%M:%S %Z"') + assert flask.json.JSONEncoder().encode(dt) == expected def test_jsonify_uuid_types(self, app, client): """Test jsonify with uuid.UUID types""" diff --git a/tox.ini b/tox.ini index a0b4ad66..cb6dd342 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,6 @@ deps = coverage greenlet blinker - pytz lowest: Werkzeug==0.9 lowest: Jinja2==2.4