Commit 68ca023b authored by Federico Vaga's avatar Federico Vaga

tst: allow multiple slot tests

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 857520ef
# SPDX-FileCopyrightText: 2020 CERN (home.cern)
# SPDX-FileCopyrightText: 2023 CERN (home.cern)
#
# SPDX-License-Identifier: LGPL-2.1-or-later
......
......@@ -45,18 +45,27 @@ def fmcfd_id_from_slot(slot):
fd_id = int(f.read().strip().split("-")[1], 16)
return fd_id
@pytest.fixture(scope="session")
def fd_id(request):
return request.param
def pytest_generate_tests(metafunc):
if "fd_id" in metafunc.fixturenames:
metafunc.parametrize("fd_id", pytest.fd_id)
@pytest.fixture(scope="function")
def fmcfd():
fd = FmcFineDelay(pytest.fd_id)
def fmcfd(fd_id):
fd = FmcFineDelay(fd_id)
for ch in fd.chan:
ch.disable()
yield fd
for chan in fd.chan:
chan.disable()
def pytest_addoption(parser):
parser.addoption("--fd-id", type=lambda x : int(x, 16),
default=None, help="Fmc Fine-Delay Linux Identifier")
parser.addoption("--slot", type=valid_slot_type,
parser.addoption("--fd-id", type=lambda x : int(x, 16), action='append',
default=[], help="Fmc Fine-Delay Linux Identifier")
parser.addoption("--slot", type=valid_slot_type, action='append',
default=None, help="Fmc Fine-Delay absolute slot (works only for SPEC and SVEC)")
parser.addoption("--channel", type=int, default=[],
action="append", choices=range(FmcFineDelay.CHANNEL_NUMBER),
......@@ -64,12 +73,14 @@ def pytest_addoption(parser):
def pytest_configure(config):
pytest.fd_id = config.getoption("--fd-id")
if pytest.fd_id is None:
if len(pytest.fd_id) == 0:
pytest.slot = config.getoption("--slot")
if pytest.slot is None:
if len(pytest.slot) == 0:
print("Missing argument --fd-id or --slot")
raise Exception()
pytest.fd_id = fmcfd_id_from_slot(pytest.slot)
pytest.fd_id = []
for slot in pytest.slot:
pytest.fd_id.append(fmcfd_id_from_slot(slot))
pytest.channels = config.getoption("--channel")
if len(pytest.channels) == 0:
pytest.channels = range(FmcFineDelay.CHANNEL_NUMBER)
......@@ -10,9 +10,8 @@ from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime
@pytest.fixture(scope="function", params=range(0, FmcFineDelay.CHANNEL_NUMBER))
def fmcfd_chan(request):
fd = FmcFineDelay(pytest.fd_id)
yield fd.chan[request.param]
def fmcfd_chan(request, fmcfd):
yield fmcfd.chan[request.param]
class TestFmcfdGetterSetter(object):
......
......@@ -11,16 +11,6 @@ from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime
import random
@pytest.fixture(scope="function")
def fmcfd():
fd = FmcFineDelay(pytest.fd_id)
for ch in fd.chan:
ch.disable()
yield fd
for ch in fd.chan:
ch.disable()
@pytest.fixture(scope="function", params=pytest.channels)
def fmcfd_chan(request, fmcfd):
yield fmcfd.chan[request.param]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment