def test_load_namespace_with_reftype_attribute_check_autoclass_const(self): ns_builder = NWBNamespaceBuilder('Extension for use in my Lab', self.prefix) test_ds_ext = NWBDatasetSpec( doc='test dataset to add an attr', name='test_data', shape=(None, ), attributes=[ NWBAttributeSpec(name='target_ds', doc='the target the dataset applies to', dtype=RefSpec('TimeSeries', 'object')) ], neurodata_type_def='my_new_type') ns_builder.add_spec(self.ext_source, test_ds_ext) ns_builder.export(self.ns_path, outdir=self.tempdir) type_map = get_type_map( extensions=os.path.join(self.tempdir, self.ns_path)) my_new_type = type_map.get_container_cls(self.prefix, 'my_new_type') docval = None for tmp in get_docval(my_new_type.__init__): if tmp['name'] == 'target_ds': docval = tmp break self.assertIsNotNone(docval) self.assertEqual(docval['type'], TimeSeries)
class TetrodeSeries(ElectricalSeries): __nwbfields__ = ('trode_id', ) @docval(*get_docval(ElectricalSeries.__init__) + ({ 'name': 'trode_id', 'type': int, 'doc': 'the tetrode id' }, )) def __init__(self, **kwargs): call_docval_func(super(TetrodeSeries, self).__init__, kwargs) self.trode_id = getargs('trode_id', kwargs)
def test_dynamic_container_creation_defaults(self): baz_spec = GroupSpec( 'A test extension with no Container class', data_type_def='Baz', data_type_inc=self.bar_spec, attributes=[ AttributeSpec('attr3', 'an example float attribute', 'float'), AttributeSpec('attr4', 'another example float attribute', 'float') ]) self.spec_catalog.register_spec(baz_spec, 'extension.yaml') cls = self.type_map.get_container_cls(CORE_NAMESPACE, 'Baz') expected_args = {'name', 'data', 'attr1', 'attr2', 'attr3', 'attr4'} received_args = set(map(lambda x: x['name'], get_docval(cls.__init__))) self.assertSetEqual(expected_args, received_args) self.assertEqual(cls.__name__, 'Baz') self.assertTrue(issubclass(cls, Bar))
class ECoGSubject(Subject): __nwbfields__ = ({'name': 'cortical_surfaces', 'child': True},) @docval(*get_docval(Subject.__init__) + ( { 'name': 'cortical_surfaces', 'doc': 'extension of Subject that allows adding cortical surface data', 'type': CorticalSurfaces, 'default': None, },) ) def __init__(self, **kwargs): cortical_surfaces = popargs('cortical_surfaces', kwargs) super(ECoGSubject, self).__init__(**kwargs) if cortical_surfaces is not None: self.cortical_surfaces = cortical_surfaces