Fix date and datetime export to JSON in Python versions with a json package

Python without a json package will use omnijson and fail on date and datetime objects.
Added unit tests.
This commit is contained in:
Dylan Verheul
2016-11-30 12:32:47 +01:00
parent f59abe84be
commit 91d3299280
3 changed files with 30 additions and 2 deletions
+3
View File
@@ -26,3 +26,6 @@ junit-py27.xml
# tox noise
.tox
# pyenv noise
.python-version
+4 -2
View File
@@ -5,8 +5,10 @@
import tablib
import sys
from tablib.packages import omnijson as json
try:
import json
except ImportError:
from tablib.packages import omnijson as json
title = 'json'
+23
View File
@@ -6,6 +6,9 @@ import json
import unittest
import sys
import os
import datetime
import tablib
from tablib.compat import markup, unicode, is_py3
from tablib.core import Row
@@ -381,6 +384,26 @@ class TablibTestCase(unittest.TestCase):
data.html
data.latex
def test_datetime_append(self):
"""Passes in a single datetime and a single date and exports."""
new_row = (
datetime.datetime.now(),
datetime.datetime.today(),
)
data.append(new_row)
data.json
data.yaml
data.csv
data.tsv
data.xls
data.xlsx
data.ods
data.html
data.latex
def test_book_export_no_exceptions(self):
"""Test that various exports don't error out."""