def test_add_category_already_in_table(self): category_names = ['test1', 'test2', 'test2'] num_rows = 10 categories = [DynamicTable(name=val, description=val+" description", columns=[VectorData(name=val+t, description=val+t+' description', data=np.arange(num_rows)) for t in ['c1', 'c2', 'c3']] ) for val in category_names] adt = AlignedDynamicTable( name='test_aligned_table', description='Test aligned container', category_tables=categories[0:2]) self.assertListEqual(adt.categories, category_names[0:2]) with self.assertRaises(ValueError) as ve: adt.add_category(categories[-1]) self.assertEqual(str(ve.exception), "Category test2 already in the table")
def test_add_category(self): """Test that we can correct a non-empty category to an existing table""" category_names = ['test1', 'test2', 'test3'] num_rows = 10 categories = [DynamicTable(name=val, description=val+" description", columns=[VectorData(name=val+t, description=val+t+' description', data=np.arange(num_rows)) for t in ['c1', 'c2', 'c3']] ) for val in category_names] adt = AlignedDynamicTable( name='test_aligned_table', description='Test aligned container', category_tables=categories[0:2]) self.assertListEqual(adt.categories, category_names[0:2]) adt.add_category(categories[-1]) self.assertListEqual(adt.categories, category_names)
def test_add_category_misaligned_rows(self): """Test that we can correct a non-empty category to an existing table""" category_names = ['test1', 'test2'] num_rows = 10 categories = [DynamicTable(name=val, description=val+" description", columns=[VectorData(name=val+t, description=val+t+' description', data=np.arange(num_rows)) for t in ['c1', 'c2', 'c3']] ) for val in category_names] adt = AlignedDynamicTable( name='test_aligned_table', description='Test aligned container', category_tables=categories) self.assertListEqual(adt.categories, category_names) with self.assertRaises(ValueError) as ve: adt.add_category(DynamicTable(name='test3', description='test3_description', columns=[VectorData(name='test3_'+t, description='test3 '+t+' description', data=np.arange(num_rows - 2)) for t in ['c1', 'c2', 'c3'] ])) self.assertEqual(str(ve.exception), "New category DynamicTable does not align, it has 8 rows expected 10")