Esempio n. 1
0
    def getSpecs(self):
        bar = GroupSpec('A test group specification with a data type',
                        data_type_def='Bar',
                        datasets=[
                            DatasetSpec('an example dataset',
                                        'int',
                                        name='data',
                                        attributes=[
                                            AttributeSpec(
                                                'attr2',
                                                'an example integer attribute',
                                                'int')
                                        ])
                        ],
                        attributes=[
                            AttributeSpec('attr1',
                                          'an example string attribute', 'str')
                        ])
        foo = GroupSpec('A test group that contains a data type',
                        data_type_def='Foo',
                        groups=[
                            GroupSpec('A Bar group for Foos',
                                      name='my_bar',
                                      data_type_inc='Bar')
                        ],
                        attributes=[
                            AttributeSpec(
                                'foo_attr',
                                'a string attribute specified as text',
                                'text',
                                required=False)
                        ])

        return (bar, foo)
Esempio n. 2
0
 def test_set_dataset(self):
     spec = GroupSpec('A test group',
                      name='root_test_set_dataset',
                      linkable=False,
                      data_type_def='EphysData')
     spec.set_dataset(self.datasets[0])
     self.assertIs(spec, self.datasets[0].parent)
Esempio n. 3
0
 def setUpBucketSpec(self):
     self.bucket_spec = GroupSpec('A test group specification for a data type containing data type',
                                  name="test_foo_bucket",
                                  data_type_def='FooBucket',
                                  groups=[GroupSpec(
                                      'the Foos in this bucket',
                                      data_type_inc='Foo',
                                      quantity=ZERO_OR_MANY)])
Esempio n. 4
0
 def setUpBarSpec(self):
     self.bar_spec = GroupSpec(
         'A test group specification with a data type',
         data_type_def='Bar',
         groups=[GroupSpec('an example group', data_type_def='Foo')],
         attributes=[
             AttributeSpec('attr1', 'an example string attribute', 'str'),
             AttributeSpec('attr2', 'an example integer attribute', 'int')
         ])
Esempio n. 5
0
 def test_set_group(self):
     spec = GroupSpec('A test group',
                      name='root_test_set_group',
                      linkable=False,
                      data_type_def='EphysData')
     spec.set_group(self.subgroups[0])
     spec.set_group(self.subgroups[1])
     self.assertListEqual(spec['groups'], self.subgroups)
     self.assertIs(spec, self.subgroups[0].parent)
     self.assertIs(spec, self.subgroups[1].parent)
     json.dumps(spec)
Esempio n. 6
0
 def setUpBucketSpec(self):
     tmp_spec = GroupSpec('A subgroup for Foos',
                          name='foo_holder',
                          groups=[GroupSpec('the Foos in this bucket',
                                            data_type_inc='Foo',
                                            quantity=ZERO_OR_MANY)])
     tmp_spec = GroupSpec('A subgroup to hold the subgroup', name='foo_holder_holder', groups=[tmp_spec])
     self.bucket_spec = GroupSpec('A test group specification for a data type containing data type',
                                  name="test_foo_bucket",
                                  data_type_def='FooBucket',
                                  groups=[tmp_spec])
Esempio n. 7
0
 def test_update_attribute_spec(self):
     spec = GroupSpec('A test group',
                      name='root_constructor',
                      attributes=[
                          AttributeSpec('attribute1', 'my first attribute',
                                        'text'),
                      ])
     spec.set_attribute(
         AttributeSpec('attribute1', 'my first attribute', 'int', value=5))
     res = spec.get_attribute('attribute1')
     self.assertEqual(res.value, 5)
     self.assertEqual(res.dtype, 'int')
