Skip to content

Commit

Permalink
[tests] Add tests for invalid timezone
Browse files Browse the repository at this point in the history
Coverage was missing for when timezone
might be invalid. Added a test which takes an invalid date
and tries to convert it to UTC. Being invalid, it will trigger
the exception on line 92, remove timezone info and convert to UTC.

Signed-off-by: sevagenv <sevagenv@gmail.com>
  • Loading branch information
VSevagen committed Apr 1, 2021
1 parent 5bf8fc8 commit 357bb1d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def test_conversion(self):
self.assertIsInstance(utc, datetime.datetime)
self.assertEqual(utc, expected)

# This data is invalid because of the timezone offset
# It will trigger the exception and get converted to utc
date = datetime.datetime(2001, 12, 1, 23, 15, 32,
tzinfo=dateutil.tz.tzoffset(None, 93600))
expected = datetime.datetime(2001, 12, 1, 23, 15, 32,
tzinfo=dateutil.tz.tzutc())
utc = datetime_to_utc(date)
self.assertIsInstance(utc, datetime.datetime)
self.assertEqual(utc, expected)

def test_invalid_datetime(self):
"""Check if it raises an exception on invalid instances."""

Expand Down

0 comments on commit 357bb1d

Please sign in to comment.