Repository: jazzband/tablib
Pull request #566 (2023-10-26 08:11:10)

fix(ods): None values are not displayed as string
Actually, `None` values are converted in string in an ODS sheet (so 'None' string is displayed in cells). This fill a cell empty value in case of None.
Sorry for not providing test : I see that ODS is tested only globally. It could be improved later :)
Thanks!

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/jazzband/tablib/pull/566?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) Report
> Merging [#566](https://app.codecov.io/gh/jazzband/tablib/pull/566?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) (91e8234) into [master](https://app.codecov.io/gh/jazzband/tablib/commit/0f0ddf6ab126e8543e24d018b7863a1513648cb6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) (0f0ddf6) will **decrease** coverage by `0.03%`.
> The diff coverage is `50.00%`.

```diff
@@            Coverage Diff             @@
##           master     #566      +/-   ##
==========================================
- Coverage   92.11%   92.08%   -0.03%     
==========================================
  Files          28       28              
  Lines        2827     2829       +2     
==========================================
+ Hits         2604     2605       +1     
- Misses        223      224       +1     
```


| [Files](https://app.codecov.io/gh/jazzband/tablib/pull/566?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) | Coverage Δ | |
|---|---|---|
| [src/tablib/formats/\_ods.py](https://app.codecov.io/gh/jazzband/tablib/pull/566?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband#diff-c3JjL3RhYmxpYi9mb3JtYXRzL19vZHMucHk=) | `96.49% <50.00%> (-1.70%)` | :arrow_down: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband)

claudep: I would suggest waiting for PR #568 to be merged, then you can rebase and take advantage of the new import functionality to complement the tests.
hoccau: > I would suggest waiting for PR #568 to be merged, then you can rebase and take advantage of the new import functionality to complement the tests.

ok, fine.

Patch:
diff --git a/src/tablib/formats/_ods.py b/src/tablib/formats/_ods.py
index 4f45192..34b47a0 100644
--- a/src/tablib/formats/_ods.py
+++ b/src/tablib/formats/_ods.py
@@ -164,6 +164,8 @@ class ODSFormat:
                     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))


Test patch:
diff --git a/tests/test_tablib.py b/tests/test_tablib.py
index c40d7bf..6c61c20 100755
--- a/tests/test_tablib.py
+++ b/tests/test_tablib.py
@@ -1111,9 +1111,9 @@ class ODSTests(BaseTestCase):
         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 @@ class ODSTests(BaseTestCase):
         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'