Exemplo n.º 1
0
def spec_index_from_spec_file_index(spec_file_index):
    """Builds a :py:class:`SpecIndex` from a spec file index

    Goes through each spec path in each package of the given spec file index
    and parses them into objects. The objects are stored in a
    :py:class:`SpecIndex` before being returned.

    Duplicate Names are not allowed, even between different spec types
    and packages. Any duplicate names will be raised as a
    :py:exc:`DuplicateNameException`.

    Any other errors encountered during spec file processing will be returned
    as a list along with the :py:class:`SpecIndex`.

    :param spec_file_index: spec_file_index, see
        :py:func:`spec_file_index_from_packages_dict`
    :type spec_file_index: dict
    :returns: SpecIndex which contains all the loaded specs
        and a list of any errors encountered while loading the spec files
    :rtype: :py:class:`SpecIndex`, :py:obj:`list`
    :raises DuplicateNameException: when two interfaces have the same name
    """
    spec_index = SpecIndex()
    errors = []
    error_types = (
        InterfaceNameNotFoundException,
        DuplicateNameException,
        InvalidInterface,
        InvalidSemanticInterface,
        InvalidProvider
    )
    # First load and process CapabilityInterface's
    for package_name, package_dict in spec_file_index.items():
        interface_paths = package_dict['capability_interface']
        for path in interface_paths:
            try:
                interface = capability_interface_from_file_path(path)
                spec_index.add_interface(interface, path, package_name)
            except error_types as e:
                errors.append(e)
    # Then load the SemanticCapabilityInterface's
    for package_name, package_dict in spec_file_index.items():
        semantic_interface_paths = package_dict['semantic_capability_interface']
        for path in semantic_interface_paths:
            try:
                si = semantic_capability_interface_from_file_path(path)
                spec_index.add_semantic_interface(si, path, package_name)
            except error_types as e:
                errors.append(e)
    # Finally load the CapabilityProvider's
    for package_name, package_dict in spec_file_index.items():
        capability_provider_paths = package_dict['capability_provider']
        for path in capability_provider_paths:
            try:
                provider = capability_provider_from_file_path(path)
                spec_index.add_provider(provider, path, package_name)
            except error_types as e:
                errors.append(e)
    return spec_index, errors
Exemplo n.º 2
0
def test_capability_provider_from_file_path():
    default_checker = lambda x: None
    print()  # Keeps the output clean when doing nosetests -s
    for test_file, (checker, expected_exception, expected_exception_regex) in test_files_map.iteritems():
        checker = checker or default_checker
        print('running test on file ' + test_file)
        test_file_path = os.path.join(test_data_dir, test_file)
        with assert_raises_regex(expected_exception, expected_exception_regex):
            cp = provider.capability_provider_from_file_path(test_file_path)
            checker(cp)
Exemplo n.º 3
0
def test_capability_provider_from_file_path():
    default_checker = lambda x: None
    print()  # Keeps the output clean when doing nosetests -s
    for test_file, (checker, expected_exception,
                    expected_exception_regex) in test_files_map.iteritems():
        checker = checker or default_checker
        print('running test on file ' + test_file)
        test_file_path = os.path.join(test_data_dir, test_file)
        with assert_raises_regex(expected_exception, expected_exception_regex):
            cp = provider.capability_provider_from_file_path(test_file_path)
            checker(cp)
Exemplo n.º 4
0
 def capability_provider_loader(path, package_name, spec_index):
     provider = capability_provider_from_file_path(path)
     spec_index.add_provider(provider, path, package_name)
Exemplo n.º 5
0
 def capability_provider_loader(path, package_name, spec_index):
     provider = capability_provider_from_file_path(path)
     spec_index.add_provider(provider, path, package_name)