Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/tablib/formats/_ods.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def dset_sheet(cls, dataset, ws):
odf_row = table.TableRow(stylename=style)
ws.addElement(odf_row)
for j, col in enumerate(row):
if isinstance(col, numbers.Number):
if isinstance(col, bool):
cell = table.TableCell(valuetype="boolean", booleanvalue="true" if col else "false")
elif isinstance(col, numbers.Number):
cell = table.TableCell(valuetype="float", value=col)
elif isinstance(col, dt.datetime):
cell = table.TableCell(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_tablib.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,16 @@ def test_ods_export_import_set(self):
self.assertEqual(data.dict[0]['None'], '')
self.assertEqual(data.dict[0]['empty'], '')

def test_ods_export_import_boolean(self):
data.append(('alice', True))
data.append(('bob', False))
data.headers = ('name', 'flag')
_ods = data.ods
data.ods = _ods
self.assertTrue(data.dict[0]['flag'])
self.assertFalse(data.dict[1]['flag'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not agree with this precommit change, we clearly want to test False/True here, and not the truethy/falsy values. @hugovk, do you know if we can by-pass the automatic change in this particular case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from teyit, it doesn't have # noqa way to disable per line.

Some options:

  • Flip the order: self.assertIs(True, data.dict[0]['flag'])

  • Rewrite as two checks: assertIsInstance(flag, bool) and assertTrue(flag)

  • It only matches AST constants, use variables:

  for index, expected in ((0, True), (1, False)):
      self.assertIs(data.dict[index]['flag'], expected)
  • Exclude teyit for this file in .pre-commit-config.yaml (which has the bulk of the tests)
  • Disable teyit entirely

Somewhat related, I use pytest in most other projects. What do you think about using it here, or do you prefer unittest? I'd prefer pytest, but also fine with unittest too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of automated checks, so I wouldn't be opposed to simply disable teyit entirely.

As far as testing is concerned, I've never been convicted about the real added value of pytest. For me it's more a matter of preferences, so when I can stick to the standard lib, I do. But I don't consider this as my project, so feel free to change that if you have the time for.

self.assertEqual(data.dict[0]['name'], 'alice')

def test_ods_export_display(self):
"""Test that exported datetime types are displayed correctly in office software"""
date = dt.date(2019, 10, 4)
Expand Down
Loading