Esempio n. 8
0
 def test_get_subspec_named(self):
     child_spec = GroupSpec('A test group specification with a data type',
                            'my_subgroup')
     parent_spec = GroupSpec('Something to hold a Bar',
                             'my_group',
                             groups=[child_spec])
     sub_builder = GroupBuilder('my_subgroup',
                                attributes={
                                    'data_type': 'Bar',
                                    'namespace': CORE_NAMESPACE
                                })
     builder = GroupBuilder('my_group', groups={'my_bar':
                                                sub_builder})  # noqa: F841
     result = self.type_map.get_subspec(parent_spec, sub_builder)
     self.assertIs(result, child_spec)
Esempio n. 9
0
 def test_get_spec_source_file(self):
     spikes_spec = GroupSpec('test group', data_type_def='SpikeData')
     source_file_path = '/test/myt/test.yaml'
     self.catalog.auto_register(spikes_spec, source_file_path)
     recorded_source_file_path = self.catalog.get_spec_source_file(
         'SpikeData')
     self.assertEqual(recorded_source_file_path, source_file_path)
Esempio n. 10
0
 def setUp(self):
     self.bar_spec = GroupSpec(
         'A test group specification with a data type',
         data_type_def='Bar',
         datasets=[
             DatasetSpec('an example dataset',
                         'int',
                         name='data',
                         attributes=[
                             AttributeSpec('attr2',
                                           'an example integer attribute',
                                           'int')
                         ])
         ],
         attributes=[
             AttributeSpec('attr1', 'an example string attribute', 'str')
         ])
     self.spec_catalog = SpecCatalog()
     self.spec_catalog.register_spec(self.bar_spec, 'test.yaml')
     self.namespace = SpecNamespace('a test namespace',
                                    CORE_NAMESPACE, [{
                                        'source': 'test.yaml'
                                    }],
                                    catalog=self.spec_catalog)
     self.namespace_catalog = NamespaceCatalog()
     self.namespace_catalog.add_namespace(CORE_NAMESPACE, self.namespace)
     self.type_map = TypeMap(self.namespace_catalog)
     self.type_map.register_container_type(CORE_NAMESPACE, 'Bar', Bar)
     self.type_map.register_map(Bar, ObjectMapper)
     self.manager = BuildManager(self.type_map)
     self.mapper = ObjectMapper(self.bar_spec)
Esempio n. 11
0
 def getSpecs(self):
     ret = GroupSpec('A test group specification with a data type',
                     data_type_def='Bar',
                     datasets=[DatasetSpec('an example dataset', 'int', name='data',
                                           attributes=[AttributeSpec(
                                               'attr2', 'an example integer attribute', 'int')])],
                     attributes=[AttributeSpec('attr1', 'an example string attribute', 'text')])
     return (ret,)
Esempio n. 12
0
    def setUp(self):
        self.attributes = [
            AttributeSpec('attribute1', 'my first attribute', 'text'),
            AttributeSpec('attribute2', 'my second attribute', 'text')
        ]

        self.dset1_attributes = [
            AttributeSpec('attribute3', 'my third attribute', 'text'),
            AttributeSpec('attribute4', 'my fourth attribute', 'text')
        ]

        self.dset2_attributes = [
            AttributeSpec('attribute5', 'my fifth attribute', 'text'),
            AttributeSpec('attribute6', 'my sixth attribute', 'text')
        ]

        self.datasets = [
            DatasetSpec('my first dataset',
                        'int',
                        name='dataset1',
                        attributes=self.dset1_attributes,
                        linkable=True),
            DatasetSpec('my second dataset',
                        'int',
                        name='dataset2',
                        dimension=(None, None),
                        attributes=self.dset2_attributes,
                        linkable=True,
                        namespace='core',
                        data_type_def='VoltageArray')
        ]

        self.subgroups = [
            GroupSpec('A test subgroup', name='subgroup1', linkable=False),
            GroupSpec('A test subgroup', name='subgroup2', linkable=False)
        ]
        self.ndt_attr_spec = AttributeSpec('data_type',
                                           'the data type of this object',
                                           'text',
                                           value='EphysData')
        self.ns_attr_spec = AttributeSpec(
            'namespace',
            'the namespace for the data type of this object',
            'text',
            required=False)
