Commit a11ec120 authored by Federico Vaga's avatar Federico Vaga

ci: check python style

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 4c8be336
...@@ -13,6 +13,17 @@ include: ...@@ -13,6 +13,17 @@ include:
file: file:
- 'edl-gitlab-ci.yml' - 'edl-gitlab-ci.yml'
python-style:
variables:
FF_KUBERNETES_HONOR_ENTRYPOINT: 1 # Make Gitlab K8s executors to respect entrypoint in Acc-Py images, https://cern.service-now.com/service-portal?id=ticket&table=incident&n=INC3570437
stage: analyse
image:
name: gitlab-registry.cern.ch/acc-co/devops/python/distribution-images/acc-py_cc7:pro
before_script:
- pip install pycodestyle
script:
- pycodestyle --ignore=E501,W503 pytest/ # W503 because I think is bug in pycodestyle
cppcheck: cppcheck:
stage: analyse stage: analyse
image: image:
......
...@@ -28,12 +28,12 @@ def id_from_slot(slot): ...@@ -28,12 +28,12 @@ def id_from_slot(slot):
if int(dynslot) == carrier_slot: if int(dynslot) == carrier_slot:
break break
pciid = f"0000:{pciid}" pciid = f"0000:{pciid}"
pathfmc = list(Path("/sys/bus/pci/devices").joinpath(pciid) \ pathfmc = list(Path("/sys/bus/pci/devices").joinpath(pciid)
.glob(f"spec-*/id:*/fmc-fdelay-tdc.*.auto/fmc-slot-*.{mezzanine_slot}")) .glob(f"spec-*/id:*/fmc-fdelay-tdc.*.auto/fmc-slot-*.{mezzanine_slot}"))
elif carrier_bus == "VME": elif carrier_bus == "VME":
pathfmc = list(Path("/sys/bus/vme/devices").joinpath(f"slot.{carrier_slot:02d}") \ pathfmc = list(Path("/sys/bus/vme/devices").joinpath(f"slot.{carrier_slot:02d}")
.joinpath(f"vme.{carrier_slot:02d}") \ .joinpath(f"vme.{carrier_slot:02d}")
.glob(f"svec-*/svec-*/id:*/fmc-fdelay-tdc.*.auto/fmc-slot-*.{mezzanine_slot}")) .glob(f"svec-*/svec-*/id:*/fmc-fdelay-tdc.*.auto/fmc-slot-*.{mezzanine_slot}"))
else: else:
raise ValueError() raise ValueError()
...@@ -45,21 +45,24 @@ def id_from_slot(slot): ...@@ -45,21 +45,24 @@ def id_from_slot(slot):
dev_id = int(f.read().strip().split("-")[1], 16) dev_id = int(f.read().strip().split("-")[1], 16)
return dev_id return dev_id
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
if "dev_id" in metafunc.fixturenames: if "dev_id" in metafunc.fixturenames:
metafunc.parametrize("dev_id", pytest.dev_id) metafunc.parametrize("dev_id", pytest.dev_id)
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def fmcfd(dev_id): def fmcfd(dev_id):
fd = FmcFineDelay(dev_id) fd = FmcFineDelay(dev_id)
for ch in fd.chan: for ch in fd.chan:
ch.disable() ch.disable()
yield fd yield fd
for chan in fd.chan: for chan in fd.chan:
chan.disable() chan.disable()
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption("--id", type=lambda x : int(x, 16), action='append', parser.addoption("--id", type=lambda x: int(x, 16), action='append',
default=[], help="Fmc Fine-Delay Linux Identifier") default=[], help="Fmc Fine-Delay Linux Identifier")
parser.addoption("--slot", type=valid_slot_type, action='append', parser.addoption("--slot", type=valid_slot_type, action='append',
default=[], help="Fmc Fine-Delay absolute slot (works only for SPEC and SVEC)") default=[], help="Fmc Fine-Delay absolute slot (works only for SPEC and SVEC)")
...@@ -67,6 +70,7 @@ def pytest_addoption(parser): ...@@ -67,6 +70,7 @@ def pytest_addoption(parser):
action="append", choices=range(FmcFineDelay.CHANNEL_NUMBER), action="append", choices=range(FmcFineDelay.CHANNEL_NUMBER),
help="Channel(s) to be used for acquisition tests. Default all channels") help="Channel(s) to be used for acquisition tests. Default all channels")
def pytest_configure(config): def pytest_configure(config):
pytest.dev_id = config.getoption("--id") pytest.dev_id = config.getoption("--id")
if len(pytest.dev_id) == 0: if len(pytest.dev_id) == 0:
......
...@@ -8,17 +8,17 @@ import random ...@@ -8,17 +8,17 @@ import random
from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime
@pytest.fixture(scope="function", params=range(0, FmcFineDelay.CHANNEL_NUMBER)) @pytest.fixture(scope="function", params=range(0, FmcFineDelay.CHANNEL_NUMBER))
def fmcfd_chan(request, fmcfd): def fmcfd_chan(request, fmcfd):
yield fmcfd.chan[request.param] yield fmcfd.chan[request.param]
class TestFmcfdGetterSetter(object): class TestFmcfdGetterSetter(object):
def test_disable(self, fmcfd): def test_disable(self, fmcfd):
for chan in fmcfd.chan: for chan in fmcfd.chan:
chan.disable() chan.disable()
assert chan.disabled == True assert chan.disabled is True
@pytest.mark.parametrize("enable", [True, False]) @pytest.mark.parametrize("enable", [True, False])
def test_tdc_disable_input(self, fmcfd, enable): def test_tdc_disable_input(self, fmcfd, enable):
...@@ -51,7 +51,7 @@ class TestFmcfdGetterSetter(object): ...@@ -51,7 +51,7 @@ class TestFmcfdGetterSetter(object):
(FmcFineDelay.FmcFineDelayChannel.OUT_PULSE_DELAY_MAX_WIDTH_PS, (FmcFineDelay.FmcFineDelayChannel.OUT_PULSE_DELAY_MAX_WIDTH_PS,
FmcFineDelay.FmcFineDelayChannel.OUT_PULSE_DELAY_MAX_PERIOD_PS + 1, FmcFineDelay.FmcFineDelayChannel.OUT_PULSE_DELAY_MAX_PERIOD_PS + 1,
1), 1),
]) ])
def test_pulse_delay_invalid(self, fmcfd_chan, width, period, count): def test_pulse_delay_invalid(self, fmcfd_chan, width, period, count):
"""The pulse generation can't work with invalid parameters""" """The pulse generation can't work with invalid parameters"""
with pytest.raises(OSError): with pytest.raises(OSError):
...@@ -76,9 +76,9 @@ class TestFmcfdGetterSetter(object): ...@@ -76,9 +76,9 @@ class TestFmcfdGetterSetter(object):
(FmcFineDelay.FmcFineDelayChannel.OUT_PULSE_MAX_WIDTH_PS, (FmcFineDelay.FmcFineDelayChannel.OUT_PULSE_MAX_WIDTH_PS,
FmcFineDelay.FmcFineDelayChannel.OUT_PULSE_MAX_PERIOD_PS + 1, FmcFineDelay.FmcFineDelayChannel.OUT_PULSE_MAX_PERIOD_PS + 1,
1), 1),
]) ])
def test_pulse_generate_invalid(self, fmcfd_chan, width, period, count): def test_pulse_generate_invalid(self, fmcfd_chan, width, period, count):
"""The pulse generation can't work with invalid parameters""" """The pulse generation can't work with invalid parameters"""
with pytest.raises(OSError): with pytest.raises(OSError):
fmcfd_chan.pulse_generate(FmcFineDelayTime(1, 0, 0), fmcfd_chan.pulse_generate(FmcFineDelayTime(1, 0, 0),
width, period, count) width, period, count)
...@@ -57,14 +57,14 @@ class TestFmcfdLoop(object): ...@@ -57,14 +57,14 @@ class TestFmcfdLoop(object):
@pytest.mark.parametrize("period_ps", [400000]) @pytest.mark.parametrize("period_ps", [400000])
def test_output_flush(self, fmcfd, fmcfd_chan, fmcfd_tdc, period_ps): def test_output_flush(self, fmcfd, fmcfd_chan, fmcfd_tdc, period_ps):
start = fmcfd.time + FmcFineDelayTime(0, 500000, 0) start = fmcfd.time + FmcFineDelayTime(0, 500000, 0)
fmcfd_chan.pulse_generate(start, int(period_ps / 2), period_ps, 1) fmcfd_chan.pulse_generate(start, int(period_ps / 2), period_ps, 1)
assert len(fmcfd_tdc.poll(2000)) > 0 assert len(fmcfd_tdc.poll(2000)) > 0
fmcfd_tdc.flush() fmcfd_tdc.flush()
assert len(fmcfd_tdc.poll(1000)) == 0 assert len(fmcfd_tdc.poll(1000)) == 0
@pytest.mark.parametrize("count, period_ps", [(i + 1, 1000000) for i in range(15)] + @pytest.mark.parametrize("count, period_ps",
[(100, 4500000000), [(i + 1, 1000000) for i in range(15)]
(MAX_COUNT, 4500000000)]) + [(100, 4500000000), (MAX_COUNT, 4500000000)])
def test_output_counter(self, fmcfd, fmcfd_chan, fmcfd_tdc, count, period_ps): def test_output_counter(self, fmcfd, fmcfd_chan, fmcfd_tdc, count, period_ps):
"""In pulse mode, the Fine-Delay generates the exact number of """In pulse mode, the Fine-Delay generates the exact number of
required pulses and we are able to read them all from the input required pulses and we are able to read them all from the input
...@@ -97,13 +97,10 @@ class TestFmcfdLoop(object): ...@@ -97,13 +97,10 @@ class TestFmcfdLoop(object):
prev_ts = ts[i] prev_ts = ts[i]
del ts del ts
@pytest.mark.parametrize("start_rel",
@pytest.mark.parametrize("start_rel", [FmcFineDelayTime(0, random.randrange(1, 125000000), [FmcFineDelayTime(0, random.randrange(1, 125000000), 0) for i in range(50)]
0) for i in range(50)] + + [FmcFineDelayTime(1, random.randrange(1, 125000000), 0) for i in range(5)]
[FmcFineDelayTime(1, random.randrange(1, 125000000), + [FmcFineDelayTime(2, random.randrange(1, 125000000), 0) for i in range(5)])
0) for i in range(5)] +
[FmcFineDelayTime(2, random.randrange(1, 125000000),
0) for i in range(5)])
@pytest.mark.parametrize("wr", [False, True]) @pytest.mark.parametrize("wr", [False, True])
def test_output_input_start(self, fmcfd_chan, fmcfd_tdc, wr, start_rel): def test_output_input_start(self, fmcfd_chan, fmcfd_tdc, wr, start_rel):
""" """
...@@ -123,15 +120,16 @@ class TestFmcfdLoop(object): ...@@ -123,15 +120,16 @@ class TestFmcfdLoop(object):
ts = fmcfd_tdc.read(count, os.O_NONBLOCK) ts = fmcfd_tdc.read(count, os.O_NONBLOCK)
assert len(ts) == count assert len(ts) == count
assert start.seconds == ts[0].seconds assert start.seconds == ts[0].seconds
assert ts[0].coarse - start.coarse <= 3 # there is < 3ns cable assert ts[0].coarse - start.coarse <= 3 # there is < 3ns cable
@pytest.mark.parametrize("period_ps",
@pytest.mark.parametrize("period_ps", [random.randrange(1000000, 10000000) for x in range(128)] + [random.randrange(1000000, 10000000) for x in range(128)]
[random.randrange(10000000, 100000000) for x in range(64)] + + [random.randrange(10000000, 100000000) for x in range(64)]
[random.randrange(100000000, 1000000000) for x in range(32)] + + [random.randrange(100000000, 1000000000) for x in range(32)]
[random.randrange(1000000000, 10000000000) for x in range(16)] + + [random.randrange(1000000000, 10000000000) for x in range(16)]
[random.randrange(10000000000, 100000000000) for x in range(8)] + + [random.randrange(10000000000, 100000000000) for x in range(8)]
[random.randrange(100000000000, 1000000000000) for x in range(4)]) + [random.randrange(100000000000, 1000000000000) for x in range(4)]
)
@pytest.mark.parametrize("count", [15]) @pytest.mark.parametrize("count", [15])
def test_output_period(self, fmcfd_chan, fmcfd_tdc, period_ps, count): def test_output_period(self, fmcfd_chan, fmcfd_tdc, period_ps, count):
""" """
...@@ -149,7 +147,7 @@ class TestFmcfdLoop(object): ...@@ -149,7 +147,7 @@ class TestFmcfdLoop(object):
assert len(ts) == count assert len(ts) == count
prev_ts = None prev_ts = None
for i in range(len(ts)): for i in range(len(ts)):
if prev_ts is not None: if prev_ts is not None:
period_ts = ts[i] - prev_ts period_ts = ts[i] - prev_ts
period = FmcFineDelayTime.from_pico(period_ps) period = FmcFineDelayTime.from_pico(period_ps)
...@@ -158,8 +156,8 @@ class TestFmcfdLoop(object): ...@@ -158,8 +156,8 @@ class TestFmcfdLoop(object):
else: else:
diff = period_ts - period diff = period_ts - period
assert diff < FmcFineDelayTime(0, 1, 0), \ assert diff < FmcFineDelayTime(0, 1, 0), \
"period difference {:s}\n\tcurr: {:s}\n\tprev: {:s}\n\tperi: {:s}".format(str(diff), "period difference {:s}\n\tcurr: {:s}\n\tprev: {:s}\n\tperi: {:s}".format(str(diff),
str(ts[i]), str(ts[i]),
str(prev_ts), str(prev_ts),
str(period_ts)) str(period_ts))
prev_ts = ts[i] prev_ts = ts[i]
...@@ -5,6 +5,7 @@ SPDX-FileCopyrightText: 2020 CERN ...@@ -5,6 +5,7 @@ SPDX-FileCopyrightText: 2020 CERN
import pytest import pytest
class TestFmcfdTemperature(object): class TestFmcfdTemperature(object):
def test_temperature_read(self, fmcfd): def test_temperature_read(self, fmcfd):
......
...@@ -8,14 +8,15 @@ import random ...@@ -8,14 +8,15 @@ import random
import time import time
from PyFmcFineDelay import FmcFineDelayTime from PyFmcFineDelay import FmcFineDelayTime
class TestFmcfdTime(object): class TestFmcfdTime(object):
def test_whiterabbit_mode(self, fmcfd): def test_whiterabbit_mode(self, fmcfd):
"""It must be possible to toggle the White-Rabbit status""" """It must be possible to toggle the White-Rabbit status"""
fmcfd.whiterabbit_mode = True fmcfd.whiterabbit_mode = True
assert fmcfd.whiterabbit_mode == True assert fmcfd.whiterabbit_mode is True
fmcfd.whiterabbit_mode = False fmcfd.whiterabbit_mode = False
assert fmcfd.whiterabbit_mode == False assert fmcfd.whiterabbit_mode is False
def test_time_set_fail_wr(self, fmcfd): def test_time_set_fail_wr(self, fmcfd):
"""Time can't be changed when White-Rabbit is enabled""" """Time can't be changed when White-Rabbit is enabled"""
......
...@@ -10,6 +10,7 @@ import time ...@@ -10,6 +10,7 @@ import time
import os import os
from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime
@pytest.fixture(scope="function", params=pytest.channels) @pytest.fixture(scope="function", params=pytest.channels)
def fmcfd_tdc(request): def fmcfd_tdc(request):
fd = FmcFineDelay(pytest.fd_id) fd = FmcFineDelay(pytest.fd_id)
...@@ -65,7 +66,7 @@ class TestFmcfdInput(object): ...@@ -65,7 +66,7 @@ class TestFmcfdInput(object):
import pdb import pdb
pdb.set_trace() pdb.set_trace()
for i in range(len(ts)): for i in range(len(ts)):
if prev_ts is not None: if prev_ts is not None:
assert ts[i].seq_id == prev_ts.seq_id + 1 assert ts[i].seq_id == prev_ts.seq_id + 1
diff = float(ts[i]) - float(prev_ts) diff = float(ts[i]) - float(prev_ts)
......
...@@ -8,6 +8,7 @@ import random ...@@ -8,6 +8,7 @@ import random
import time import time
from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime
@pytest.fixture(scope="function", params=pytest.channels) @pytest.fixture(scope="function", params=pytest.channels)
def fmcfd_chan(request): def fmcfd_chan(request):
fd = FmcFineDelay(pytest.fd_id) fd = FmcFineDelay(pytest.fd_id)
...@@ -29,18 +30,18 @@ class TestFmcfdOutput(object): ...@@ -29,18 +30,18 @@ class TestFmcfdOutput(object):
print(" period : {:d}ps".format(period)) print(" period : {:d}ps".format(period))
print(" count : {:d}".format(count)) print(" count : {:d}".format(count))
@pytest.mark.parametrize("width",[50000, # 50ns @pytest.mark.parametrize("width", [50000, # 50ns
60000, # 60ns 60000, # 60ns
70000, # 70ns 70000, # 70ns
80000, # 80ns 80000, # 80ns
90000, # 90ns 90000, # 90ns
500000, # 500ns 500000, # 500ns
1000000, # 1us 1000000, # 1us
500000000, # 500us 500000000, # 500us
1000000000, # 1ms 1000000000, # 1ms
500000000000, # 500ms 500000000000, # 500ms
1000000000000, # 1s 1000000000000, # 1s
]) ])
@pytest.mark.parametrize("count", [1, 3]) @pytest.mark.parametrize("count", [1, 3])
def test_pulse_width(self, capsys, fmcfd_chan, width, count): def test_pulse_width(self, capsys, fmcfd_chan, width, count):
with capsys.disabled(): with capsys.disabled():
...@@ -84,7 +85,7 @@ class TestFmcfdOutput(object): ...@@ -84,7 +85,7 @@ class TestFmcfdOutput(object):
while True: while True:
fmcfd_chan.pulse_delay(delay, 250000, 500000, 1) fmcfd_chan.pulse_delay(delay, 250000, 500000, 1)
time.sleep(1 + delay/1000000000000.0) time.sleep(1 + delay / 1000000000000.0)
ret = self.__process_outcome(fmcfd_chan.idx + 1, delay, 250000, 500000, 1) ret = self.__process_outcome(fmcfd_chan.idx + 1, delay, 250000, 500000, 1)
if ret in ["y", "n", "q"]: if ret in ["y", "n", "q"]:
break break
...@@ -92,18 +93,18 @@ class TestFmcfdOutput(object): ...@@ -92,18 +93,18 @@ class TestFmcfdOutput(object):
pytest.skip("Quit test") pytest.skip("Quit test")
assert ret == "y" assert ret == "y"
@pytest.mark.parametrize("width",[250000, # 250ns @pytest.mark.parametrize("width", [250000, # 250ns
260000, # 260ns 260000, # 260ns
270000, # 270ns 270000, # 270ns
280000, # 280ns 280000, # 280ns
290000, # 290ns 290000, # 290ns
500000, # 500ns 500000, # 500ns
1000000, # 1us 1000000, # 1us
500000000, # 500us 500000000, # 500us
1000000000, # 1ms 1000000000, # 1ms
500000000000, # 500ms 500000000000, # 500ms
1000000000000, # 1s 1000000000000, # 1s
]) ])
@pytest.mark.parametrize("count", [1, 3]) @pytest.mark.parametrize("count", [1, 3])
def test_pulse_delay_width(self, capsys, fmcfd_chan, width, count): def test_pulse_delay_width(self, capsys, fmcfd_chan, width, count):
fmcfd_chan.dev.tdc.enable_input = True fmcfd_chan.dev.tdc.enable_input = True
...@@ -119,7 +120,7 @@ class TestFmcfdOutput(object): ...@@ -119,7 +120,7 @@ class TestFmcfdOutput(object):
while True: while True:
fmcfd_chan.pulse_delay(width, width, 500000, 1) fmcfd_chan.pulse_delay(width, width, 500000, 1)
time.sleep(1 + delay/1000000000000.0) time.sleep(1 + delay / 1000000000000.0)
ret = self.__process_outcome(fmcfd_chan.idx + 1, 600000, width, 500000, 1) ret = self.__process_outcome(fmcfd_chan.idx + 1, 600000, width, 500000, 1)
if ret in ["y", "n", "q"]: if ret in ["y", "n", "q"]:
break break
......
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