Skip to content

Commit

Permalink
Refactor config_tests to automatically run all configs found
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass committed Dec 22, 2023
1 parent 6486a49 commit bb8128c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 83 deletions.
23 changes: 21 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
# Copyright Pionix GmbH and Contributors to EVerest

from pathlib import Path
import pytest

import os

def pytest_addoption(parser):
parser.addoption("--everest-prefix", action="store", default="../build/dist",
help="everest prefix path; default = '../build/dist'")


def pytest_configure(config):
everest_prefix = config.getoption('--everest-prefix')
everest_config_path = Path(everest_prefix) / 'etc/everest'
everest_configs = [path for path in everest_config_path.iterdir(
) if path.name.startswith('config-') and path.name.endswith('yaml')]
pytest.everest_configs = {}
pytest.everest_configs['params'] = []
pytest.everest_configs['ids'] = []
for config_path in everest_configs:
config_id = config_path.stem
if config_id == 'config-sil-gen-pm':
# skip
continue
pytest.everest_configs['params'].append(config_path)
pytest.everest_configs['ids'].append(config_id)
96 changes: 15 additions & 81 deletions tests/core_tests/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,12 @@
EverestConfigAdjustmentVisitor


@pytest.mark.everest_core_config('config-example.yaml')
@pytest.mark.asyncio
async def test_start_config_example(everest_core: EverestCore):
logging.info(">>>>>>>>> test_start_config_example <<<<<<<<<")
everest_core.start()


@pytest.mark.everest_core_config('config-sil-dc-sae-v2g.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_dc_sae_v2g(everest_core: EverestCore):
logging.info(">>>>>>>>> test_start_config_sil_dc_sae_v2g <<<<<<<<<")
everest_core.start()


@pytest.mark.everest_core_config('config-sil-dc-sae-v2h.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_dc_sae_v2h(everest_core: EverestCore):
logging.info(">>>>>>>>> test_start_config_sil_dc_sae_v2h <<<<<<<<<")
everest_core.start()


@pytest.mark.everest_core_config('config-sil-dc.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_dc(everest_core: EverestCore):
logging.info(">>>>>>>>> test_start_config_sil_dc <<<<<<<<<")
everest_core.start()


@pytest.mark.everest_core_config('config-sil-energy-management.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_energy_management(everest_core: EverestCore):
logging.info(">>>>>>>>> test_config_sil_energy_management <<<<<<<<<")
everest_core.start()


class EverestCoreConfigSilGenPmConfigurationVisitor(EverestConfigAdjustmentVisitor):
def __init__(self):
self.temporary_directory = mkdtemp()
self.serial_port_0, self.serial_port_1 = pty.openpty()
self.serial_port_0_name = os.ttyname(self.serial_port_0) # FIXME: cleanup socket after test
# FIXME: cleanup socket after test
self.serial_port_0_name = os.ttyname(self.serial_port_0)

def adjust_everest_configuration(self, everest_config: Dict):
adjusted_config = deepcopy(everest_config)
Expand All @@ -77,51 +43,19 @@ async def test_start_config_sil_gen_pm(everest_core: EverestCore):
everest_core.start()


@pytest.mark.everest_core_config('config-sil-ocpp-custom-extension.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_ocpp_custom_extension(everest_core: EverestCore):
logging.info(
">>>>>>>>> test_start_config_sil_ocpp_custom_extension <<<<<<<<<")
everest_core.start()
class TestConfigsInDirectory:
@pytest.fixture(params=pytest.everest_configs['params'], ids=pytest.everest_configs['ids'])
def core_config(self, request) -> EverestEnvironmentCoreConfiguration:
everest_prefix = Path(request.config.getoption("--everest-prefix"))

everest_config_path = request.param

@pytest.mark.everest_core_config('config-sil-ocpp-pnc.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_ocpp_pnc(everest_core: EverestCore):
logging.info(">>>>>>>>> test_start_config_sil_ocpp_pnc <<<<<<<<<")
everest_core.start()


@pytest.mark.everest_core_config('config-sil-ocpp.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_ocpp(everest_core: EverestCore):
logging.info(">>>>>>>>> test_start_config_sil_ocpp <<<<<<<<<")
everest_core.start()


@pytest.mark.everest_core_config('config-sil-ocpp201.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_ocpp201(everest_core: EverestCore):
logging.info(">>>>>>>>> test_start_config_sil_ocpp201 <<<<<<<<<")
everest_core.start()

return EverestEnvironmentCoreConfiguration(
everest_core_path=everest_prefix,
template_everest_config_path=everest_config_path,
)

@pytest.mark.everest_core_config('config-sil-two-evse-dc.yaml')
@pytest.mark.asyncio
async def test_start_config_sil_two_evse_dc(everest_core: EverestCore):
logging.info(">>>>>>>>> test_start_config_sil_two_evse_dc <<<<<<<<<")
everest_core.start()


@pytest.mark.everest_core_config('config-sil-two-evse.yaml')
@pytest.mark.asyncio
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):
logging.info(">>>>>>>>> test_start_config_sil <<<<<<<<<")
everest_core.start()
@pytest.mark.asyncio
async def test_config(self, everest_core: EverestCore):
logging.info(">>>>>>>>> test_config <<<<<<<<<")
everest_core.start()
1 change: 1 addition & 0 deletions tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ log_level=debug
asyncio_mode=strict
markers =
everest_core_config: marks tests using a specific config (deselect with '-m "not everest_core_config"')
everest_config_adaptions: modify config for a specific testcase

0 comments on commit bb8128c

Please sign in to comment.