From 6255ce29859cc0a6981ac025794c80f888e75a4c 2013-11-06 20:28:31 From: MinRK Date: 2013-11-06 20:28:31 Subject: [PATCH] test that we don't choke on sub-millisecond precision timestamps (#4493) --- diff --git a/IPython/utils/tests/test_jsonutil.py b/IPython/utils/tests/test_jsonutil.py index 655f516..66bb6a4 100644 --- a/IPython/utils/tests/test_jsonutil.py +++ b/IPython/utils/tests/test_jsonutil.py @@ -113,6 +113,18 @@ def test_extract_dates(): nt.assert_true(isinstance(dt, datetime.datetime)) nt.assert_equal(dt, ref) +def test_parse_ms_precision(): + base = '2013-07-03T16:34:52.' + digits = '1234567890' + + for i in range(len(digits)): + ts = base + digits[:i] + parsed = jsonutil.parse_date(ts) + if i >= 1 and i <= 6: + assert isinstance(parsed, datetime.datetime) + else: + assert isinstance(parsed, str) + def test_date_default(): data = dict(today=datetime.datetime.now(), utcnow=tz.utcnow()) jsondata = json.dumps(data, default=jsonutil.date_default)