diff --git a/modules/base/pymod/table.py b/modules/base/pymod/table.py index e3e9a56cb9f934aca34d7be3bb26f4cab8c7ce4b..77951c6344d35e5f66f307a7cb53c868b666b3ad 100644 --- a/modules/base/pymod/table.py +++ b/modules/base/pymod/table.py @@ -654,6 +654,11 @@ class Table(object): for row in self.rows: row.append(data) else: + if len(data)!=len(self.rows): + self.col_names.pop() + self.col_types.pop() + raise ValueError('Length of data (%i) must correspond to number of '%len(data) +\ + 'existing rows (%i)'%len(self.rows)) for row, d in zip(self.rows, data): row.append(d) diff --git a/modules/base/tests/test_table.py b/modules/base/tests/test_table.py index 9afefb578345fc4385bc0e292b4534d9ffe8a1db..13afa0437ea969728fe73a71ba3d20c11cf128d6 100644 --- a/modules/base/tests/test_table.py +++ b/modules/base/tests/test_table.py @@ -592,6 +592,11 @@ class TestTable(unittest.TestCase): 'foo': [True, None, True], 'bar': [1, 2, 3]}) + def testRaiseErrorOnWrongDataLengthAddCol(self): + tab = Table() + tab.AddCol('a','f',[4.2,4.2,4.2]) + self.assertRaises(ValueError, tab.AddCol, 'b', 'f', [4.2,4.2]) + def testRaiseErrorOnWrongColumnTypes(self): # wrong columns types in init