Skip to content
Myr

Actually hand-spin and use a tzinfo subclass

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This is for Python 2.x compatibility.

authored by Eugene M. Kim · committed by Eugene M. Kim · parent f803760 · Browse files · 1 file+23 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Suggested-by: David Lord <davidism@gmail.com>

Diff stats

1 file+23 added−2 removed

  • tests:+23 added−2 removed

1 file+23 added−2 removed

modified:tests/test_helpers.py+23 added-2 removed
32 unmodified lines
33 except LookupError:34 return False353637class FixedOffset(datetime.tzinfo):38 """Fixed offset in hours east from UTC.3940 This is a slight adaptation of the ``FixedOffset`` example found in41 https://docs.python.org/2.7/library/datetime.html.42 """4344 def __init__(self, hours, name):45 self.__offset = datetime.timedelta(hours=hours)46 self.__name = name4748 def utcoffset(self, dt):49 return self.__offset5051 def tzname(self, dt):52 return self.__name5354 def dst(self, dt):55 return datetime.timedelta()565758class TestJSON(object):59 def test_ignore_cached_json(self, app):60 with app.test_request_context('/', method='POST', data='malformed',61 content_type='application/json'):
138 unmodified lines
200201 @pytest.mark.parametrize('tz', (('UTC', 0), ('PST', -8), ('KST', 9)))202 def test_jsonify_aware_datetimes(self, tz):203 """Test if aware datetime.datetime objects are converted into GMT."""183 tzinfo = datetime.timezone(datetime.timedelta(hours=tz[1]), name=tz[0])204 tzinfo = FixedOffset(hours=tz[1], name=tz[0])205 dt = datetime.datetime(2017, 1, 1, 12, 34, 56, tzinfo=tzinfo)185 gmt = datetime.timezone(datetime.timedelta(), name='GMT')206 gmt = FixedOffset(hours=0, name='GMT')207 expected = dt.astimezone(gmt).strftime('"%a, %d %b %Y %H:%M:%S %Z"')208 assert flask.json.JSONEncoder().encode(dt) == expected209210 def test_jsonify_uuid_types(self, app, client):
766 unmodified lines