Ejemplo n.º 1
0
    def test_minimum_requirement_only(self):
        collection = ComponentCollection()

        component1 = Component('Test1', {'requires': {'Test2': '[1.0.0,'}, 'version': '1.5.3'}, TypeCollection())
        component2 = Component('Test2', {'requires': {'Test1': '[1.0.0, 2.0.0)'}, 'version': '3.0.0'}, TypeCollection())

        collection.add(component1)
        collection.add(component2)
        collection.check_dependencies()
Ejemplo n.º 2
0
    def test_exception_when_requirements_are_not_met(self):
        collection = ComponentCollection()

        component1 = Component('Test1', {'requires': {'Test2': '[1.0.0, 2.0.0)'}, 'version': '1.5.3'}, TypeCollection())
        component2 = Component('Test2', {'requires': {'Test1': '[1.0.0, 2.0.0)'}, 'version': '2.0.0'}, TypeCollection())

        collection.add(component1)
        collection.add(component2)
        self.assertRaises(Exception, collection.check_dependencies)
Ejemplo n.º 3
0
 def _load_component_config(self, component_name):
     if component_name not in self._components:
         component_config_file = f'{self._component_dir(component_name)}/config.json'
         with open(component_config_file, "r") as file:
             component_config = json.load(file)
         self.add_component(
             Component(component_name, component_config, self.types))
Ejemplo n.º 4
0
def expand_runtime_events(owner: CGlue, project_config):
    runtime_config = project_config['runtime']
    runtime_component = Component.create_empty_config('Runtime')
    runtime_component['source_files'] = []

    runtime_runnables = runtime_config['runnables']

    runtime_component['ports'] = {
        event: {
            'port_type': 'Event'
        }
        for event in runtime_runnables
    }
    event_connections = ({
        'provider': {
            'short_name': f'Runtime/{event}',
            'component': 'Runtime',
            'port': event
        },
        'consumers': handlers
    } for event, handlers in runtime_runnables.items())

    owner.add_component(Component('Runtime', runtime_component, owner.types))
    runtime_config['port_connections'] += event_connections
Ejemplo n.º 5
0
def create_runnable_ports(owner: CGlue, component: Component):
    for runnable_name, runnable_data in component.config['runnables'].items():
        if type(runnable_data) is str:
            type_data = owner.types.get(runnable_data)
            if type_data.category.name != TypeCollection.FUNC_PTR:
                raise ValueError(
                    'Runnable config must either be an object or the name of a function pointer type'
                )
            runnable_data = {
                'return_type': type_data.data['return_type'],
                'arguments': type_data.data['arguments']
            }

        if component.config['multiple_instances']:
            args = OrderedDict()

            runnable_arguments = runnable_data.get('arguments', {})
            try:
                instance_type = runnable_arguments["instance"]["data_type"]
                if instance_type != component.instance_type:
                    raise TypeError(
                        f'Runnable has argument named "instance" but '
                        f'its type ({instance_type.name}) does not match instance type'
                    )
            except KeyError:
                args['instance'] = {
                    'data_type': component.instance_type,
                    'direction': 'inout'
                }

            args.update(runnable_arguments)
            runnable_data['arguments'] = args

        component.config['ports'][runnable_name] = {
            'port_type': 'Runnable',
            **runnable_data
        }
Ejemplo n.º 6
0
 def test_default_version_is_added_if_missing(self):
     config = {}
     component = Component('Test', config, TypeCollection())
     self.assertEqual(Version('1.0.0'), component.version)