Esempio n. 13
0
 def test_add_attribute(self):
     spec = GroupSpec('A test group',
                      name='root_constructor',
                      groups=self.subgroups,
                      datasets=self.datasets,
                      linkable=False)
     for attrspec in self.attributes:
         spec.add_attribute(**attrspec)
     self.assertListEqual(spec['attributes'], self.attributes)
     self.assertListEqual(spec['datasets'], self.datasets)
     self.assertNotIn('data_type_def', spec)
     self.assertIs(spec, self.subgroups[0].parent)
     self.assertIs(spec, self.subgroups[1].parent)
     self.assertIs(spec, spec.attributes[0].parent)
     self.assertIs(spec, spec.attributes[1].parent)
     self.assertIs(spec, self.datasets[0].parent)
     self.assertIs(spec, self.datasets[1].parent)
     json.dumps(spec)
Esempio n. 14
0
 def setUpBarSpec(self):
     self.bar_spec = GroupSpec(
         'A test group specification with a data type',
         data_type_def='Bar',
         datasets=[DatasetSpec('an example dataset', 'int', name='data')],
         attributes=[
             AttributeSpec('attr1', 'an example string attribute', 'text'),
             AttributeSpec('attr2', 'an example integer attribute', 'int')
         ])
Esempio n. 15
0
 def setUp(self):
     self.bar_spec = GroupSpec(
         'A test group specification with a data type', data_type_def='Bar')
     self.foo_spec = GroupSpec(
         'A test group specification with data type Foo',
         data_type_def='Foo')
     self.spec_catalog = SpecCatalog()
     self.spec_catalog.register_spec(self.bar_spec, 'test.yaml')
     self.spec_catalog.register_spec(self.foo_spec, 'test.yaml')
     self.namespace = SpecNamespace('a test namespace',
                                    CORE_NAMESPACE, [{
                                        'source': 'test.yaml'
                                    }],
                                    catalog=self.spec_catalog)
     self.namespace_catalog = NamespaceCatalog()
     self.namespace_catalog.add_namespace(CORE_NAMESPACE, self.namespace)
     self.type_map = TypeMap(self.namespace_catalog)
     self.type_map.register_container_type(CORE_NAMESPACE, 'Bar', Bar)
     self.type_map.register_container_type(CORE_NAMESPACE, 'Foo', Foo)
Esempio n. 16
0
 def test_datatype_extension_groupspec(self):
     '''Test to make sure DatasetSpec catches when a GroupSpec used as data_type_inc'''
     base = GroupSpec('a fake grop',
                      data_type_def='EphysData')
     with self.assertRaises(TypeError):
         ext = DatasetSpec('my first dataset extension',  # noqa: F841
                           'int',
                           name='dataset1',
                           data_type_inc=base,
                           data_type_def='SpikeData')
Esempio n. 17
0
 def test_get_subspec_data_type_noname(self):
     parent_spec = GroupSpec('Something to hold a Bar',
                             'bar_bucket',
                             groups=[self.bar_spec])
     sub_builder = GroupBuilder('my_bar',
                                attributes={
                                    'data_type': 'Bar',
                                    'namespace': CORE_NAMESPACE
                                })
     builder = GroupBuilder('bar_bucket',
                            groups={'my_bar': sub_builder})  # noqa: F841
     result = self.type_map.get_subspec(parent_spec, sub_builder)
     self.assertIs(result, self.bar_spec)
Esempio n. 18
0
 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))
Esempio n. 19
0
 def test_constructor_nwbtype(self):
     spec = GroupSpec('A test group',
                      name='root_constructor_nwbtype',
                      datasets=self.datasets,
                      attributes=self.attributes,
                      linkable=False,
                      data_type_def='EphysData')
     self.assertFalse(spec['linkable'])
     self.assertListEqual(spec['attributes'], self.attributes)
     self.assertListEqual(spec['datasets'], self.datasets)
     self.assertEqual(spec['data_type_def'], 'EphysData')
     self.assertIs(spec, self.attributes[0].parent)
     self.assertIs(spec, self.attributes[1].parent)
     self.assertIs(spec, self.datasets[0].parent)
     self.assertIs(spec, self.datasets[1].parent)
     self.assertEqual(spec.data_type_def, 'EphysData')
     self.assertIsNone(spec.data_type_inc)
     json.dumps(spec)
