From 33ba2a5b3566dcfc8c0437f5d623e44e866eeb3f Mon Sep 17 00:00:00 2001 From: mavaylon1 Date: Wed, 27 Sep 2023 19:10:51 -0700 Subject: [PATCH] test next --- src/hdmf/common/table.py | 14 ++++++++++++++ tests/unit/test_term_set.py | 11 +++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/hdmf/common/table.py b/src/hdmf/common/table.py index c1154affd..2a01f1143 100644 --- a/src/hdmf/common/table.py +++ b/src/hdmf/common/table.py @@ -582,12 +582,26 @@ def add_row(self, **kwargs): data, row_id, enforce_unique_id = popargs('data', 'id', 'enforce_unique_id', kwargs) data = data if data is not None else kwargs + bad_data = [] extra_columns = set(list(data.keys())) - set(list(self.__colids.keys())) missing_columns = set(list(self.__colids.keys())) - set(list(data.keys())) for colname, colnum in self.__colids.items(): if colname not in data: raise ValueError("column '%s' missing" % colname) + col = self.__df_cols[colnum] + if isinstance(col, VectorIndex): + continue + else: + if col.term_set is not None: + if col.term_set.validate(term=data[colname]): + continue + else: + bad_data.append(data[colname]) + + if len(bad_data)!=0: + msg = ('"%s" is not in the term set.' % ', '.join([str(item) for item in bad_data])) + raise ValueError(msg) # check to see if any of the extra columns just need to be added if extra_columns: diff --git a/tests/unit/test_term_set.py b/tests/unit/test_term_set.py index f9115ecdb..931d7bda8 100644 --- a/tests/unit/test_term_set.py +++ b/tests/unit/test_term_set.py @@ -181,11 +181,6 @@ def test_wrapper_extend_error(self): data_obj.extend(['bad_data']) def test_wrapper_next(self): - data_values = ['Homo sapiens', 'Mus musculus'] - data_obj = VectorData(name='species', description='...', data=self.wrapped_list) - data_obj.extend(['Mus musculus']) - - counter = 0 - for i in data_obj.data: - self.assertEqual(i, data_values[counter]) - counter +=1 + with self.assertRaises(AttributeError): + next(self.wrapped_list) +