Skip to content

Commit

Permalink
Merge pull request #120 from JuliaSprenger/fix/119
Browse files Browse the repository at this point in the history
Fix conversion of empty tables
  • Loading branch information
JuliaSprenger committed Dec 11, 2020
2 parents f978799 + 840eeeb commit 583cf39
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
11 changes: 7 additions & 4 deletions odmltables/odml_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ def load_from_csv_table(self, load_from):
# create a inverted header_titles dictionary for an inverted lookup
inv_header_titles = {v: k for (k, v) in list(self._header_titles.items())}

row_id = None

with open(load_from, 'r') as csvfile:
csvreader = csv.reader(csvfile)

Expand Down Expand Up @@ -489,10 +491,11 @@ def load_from_csv_table(self, load_from):
current_dic = new_dic

# copy final property
if row_id == 0:
self._odmldict.append(copy.deepcopy(new_dic))
else:
self._odmldict.append(copy.deepcopy(current_dic))
if not (row_id is None):
if row_id == 0:
self._odmldict.append(copy.deepcopy(new_dic))
else:
self._odmldict.append(copy.deepcopy(current_dic))

# value conversion for all properties
for current_dic in self._odmldict:
Expand Down
16 changes: 16 additions & 0 deletions odmltables/tests/test_odml_csv_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ def test_saveload_empty_value(self):
self.assertEqual(len(table._odmldict), 1)
self.assertDictEqual(table._odmldict[0], table2._odmldict[0])

def test_saveload_empty_header(self):
doc = odml.Document()

table = OdmlCsvTable()
table.load_from_odmldoc(doc)
table.change_header('full')
table.write2file(self.filename)

table2 = OdmlTable()
table2.load_from_csv_table(self.filename)

# comparing values which are written to xls by default
self.assertEqual(table._odmldict, [])
self.assertDictEqual({'author': None, 'date': None, 'repository': None, 'version': None},
table._docdict)


class TestShowallOdmlCsvTable(unittest.TestCase):
"""
Expand Down
16 changes: 16 additions & 0 deletions odmltables/tests/test_odml_xls_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ def test_saveload_empty_value(self):
self.assertEqual(len(table._odmldict), 1)
self.assertDictEqual(table._odmldict[0], table2._odmldict[0])

def test_saveload_empty_header(self):
doc = odml.Document()

table = OdmlXlsTable()
table.load_from_odmldoc(doc)
table.change_header('full')
table.write2file(self.filename)

table2 = OdmlTable()
table2.load_from_xls_table(self.filename)

# comparing values which are written to xls by default
self.assertEqual(table._odmldict, [])
self.assertDictEqual({'author': None, 'date': None, 'repository': None, 'version': None},
table._docdict)


class TestShowallOdmlXlsTable(unittest.TestCase):
"""
Expand Down

0 comments on commit 583cf39

Please sign in to comment.