def test_type_extension(self): spec = GroupSpec('A test group', name='parent_type', datasets=self.datasets, attributes=self.attributes, linkable=False, data_type_def='EphysData') dset1_attributes_ext = [ AttributeSpec('dset1_extra_attribute', 'an extra attribute for the first dataset', 'text') ] ext_datasets = [ DatasetSpec('my first dataset extension', 'int', name='dataset1', attributes=dset1_attributes_ext, linkable=True), ] ext_attributes = [ AttributeSpec('ext_extra_attribute', 'an extra attribute for the group', 'text'), ] ext = GroupSpec('A test group extension', name='child_type', datasets=ext_datasets, attributes=ext_attributes, linkable=False, data_type_inc=spec, data_type_def='SpikeData') ext_dset1 = ext.get_dataset('dataset1') ext_dset1_attrs = ext_dset1.attributes self.assertDictEqual(ext_dset1_attrs[0], dset1_attributes_ext[0]) self.assertDictEqual(ext_dset1_attrs[1], self.dset1_attributes[0]) self.assertDictEqual(ext_dset1_attrs[2], self.dset1_attributes[1]) self.assertEqual(ext.data_type_def, 'SpikeData') self.assertEqual(ext.data_type_inc, 'EphysData') ext_dset2 = ext.get_dataset('dataset2') self.maxDiff = None # this will suffice for now, assertDictEqual doesn't do deep equality checks self.assertEqual(str(ext_dset2), str(self.datasets[1])) self.assertAttributesEqual(ext_dset2, self.datasets[1]) # self.ns_attr_spec ndt_attr_spec = AttributeSpec('data_type', 'the data type of this object', # noqa: F841 'text', value='SpikeData') res_attrs = ext.attributes self.assertDictEqual(res_attrs[0], ext_attributes[0]) self.assertDictEqual(res_attrs[1], self.attributes[0]) self.assertDictEqual(res_attrs[2], self.attributes[1]) # test that inherited specs are tracked appropriate for d in self.datasets: with self.subTest(dataset=d.name): self.assertTrue(ext.is_inherited_spec(d)) self.assertFalse(spec.is_inherited_spec(d)) json.dumps(spec)
def test_update_docval_dset_shape(self): """Test that update_docval_args for a dataset with shape sets the type and shape keys.""" spec = GroupSpec(doc='A test group specification with a data type', data_type_def='Baz', datasets=[ DatasetSpec(name='dset1', doc='a string dataset', dtype='text', shape=[None]) ]) not_inherited_fields = {'dset1': spec.get_dataset('dset1')} docval_args = list() CustomClassGenerator.process_field_spec( classdict={}, docval_args=docval_args, parent_cls=EmptyBar, # <-- arbitrary class attr_name='dset1', not_inherited_fields=not_inherited_fields, type_map=TypeMap(), spec=spec) expected = [{ 'name': 'dset1', 'type': ('array_data', 'data'), 'doc': 'a string dataset', 'shape': [None] }] self.assertListEqual(docval_args, expected)
def test_update_docval(self): """Test update_docval_args for a variety of data types and mapping configurations.""" spec = GroupSpec( doc="A test group specification with a data type", data_type_def="Baz", groups=[ GroupSpec(doc="a group", data_type_inc="EmptyBar", quantity="?") ], datasets=[ DatasetSpec( doc="a dataset", dtype="int", name="data", attributes=[ AttributeSpec(name="attr2", doc="an integer attribute", dtype="int") ], ) ], attributes=[ AttributeSpec(name="attr1", doc="a string attribute", dtype="text"), AttributeSpec(name="attr3", doc="a numeric attribute", dtype="numeric"), AttributeSpec(name="attr4", doc="a float attribute", dtype="float"), ], ) expected = [ { 'name': 'data', 'type': (int, np.int32, np.int64), 'doc': 'a dataset' }, { 'name': 'attr1', 'type': str, 'doc': 'a string attribute' }, { 'name': 'attr2', 'type': (int, np.int32, np.int64), 'doc': 'an integer attribute' }, { 'name': 'attr3', 'doc': 'a numeric attribute', 'type': (float, np.float32, np.float64, np.int8, np.int16, np.int32, np.int64, int, np.uint8, np.uint16, np.uint32, np.uint64) }, { 'name': 'attr4', 'doc': 'a float attribute', 'type': (float, np.float32, np.float64) }, { 'name': 'bar', 'type': EmptyBar, 'doc': 'a group', 'default': None }, ] not_inherited_fields = { 'data': spec.get_dataset('data'), 'attr1': spec.get_attribute('attr1'), 'attr2': spec.get_dataset('data').get_attribute('attr2'), 'attr3': spec.get_attribute('attr3'), 'attr4': spec.get_attribute('attr4'), 'bar': spec.groups[0] } docval_args = list() for i, attr_name in enumerate(not_inherited_fields): with self.subTest(attr_name=attr_name): CustomClassGenerator.process_field_spec( classdict={}, docval_args=docval_args, parent_cls=EmptyBar, # <-- arbitrary class attr_name=attr_name, not_inherited_fields=not_inherited_fields, type_map=self.type_map, spec=spec) self.assertListEqual(docval_args, expected[:( i + 1)]) # compare with the first i elements of expected