Fixed get_datetime method from timestamp tests.

This commit is contained in:
Fabio Caccamo 2019-07-09 18:36:19 +02:00
parent 71a94131e9
commit d39c13fd9c
1 changed files with 6 additions and 5 deletions

View File

@ -4,8 +4,9 @@ from benedict.dicts.parse import ParseDict
from datetime import datetime from datetime import datetime
from decimal import Decimal from decimal import Decimal
from six import PY3 from six import PY2, PY3
import time
import unittest import unittest
@ -91,21 +92,21 @@ class ParseDictTestCase(unittest.TestCase):
def test_get_datetime_with_timestamp_int(self): def test_get_datetime_with_timestamp_int(self):
now = datetime.now() now = datetime.now()
ts = datetime.timestamp(now) ts = time.mktime(now.timetuple()) if PY2 else datetime.timestamp(now)
d = { d = {
'a': ts, 'a': ts,
} }
b = ParseDict(d) b = ParseDict(d)
self.assertEqual(b.get_datetime('a'), now) self.assertEqual(b.get_datetime('a'), datetime.fromtimestamp(ts))
def test_get_datetime_with_timestamp_string(self): def test_get_datetime_with_timestamp_string(self):
now = datetime.now() now = datetime.now()
ts = datetime.timestamp(now) ts = time.mktime(now.timetuple()) if PY2 else datetime.timestamp(now)
d = { d = {
'a': str(ts), 'a': str(ts),
} }
b = ParseDict(d) b = ParseDict(d)
self.assertEqual(b.get_datetime('a'), now) self.assertEqual(b.get_datetime('a'), datetime.fromtimestamp(ts))
def test_get_datetime_with_valid_format(self): def test_get_datetime_with_valid_format(self):
d = { d = {