From 26ded27c5ea3ea67f39169e578ab26fe87045fe0 Mon Sep 17 00:00:00 2001 From: Antoine Date: Sun, 10 Sep 2023 19:15:15 +0200 Subject: [PATCH] fix(ods): None values are not displayed as string --- src/tablib/formats/_ods.py | 2 ++ tests/test_tablib.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tablib/formats/_ods.py b/src/tablib/formats/_ods.py index 4f451923..34b47a0d 100644 --- a/src/tablib/formats/_ods.py +++ b/src/tablib/formats/_ods.py @@ -164,6 +164,8 @@ def dset_sheet(cls, dataset, ws): cell = table.TableCell(valuetype="date", datevalue=col.strftime('%Y-%m-%d')) elif isinstance(col, dt.time): cell = table.TableCell(valuetype="time", timevalue=col.strftime('%H:%M:%S')) + elif col is None: + cell = table.TableCell(valuetype="void") else: cell = table.TableCell(valuetype="string") cell.addElement(text.P(text=str(col), stylename=style)) diff --git a/tests/test_tablib.py b/tests/test_tablib.py index c40d7bf1..6c61c204 100755 --- a/tests/test_tablib.py +++ b/tests/test_tablib.py @@ -1111,9 +1111,9 @@ def test_ods_export_import_set(self): date = dt.date(2019, 10, 4) date_time = dt.datetime(2019, 10, 4, 12, 30, 8) time = dt.time(14, 30) - data.append(('string', '004', 42, 21.55, Decimal('34.5'), date, time, date_time)) + data.append(('string', '004', 42, 21.55, Decimal('34.5'), date, time, date_time, None)) data.headers = ( - 'string', 'start0', 'integer', 'float', 'decimal', 'date', 'time', 'date/time' + 'string', 'start0', 'integer', 'float', 'decimal', 'date', 'time', 'date/time', 'None' ) _ods = data.ods data.ods = _ods @@ -1125,6 +1125,7 @@ def test_ods_export_import_set(self): self.assertEqual(data.dict[0]['date'], date) self.assertEqual(data.dict[0]['time'], time) self.assertEqual(data.dict[0]['date/time'], date_time) + self.assertEqual(data.dict[0]['None'], '') def test_ods_import_book(self): ods_source = Path(__file__).parent / 'files' / 'book.ods'