From cf55dcd223e0070190d6a45e7615de3523b3f5a8 Mon Sep 17 00:00:00 2001 From: Kai-Uwe Hermann Date: Mon, 20 Nov 2023 10:50:25 +0100 Subject: [PATCH] Use temporary directory as serial port for config-sil-gen-pm test Signed-off-by: Kai-Uwe Hermann --- tests/core_tests/config_tests.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/core_tests/config_tests.py b/tests/core_tests/config_tests.py index a724dfcec3..729889fe95 100644 --- a/tests/core_tests/config_tests.py +++ b/tests/core_tests/config_tests.py @@ -3,12 +3,20 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest +from copy import deepcopy import logging +from pathlib import Path import pytest +import subprocess +from tempfile import mkdtemp +from typing import Dict from everest.testing.core_utils.fixtures import * from everest.testing.core_utils.everest_core import EverestCore +from everest.testing.core_utils.configuration.everest_configuration_visitors.everest_configuration_visitor import \ + EverestConfigAdjustmentVisitor + @pytest.mark.everest_core_config('config-example.yaml') @pytest.mark.asyncio @@ -45,10 +53,29 @@ async def test_start_config_sil_energy_management(everest_core: EverestCore): everest_core.start() +class EverestCoreConfigSilGenPmConfigurationVisitor(EverestConfigAdjustmentVisitor): + def __init__(self): + self.temporary_directory = mkdtemp() + self.serial_port_0 = Path(self.temporary_directory) / 'serial_port_0' + self.serial_port_1 = Path(self.temporary_directory) / 'serial_port_1' + + def adjust_everest_configuration(self, everest_config: Dict): + adjusted_config = deepcopy(everest_config) + + adjusted_config["active_modules"]["serial_comm_hub"]["config_implementation"]["main"]["serial_port"] = self.serial_port_0.as_posix() + + return adjusted_config + + @pytest.mark.everest_core_config('config-sil-gen-pm.yaml') +@pytest.mark.everest_config_adaptations(EverestCoreConfigSilGenPmConfigurationVisitor()) @pytest.mark.asyncio -async def test_start_config_sil_gen_pm(everest_core: EverestCore): +async def test_start_config_sil_gen_pm(request, everest_core: EverestCore): logging.info(">>>>>>>>> test_start_config_sil_gen_pm <<<<<<<<<") + config_adaptation = request.node.get_closest_marker( + 'everest_config_adaptations').args[0] + logging.info(f"config_adaptation: {config_adaptation.serial_port_0}") + # serial_port_process = subprocess.Popen(['socat', 'PTY,link=/tmp/serial_port', 'PTY,link=/tmp/serial_port_1']) everest_core.start() @@ -94,6 +121,7 @@ async def test_start_config_sil_two_evse(everest_core: EverestCore): logging.info(">>>>>>>>> test_start_config_sil_two_evse <<<<<<<<<") everest_core.start() + @pytest.mark.everest_core_config('config-sil.yaml') @pytest.mark.asyncio async def test_start_config_sil(everest_core: EverestCore):