Esempio n. 20
0
 def test_dynamic_container_constructor(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')
     # TODO: test that constructor works!
     inst = cls('My Baz', [1, 2, 3, 4],
                'string attribute',
                1000,
                attr3=98.6,
                attr4=1.0)
     self.assertEqual(inst.name, 'My Baz')
     self.assertEqual(inst.data, [1, 2, 3, 4])
     self.assertEqual(inst.attr1, 'string attribute')
     self.assertEqual(inst.attr2, 1000)
     self.assertEqual(inst.attr3, 98.6)
     self.assertEqual(inst.attr4, 1.0)
Esempio n. 21
0
 def setUp(self):
     self.attributes = [
         AttributeSpec('attribute1', 'my first attribute', 'text'),
         AttributeSpec('attribute2', 'my second attribute', 'text')
     ]
     self.dset1_attributes = [
         AttributeSpec('attribute3', 'my third attribute', 'text'),
         AttributeSpec('attribute4', 'my fourth attribute', 'text')
     ]
     self.dset2_attributes = [
         AttributeSpec('attribute5', 'my fifth attribute', 'text'),
         AttributeSpec('attribute6', 'my sixth attribute', 'text')
     ]
     self.datasets = [
         DatasetSpec(
             'my first dataset',  # noqa: F405
             'int',
             name='dataset1',
             attributes=self.dset1_attributes,
             linkable=True),
         DatasetSpec(
             'my second dataset',  # noqa: F405
             'int',
             name='dataset2',
             dimension=(None, None),
             attributes=self.dset2_attributes,
             linkable=True,
             data_type_def='VoltageArray')
     ]
     self.spec = GroupSpec(
         'A test group',  # noqa: F405
         name='root_constructor_nwbtype',
         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')
     ]
     self.ext_datasets = [
         DatasetSpec(
             'my first dataset extension',  # noqa: F405
             'int',
             name='dataset1',
             attributes=dset1_attributes_ext,
             linkable=True),
     ]
     self.ext_attributes = [
         AttributeSpec('ext_extra_attribute',
                       'an extra attribute for the group', 'text'),
     ]
     self.ext_spec = GroupSpec(
         'A test group extension',  # noqa: F405
         name='root_constructor_nwbtype',
         datasets=self.ext_datasets,
         attributes=self.ext_attributes,
         linkable=False,
         data_type_inc='EphysData',
         data_type_def='SpikeData')
     to_dump = {'groups': [self.spec, self.ext_spec]}
     self.specs_path = 'test_load_namespace.specs.yaml'
     self.namespace_path = 'test_load_namespace.namespace.yaml'
     with open(self.specs_path, 'w') as tmp:
         yaml.safe_dump(json.loads(json.dumps(to_dump)),
                        tmp,
                        default_flow_style=False)
     ns_dict = {
         'doc': 'a test namespace',
         'name': self.NS_NAME,
         'schema': [{
             'source': self.specs_path
         }]
     }
     self.namespace = SpecNamespace.build_namespace(**ns_dict)  # noqa: F405
     to_dump = {'namespaces': [self.namespace]}
     with open(self.namespace_path, 'w') as tmp:
         yaml.safe_dump(json.loads(json.dumps(to_dump)),
                        tmp,
                        default_flow_style=False)
     self.ns_catalog = NamespaceCatalog()  # noqa: F405
Esempio n. 22
0
    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)
Esempio n. 23
0
 def getSpecs(self):
     return (GroupSpec('A test group specification with a data type', data_type_def='Bar'),)