Exemple #1
0
    return ret


def _get_resources():
    # LEGACY: Needed to support legacy implementation.
    return __get_resources()


# a global namespace catalog
global __NS_CATALOG
global __TYPE_MAP

__NS_CATALOG = NamespaceCatalog(NWBGroupSpec, NWBDatasetSpec, NWBNamespace)

hdmf_typemap = hdmf.common.get_type_map()
__NS_CATALOG.merge(hdmf_typemap.namespace_catalog)

__TYPE_MAP = TypeMap(__NS_CATALOG)
__TYPE_MAP.merge(hdmf_typemap)


@docval(
    {
        'name': 'extensions',
        'type': (str, TypeMap, list),
        'doc':
        'a path to a namespace, a TypeMap, or a list consisting of paths to namespaces and TypeMaps',
        'default': None
    },
    returns="the namespaces loaded from the given file",
    rtype=tuple,
Exemple #2
0
class TestCustomSpecClasses(TestCase):
    def setUp(self):  # noqa: C901
        self.ns_catalog = NamespaceCatalog(CustomGroupSpec, CustomDatasetSpec,
                                           CustomSpecNamespace)
        hdmf_typemap = get_type_map()
        self.ns_catalog.merge(hdmf_typemap.namespace_catalog)

    def test_constructor_getters(self):
        self.assertEqual(self.ns_catalog.dataset_spec_cls, CustomDatasetSpec)
        self.assertEqual(self.ns_catalog.group_spec_cls, CustomGroupSpec)
        self.assertEqual(self.ns_catalog.spec_namespace_cls,
                         CustomSpecNamespace)

    def test_load_namespaces(self):
        namespace_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'test.namespace.yaml')
        namespace_deps = self.ns_catalog.load_namespaces(namespace_path)

        # test that the dependencies are correct, including dependencies of the dependencies
        expected = set([
            'Data', 'Container', 'DynamicTable', 'ElementIdentifiers',
            'VectorData'
        ])
        self.assertSetEqual(set(namespace_deps['test']['hdmf-common']),
                            expected)

        # test that the types are loaded
        types = self.ns_catalog.get_types('test.base.yaml')
        expected = ('TestData', 'TestContainer', 'TestTable')
        self.assertTupleEqual(types, expected)

        # test that the namespace is correct and the types_key is updated for test ns
        test_namespace = self.ns_catalog.get_namespace('test')
        expected = {
            'doc':
            'Test namespace',
            'schema': [{
                'namespace': 'hdmf-common',
                'my_data_types': ['Data', 'DynamicTable', 'Container']
            }, {
                'doc': 'This source module contains base data types.',
                'source': 'test.base.yaml',
                'title': 'Base data types'
            }],
            'name':
            'test',
            'full_name':
            'Test',
            'version':
            '0.1.0',
            'author': ['Test test'],
            'contact': ['*****@*****.**']
        }
        self.assertDictEqual(test_namespace, expected)

        # test that the def_key is updated for test ns
        test_data_spec = self.ns_catalog.get_spec('test', 'TestData')
        self.assertTrue('my_data_type_def' in test_data_spec)
        self.assertTrue('my_data_type_inc' in test_data_spec)

        # test that the def_key is maintained for hdmf-common
        data_spec = self.ns_catalog.get_spec('hdmf-common', 'Data')
        self.assertTrue('data_type_def' in data_spec)

    def test_load_namespaces_ext(self):
        namespace_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'test.namespace.yaml')
        self.ns_catalog.load_namespaces(namespace_path)

        ext_namespace_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            'test-ext.namespace.yaml')
        ext_namespace_deps = self.ns_catalog.load_namespaces(
            ext_namespace_path)

        # test that the dependencies are correct, including dependencies of the dependencies
        expected_deps = set([
            'TestData', 'TestContainer', 'TestTable', 'Container', 'Data',
            'DynamicTable', 'ElementIdentifiers', 'VectorData'
        ])
        self.assertSetEqual(set(ext_namespace_deps['test-ext']['test']),
                            expected_deps)

    def test_load_namespaces_bad_path(self):
        namespace_path = 'test.namespace.yaml'
        msg = "namespace file 'test.namespace.yaml' not found"
        with self.assertRaisesWith(IOError, msg):
            self.ns_catalog.load_namespaces(namespace_path)

    def test_load_namespaces_twice(self):
        namespace_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'test.namespace.yaml')
        namespace_deps1 = self.ns_catalog.load_namespaces(namespace_path)
        namespace_deps2 = self.ns_catalog.load_namespaces(namespace_path)
        self.assertDictEqual(namespace_deps1, namespace_deps2)