Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create linter.yml #637

Merged
merged 7 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ignore ruff format and --fix
6ffe0b87307b63cdfa5fced7220417462d46c946
3a3e89cc887fd631553efc6b0d4589b355fc5a81
6250161bf68ccefc61d2fa20c5eb86582e8d4b4f
7 changes: 7 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Linter
on: [pull_request]
jobs:
call-workflow:
uses: ISISComputingGroup/reusable-workflows/.github/workflows/linters.yml@main
with:
compare-branch: origin/master
6 changes: 2 additions & 4 deletions common_tests/DAQmx.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from time import sleep

from utils.channel_access import ChannelAccess
from utils.testing import get_running_lewis_and_ioc, assert_log_messages

from utils.testing import assert_log_messages, get_running_lewis_and_ioc

# Device prefix
DEVICE_PREFIX = "DAQMXTEST"
Expand All @@ -13,6 +12,7 @@ class DAQmxTests(object):
"""
General tests for the DAQmx.
"""

def setUp(self):
self.emulator, self._ioc = get_running_lewis_and_ioc(DEVICE_PREFIX, DEVICE_PREFIX)

Expand All @@ -33,5 +33,3 @@ def test_WHEN_emulator_disconnected_THEN_data_in_alarm_and_valid_on_reconnect(se
self.emulator.reconnect_device()
self.ca.assert_that_pv_alarm_is_not("DATA", ChannelAccess.Alarms.INVALID, timeout=5)
self.ca.assert_that_pv_value_is_changing("DATA", 1)


140 changes: 94 additions & 46 deletions common_tests/danfysik.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import time
from utils.test_modes import TestModes
from utils.channel_access import ChannelAccess
from utils.testing import skip_if_recsim, skip_if_devsim, get_running_lewis_and_ioc, parameterized_list
from utils.ioc_launcher import IOCRegister, MAX_TIME_TO_WAIT_FOR_IOC_TO_START, DEFAULT_IOC_START_TEXT

from parameterized import parameterized

from utils.channel_access import ChannelAccess
from utils.ioc_launcher import (
IOCRegister,
)
from utils.test_modes import TestModes
from utils.testing import (
get_running_lewis_and_ioc,
parameterized_list,
skip_if_devsim,
skip_if_recsim,
)

# Device prefix
DEVICE_PREFIX = "DFKPS_01"
EMULATOR_NAME = "danfysik"
Expand Down Expand Up @@ -84,14 +93,20 @@
@skip_if_recsim("Can not test disconnection in rec sim")
def test_GIVEN_device_not_connected_WHEN_pv_checked_THEN_pv_in_alarm(self, _, pv):
for id_prefix in self.id_prefixes:
self.ca.assert_that_pv_alarm_is_not("{}{}".format(id_prefix, pv), ChannelAccess.Alarms.INVALID, timeout=30)
self.ca.assert_that_pv_alarm_is_not(
"{}{}".format(id_prefix, pv), ChannelAccess.Alarms.INVALID, timeout=30
)

with self._lewis.backdoor_simulate_disconnected_device():
for id_prefix in self.id_prefixes:
self.ca.assert_that_pv_alarm_is("{}{}".format(id_prefix, pv), ChannelAccess.Alarms.INVALID, timeout=30)
self.ca.assert_that_pv_alarm_is(
"{}{}".format(id_prefix, pv), ChannelAccess.Alarms.INVALID, timeout=30
)

for id_prefix in self.id_prefixes:
self.ca.assert_that_pv_alarm_is_not("{}{}".format(id_prefix, pv), ChannelAccess.Alarms.INVALID, timeout=30)
self.ca.assert_that_pv_alarm_is_not(
"{}{}".format(id_prefix, pv), ChannelAccess.Alarms.INVALID, timeout=30
)

def test_WHEN_polarity_setpoint_is_set_THEN_readback_updates_with_set_value(self):
for id_prefix in self.id_prefixes:
Expand All @@ -101,8 +116,9 @@
def test_WHEN_polarity_setpoint_is_set_with_number_THEN_readback_updates_with_set_value(self):
for id_prefix in self.id_prefixes:
for pol_num, pol in enumerate(POLARITIES):
self.ca.assert_setting_setpoint_sets_readback(pol_num, "{}POL".format(id_prefix),
"{}POL:SP".format(id_prefix), pol)
self.ca.assert_setting_setpoint_sets_readback(
pol_num, "{}POL".format(id_prefix), "{}POL:SP".format(id_prefix), pol
)

@skip_if_recsim("Recsim is not set up properly for this test to work")
def test_WHEN_power_setpoint_is_set_THEN_readback_updates_with_set_value(self):
Expand All @@ -111,18 +127,23 @@
self.ca.assert_setting_setpoint_sets_readback(state, "{}POWER".format(id_prefix))

@skip_if_recsim("Recsim is not set up properly for this test to work")
def test_WHEN_power_setpoint_is_set_THEN_readback_updates_with_set_value(self):

Check failure on line 130 in common_tests/danfysik.py

View workflow job for this annotation

GitHub Actions / call-workflow / ruff

Ruff (F811)

common_tests/danfysik.py:130:9: F811 Redefinition of unused `test_WHEN_power_setpoint_is_set_THEN_readback_updates_with_set_value` from line 124
for id_prefix in self.id_prefixes:
for state_num, state in enumerate(POWER_STATES):
self.ca.assert_setting_setpoint_sets_readback(state_num, "{}POWER".format(id_prefix),
"{}POWER:SP".format(id_prefix), state)
self.ca.assert_setting_setpoint_sets_readback(
state_num, "{}POWER".format(id_prefix), "{}POWER:SP".format(id_prefix), state
)

def test_WHEN_current_setpoint_is_set_THEN_current_readback_updates_to_set_value(self):
for id_prefix in self.id_prefixes:
for curr in TEST_CURRENTS:
self.ca.set_pv_value("{}CURR:SP".format(id_prefix), curr)
expected_value = curr*self.current_readback_factor if IOCRegister.uses_rec_sim else curr
self.ca.assert_that_pv_is_number("{}CURR".format(id_prefix), expected_value, tolerance=0.5) # Tolerance 0.5 because readback is integer
expected_value = (
curr * self.current_readback_factor if IOCRegister.uses_rec_sim else curr
)
self.ca.assert_that_pv_is_number(
"{}CURR".format(id_prefix), expected_value, tolerance=0.5
) # Tolerance 0.5 because readback is integer

@skip_if_devsim("In dev sim this test fails as the simulated records are not used")
def test_GIVEN_emulator_not_in_use_WHEN_voltage_is_read_THEN_value_is_as_expected(self):
Expand All @@ -139,7 +160,9 @@
self.set_voltage(volt)
for id_prefix in self.id_prefixes:
# Should be able to re-initialize comms and read the new voltage
self.ca.assert_that_pv_is_number("{}VOLT".format(id_prefix), volt, tolerance=0.5, timeout=30)
self.ca.assert_that_pv_is_number(
"{}VOLT".format(id_prefix), volt, tolerance=0.5, timeout=30
)

finally:
# If test fails, don't want it to affect other tests.
Expand All @@ -150,8 +173,10 @@
for id_prefix in self.id_prefixes:
self.ca.assert_that_pv_is("{}ILK".format(id_prefix), HAS_TRIPPED[False])

@skip_if_recsim("In rec sim this test fails as recsim does not set any of the related values "
"which are set by the emulator")
@skip_if_recsim(
"In rec sim this test fails as recsim does not set any of the related values "
"which are set by the emulator"
)
def test_WHEN_reset_is_sent_THEN_readbacks_and_power_are_off(self):
for id_prefix in self.id_prefixes:
self.ca.set_pv_value("{}CURR:SP".format(id_prefix), 5)
Expand All @@ -170,7 +195,9 @@

self.ca.assert_that_pv_is("POWER:SP", "Off")

def test_GIVEN_power_off_and_non_zero_sp_WHEN_enabling_auto_onoff_THEN_device_is_powered_on(self):
def test_GIVEN_power_off_and_non_zero_sp_WHEN_enabling_auto_onoff_THEN_device_is_powered_on(
self,
):
self.set_autoonoff(False)
self.ca.set_pv_value("POWER:SP", 0)
self.ca.set_pv_value("CURR:SP", 10)
Expand Down Expand Up @@ -200,7 +227,9 @@

self.ca.assert_that_pv_is("POWER:SP", "On")

def test_GIVEN_power_on_and_auto_onoff_enabled_WHEN_setting_zero_value_THEN_device_is_powered_off(self):
def test_GIVEN_power_on_and_auto_onoff_enabled_WHEN_setting_zero_value_THEN_device_is_powered_off(
self,
):
self.ca.set_pv_value("POWER:SP", 1)
self.ca.set_pv_value("CURR:SP", 10)
self.set_autoonoff(True)
Expand All @@ -210,7 +239,9 @@

self.ca.assert_that_pv_is("POWER:SP", "Off")

def test_GIVEN_power_off_and_auto_onoff_enabled_WHEN_setting_non_zero_value_THEN_device_is_powered_on(self):
def test_GIVEN_power_off_and_auto_onoff_enabled_WHEN_setting_non_zero_value_THEN_device_is_powered_on(
self,
):
self.set_autoonoff(True)
self.ca.set_pv_value("POWER:SP", 0)
self.ca.set_pv_value("CURR:SP", 0)
Expand All @@ -220,7 +251,9 @@

self.ca.assert_that_pv_is("POWER:SP", "On")

def test_GIVEN_auto_onoff_disabled_WHEN_sweep_to_zero_and_turn_off_triggered_THEN_actioned_by_enabling_auto_onoff_and_setting_sp_to_zero(self):
def test_GIVEN_auto_onoff_disabled_WHEN_sweep_to_zero_and_turn_off_triggered_THEN_actioned_by_enabling_auto_onoff_and_setting_sp_to_zero(
self,
):
self.set_autoonoff(False)
self.ca.set_pv_value("POWER:SP", 1)
self.ca.set_pv_value("CURR:SP", 10)
Expand All @@ -232,22 +265,28 @@
self.ca.assert_that_pv_is("CURR", 0)
self.ca.assert_that_pv_is("POWER:SP", "Off")

@parameterized.expand([
("power_on_and_current_at_10", True, 10),
("power_off_and_current_at_50", False, 50),
])
@parameterized.expand(
[
("power_on_and_current_at_10", True, 10),
("power_off_and_current_at_50", False, 50),
]
)
@skip_if_recsim("In rec sim this test fails as there is nothing holding the device state")
def test_WHEN_IOC_is_restarted_THEN_current_and_powered_are_not_changed(self, _, power_state, current):
def test_WHEN_IOC_is_restarted_THEN_current_and_powered_are_not_changed(
self, _, power_state, current
):
self.set_autoonoff(False)
self.ca.set_pv_value("POWER:SP", int(power_state))
self.ca.assert_that_pv_is("POWER", "On" if power_state else "Off")
self.ca.set_pv_value("CURR:SP", current)
self.ca.assert_that_pv_is("CURR", current)

# check emulator is in correct state before ioc restart
self.assertEqual(str(float(current)), self._lewis.backdoor_get_from_device("absolute_current"))
self.assertEqual(
str(float(current)), self._lewis.backdoor_get_from_device("absolute_current")
)
self.assertEqual(str(power_state), self._lewis.backdoor_get_from_device("power"))

# currently using 30 second autosave for autoonoff etc. adding this wait makes sure we have autosaved
# the above autoonoff setting as this gets modified in other tests and we may potentially pick up their autosaved
# value instead. If this wait fixes things, we need to look at the logic more for a better fix
Expand All @@ -260,35 +299,45 @@
self.ca.assert_that_pv_is("CURR", current)
self.ca.assert_that_pv_is("POWER", "On" if power_state else "Off")

self.assertEqual(str(float(current)), self._lewis.backdoor_get_from_device("absolute_current"))
self.assertEqual(
str(float(current)), self._lewis.backdoor_get_from_device("absolute_current")
)
self.assertEqual(str(power_state), self._lewis.backdoor_get_from_device("power"))

@parameterized.expand([
("_within_limits", TEST_CURRENTS[1], TEST_CURRENTS[0], 0, "No"),
("_outside_limits", TEST_CURRENTS[0], TEST_CURRENTS[1], 2, "CURR LIMIT"),
])
@parameterized.expand(
[
("_within_limits", TEST_CURRENTS[1], TEST_CURRENTS[0], 0, "No"),
("_outside_limits", TEST_CURRENTS[0], TEST_CURRENTS[1], 2, "CURR LIMIT"),
]
)
@skip_if_recsim("Cannot catch errors in RECSIM")
def test_WHEN_current_set_AND_limits_set_THEN_limit_correct(self, _, limit, setpoint, summary, limit_enum):
self.ca.set_pv_value(f"CURR.HIGH", limit)
self.ca.set_pv_value(f"CURR.LOW", 0)
self.ca.set_pv_value(f"CURR:SP", setpoint)
self.ca.assert_that_pv_is_number(f"CURR", setpoint, tolerance=0.5)
def test_WHEN_current_set_AND_limits_set_THEN_limit_correct(
self, _, limit, setpoint, summary, limit_enum
):
self.ca.set_pv_value("CURR.HIGH", limit)
self.ca.set_pv_value("CURR.LOW", 0)
self.ca.set_pv_value("CURR:SP", setpoint)
self.ca.assert_that_pv_is_number("CURR", setpoint, tolerance=0.5)
self.ca.assert_that_pv_is("LIMIT", summary)
self.ca.assert_that_pv_is("LIMIT:ENUM", limit_enum)

@parameterized.expand([
("_within_limits", TEST_VOLTAGES[1], TEST_VOLTAGES[0], 0, "No"),
("_outside_limits", TEST_VOLTAGES[0], TEST_VOLTAGES[1], 1, "VOLT LIMIT"),
])

@parameterized.expand(
[
("_within_limits", TEST_VOLTAGES[1], TEST_VOLTAGES[0], 0, "No"),
("_outside_limits", TEST_VOLTAGES[0], TEST_VOLTAGES[1], 1, "VOLT LIMIT"),
]
)
@skip_if_recsim("Cannot catch errors in RECSIM")
def test_WHEN_voltage_set_AND_limits_set_THEN_limit_correct(self, _, limit, setpoint, summary, limit_enum):
def test_WHEN_voltage_set_AND_limits_set_THEN_limit_correct(
self, _, limit, setpoint, summary, limit_enum
):
self.ca.set_pv_value("VOLT.HIGH", limit)
self.ca.set_pv_value("VOLT.LOW", -1)
self.set_voltage(setpoint)
self.ca.assert_that_pv_is_number("VOLT", setpoint, tolerance=0.5)
self.ca.assert_that_pv_is("LIMIT", summary)
self.ca.assert_that_pv_is("LIMIT:ENUM", limit_enum)

@skip_if_recsim("Cannot catch errors in RECSIM")
def test_WHEN_both_outside_limits_THEN_both_limit(self):
self.ca.set_pv_value("CURR.HIGH", TEST_CURRENTS[0])
Expand All @@ -299,4 +348,3 @@
self.set_voltage(TEST_VOLTAGES[1])
self.ca.assert_that_pv_is("LIMIT", 3)
self.ca.assert_that_pv_is("LIMIT:ENUM", "BOTH LIMITS")

Loading
Loading