##########################################################################
# Copyright (c) 2010-2022 Robert Bosch GmbH
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
##########################################################################

# Code generated by "pykitest". DO NOT EDIT. Called command:
# pykitest {% for args in sys_args[1:] %}{{args}} {% endfor %}

{% for aux_con, module_path in module_imports.items() %}
from {{module_path}} import {{aux_con}}{% endfor %}


import pytest
import logging

{% set auxiliaries = dict_item.auxiliaries %}
{% for aux, value in auxiliaries.items() %}
{% set aux_type = value.type.split(':')[-1] %}
@pytest.fixture(scope="session")
def {{aux}}():
    try:
        {%- if 'connectors' in dict_item.auxiliaries[aux] %}
        {%- for con_key, con_value in dict_item.auxiliaries[aux].connectors.items() %}
        {%- set com_connector_type = dict_item.connectors[con_value].type.split(':')[-1] %}
        {%- set connector_config = dict_item.connectors[con_value].config%}
        {{con_key}} = {{com_connector_type}}(name="{{con_value}}"{%- if connector_config %}
        {%- for channel_config_key, channel_config_value in connector_config.items() %},
        {{channel_config_key}}={{channel_config_value|format_value}}{% endfor %}{%- endif %}){% endfor %}{% endif %}
        {{aux}} = {{aux_type}}(
        {%- if dict_item.auxiliaries[aux].connectors %}
        {%- for con_key, con_value in dict_item.auxiliaries[aux].connectors.items() %}
        {{con_key}} = {{con_key}},{% endfor %}{%- endif %}
        {%- if value.config %}
        {%- for config_key, config_value in value.config.items() %}
            {{config_key}} = {{config_value|format_value}},{% endfor %}{%- endif %})
        {{aux}}.start()
        {{aux}}.create_instance()
    except Exception:
        logging.exception("something bad happened")
    yield {{aux}}
    {{aux}}.delete_instance()
    {{aux}}.stop()
{% endfor %}
{% if proxy_aux_config %}
{% set proxy_connector =dict_item.connectors[proxy_aux_config.connectors.com].type.split(':')[-1] %}
{% set proxy_con_name = proxy_aux_config.connectors.com %}
{% set proxy_con_configs = dict_item.connectors[proxy_aux_config.connectors.com].config %}
{% set proxy_aux_name = proxy_aux_config.name %}
{% set proxy_aux_auxes = proxy_aux_config.config.aux_list %}
@pytest.fixture(scope="session")
def proxy({% for key, _ in auxiliaries.items() %} {{key}} ,{% endfor %}):
    channel = {{proxy_connector}}(name = "{{proxy_con_name}}" ,
        {% for config_key, config_value in proxy_con_configs.items() %}
    {{config_key}} = {{config_value|format_value}},{% endfor %})

    proxy_aux = ProxyAuxiliary(name="{{proxy_aux_name}}", com=channel,  aux_list={{proxy_aux_auxes}})
    proxy_aux.start()
    proxy_aux.create_instance()
    yield {% for key, _ in auxiliaries.items() %} {{key}} ,{% endfor %} proxy_aux
    proxy_aux.delete_instance()
    proxy_aux.stop()
{% endif %}
