MCPcopy Create free account
hub / github.com/dateutil/dateutil / TestTzinfoInputTypes

Class TestTzinfoInputTypes

tests/test_parser.py:350–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348
349
350class TestTzinfoInputTypes:
351 def assert_equal_same_tz(self, dt1, dt2):
352 assert dt1 == dt2
353 assert dt1.tzinfo is dt2.tzinfo
354
355 def test_tzinfo_dict_could_return_none(self):
356 dstr = "2017-02-03 12:40 BRST"
357 result = parse(dstr, tzinfos={"BRST": None})
358 expected = datetime(2017, 2, 3, 12, 40)
359 self.assert_equal_same_tz(result, expected)
360
361 def test_tzinfos_callable_could_return_none(self):
362 dstr = "2017-02-03 12:40 BRST"
363 result = parse(dstr, tzinfos=lambda *args: None)
364 expected = datetime(2017, 2, 3, 12, 40)
365 self.assert_equal_same_tz(result, expected)
366
367 def test_invalid_tzinfo_input(self):
368 dstr = "2014 January 19 09:00 UTC"
369 # Pass an absurd tzinfos object
370 tzinfos = {"UTC": ValueError}
371 with pytest.raises(TypeError):
372 parse(dstr, tzinfos=tzinfos)
373
374 def test_valid_tzinfo_tzinfo_input(self):
375 dstr = "2014 January 19 09:00 UTC"
376 tzinfos = {"UTC": tz.UTC}
377 expected = datetime(2014, 1, 19, 9, tzinfo=tz.UTC)
378 res = parse(dstr, tzinfos=tzinfos)
379 self.assert_equal_same_tz(res, expected)
380
381 def test_valid_tzinfo_unicode_input(self):
382 dstr = "2014 January 19 09:00 UTC"
383 tzinfos = {"UTC": "UTC+0"}
384 expected = datetime(2014, 1, 19, 9, tzinfo=tz.tzstr("UTC+0"))
385 res = parse(dstr, tzinfos=tzinfos)
386 self.assert_equal_same_tz(res, expected)
387
388 def test_valid_tzinfo_callable_input(self):
389 dstr = "2014 January 19 09:00 UTC"
390
391 def tzinfos(*args, **kwargs):
392 return "UTC+0"
393
394 expected = datetime(2014, 1, 19, 9, tzinfo=tz.tzstr("UTC+0"))
395 res = parse(dstr, tzinfos=tzinfos)
396 self.assert_equal_same_tz(res, expected)
397
398 def test_valid_tzinfo_int_input(self):
399 dstr = "2014 January 19 09:00 UTC"
400 tzinfos = {"UTC": -28800}
401 expected = datetime(2014, 1, 19, 9, tzinfo=tz.tzoffset("UTC", -28800))
402 res = parse(dstr, tzinfos=tzinfos)
403 self.assert_equal_same_tz(res, expected)
404
405
406class ParserTest(unittest.TestCase):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected