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 5, 2021
1 parent 5bf8fc8 commit 761009d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ def test_conversion(self):
self.assertIsInstance(utc, datetime.datetime)
self.assertEqual(utc, expected)

def test_invalid_timezone(self):
""" Check whether datetime converts to UTC when timezone invalid """

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 761009d

Please sign in to comment.