def test_recursive_annotation_read(self): with tb.File(self.h5_name, mode='a') as h5_file: io.annotate_database(h5_file) io.write_custom_annotation( h5_file, 'test_ann_1', 'a test 1', annotations_sub_group='zzz_test_group_1') io.write_custom_annotation( h5_file, 'test_ann_2', 'a test 2', annotations_sub_group='zzz_test_group_2') io.write_custom_annotation( h5_file, 'test_ann_11', 'a test 11', annotations_sub_group='zzz_test_group_1/zzz_test_group_11') annotations = io.read_annotations(h5_file) annotation_lvl_0_keys = sorted(annotations.keys()) self.assertEqual( annotation_lvl_0_keys, self.ref_annotation_keys + ['zzz_test_group_1', 'zzz_test_group_2']) annotation_lvl_01_keys = sorted(annotations['zzz_test_group_1']) self.assertEqual(annotation_lvl_01_keys, ['test_ann_1', 'zzz_test_group_11']) annotation_lvl_02_keys = sorted(annotations['zzz_test_group_2']) self.assertEqual(annotation_lvl_02_keys, ['test_ann_2']) annotation_lvl_11_keys = sorted( annotations['zzz_test_group_1']['zzz_test_group_11']) self.assertEqual(annotation_lvl_11_keys, ['test_ann_11'])
def test_annotations_roundtrip(self): with tb.File(self.h5_name, mode='a') as h5_file: io.annotate_database(h5_file) annotation_keys = sorted(io.read_annotations(h5_file).keys()) self.assertEqual(annotation_keys, self.ref_annotation_keys) io.remove_annotations(h5_file) with self.assertRaises(tb.NoSuchNodeError): io.read_annotations(h5_file)
def test_annotations_exceptions(self): with tb.File(self.h5_name, mode='a') as h5_file: # No annotations io.remove_annotations(h5_file) # Pass if no annotations with self.assertRaises(tb.NoSuchNodeError): io.read_annotations(h5_file) # Non-compliant annotation annotations_group = h5_file.create_group('/', 'annotations') h5_file.create_array(annotations_group, 'fail_ann', obj='[fail)'.encode()) h5_file.flush() with self.assertRaises(ValueError): io.read_annotations(h5_file) # Already annotated database with self.assertRaises(tb.NodeError): io.annotate_database(h5_file)