mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
Add BooleanConverter to map proper boolean cells to a Bool column
Note that only proper boolean will be considered, but not integers nor truthy or falsy strings.
This commit is contained in:
BIN
sandbox/grist/imports/fixtures/test_boolean.xlsx
Normal file
BIN
sandbox/grist/imports/fixtures/test_boolean.xlsx
Normal file
Binary file not shown.
@@ -33,9 +33,10 @@ class TestImportXLS(unittest.TestCase):
|
||||
self.assertEqual(parsed_file[1][0]["table_data"][1],
|
||||
["a", "b", "c", "d", "e", "f", "g", "h"])
|
||||
|
||||
# 0s and 1s become Numeric, not boolean like in the past
|
||||
self.assertEqual(parsed_file[1][0]["column_metadata"][2], {"type": "Numeric", "id": "boolean"})
|
||||
self.assertEqual(parsed_file[1][0]["table_data"][2], [1, 0, 1, 0, 1, 0, 1, 0])
|
||||
# check that column type was correctly set to bool and values are properly parsed
|
||||
self.assertEqual(parsed_file[1][0]["column_metadata"][2], {"type": "Bool", "id": "boolean"})
|
||||
self.assertEqual(parsed_file[1][0]["table_data"][2],
|
||||
[True, False, True, False, True, False, True, False])
|
||||
|
||||
# check that column type was correctly set to text and values are properly parsed
|
||||
self.assertEqual(parsed_file[1][0]["column_metadata"][3],
|
||||
@@ -196,12 +197,29 @@ class TestImportXLS(unittest.TestCase):
|
||||
self.assertEqual(tables, [{
|
||||
'table_name': 'Sheet1',
|
||||
'column_metadata': [
|
||||
{'id': u'A', 'type': 'Numeric'},
|
||||
{'id': u'A', 'type': 'Bool'},
|
||||
{'id': u'B', 'type': 'Numeric'},
|
||||
],
|
||||
'table_data': [
|
||||
[False, False],
|
||||
[0, 0],
|
||||
[0, 0],
|
||||
],
|
||||
}])
|
||||
|
||||
def test_boolean(self):
|
||||
parsed_file = import_xls.parse_file(*_get_fixture('test_boolean.xlsx'))
|
||||
tables = parsed_file[1]
|
||||
self.assertEqual(tables, [{
|
||||
'table_name': 'Sheet1',
|
||||
'column_metadata': [
|
||||
{'id': u'A', 'type': 'Bool'},
|
||||
{'id': u'B', 'type': 'Bool'},
|
||||
{'id': u'C', 'type': 'Any'},
|
||||
],
|
||||
'table_data': [
|
||||
[True, False],
|
||||
[False, False],
|
||||
['true', 'False'],
|
||||
],
|
||||
}])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user