Skip to content

Commit

Permalink
Use temporary directory as serial port for config-sil-gen-pm test
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass committed Nov 20, 2023
1 parent 00e9fd7 commit cf55dcd
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/core_tests/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 10 in tests/core_tests/config_tests.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/core_tests/config_tests.py#L10

Consider possible security implications associated with the subprocess module.

Check warning on line 10 in tests/core_tests/config_tests.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/core_tests/config_tests.py#L10

Unused 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
Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit cf55dcd

Please sign in to comment.