Skip to content

Commit

Permalink
Merge pull request #234 from ISISComputingGroup/Ticket4695_jaws_adel
Browse files Browse the repository at this point in the history
Ticket4695 jaws adel
  • Loading branch information
Tom-Willemsen authored Sep 24, 2019
2 parents 937c5b7 + be2003a commit 6750df5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 48 deletions.
98 changes: 50 additions & 48 deletions tests/jaws.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from utils.test_modes import TestModes
from utils.testing import parameterized_list
from parameterized import parameterized
from collections import OrderedDict

MTR_01 = "GALIL_01"

Expand Down Expand Up @@ -41,14 +42,17 @@ class JawsTests(unittest.TestCase):
"""
MTR_NORTH = "MOT:MTR0101"
MTR_SOUTH = "MOT:MTR0102"
MTR_EAST = "MOT:MTR0103"
MTR_WEST = "MOT:MTR0104"
UNDERLYING_MTRS = [MTR_NORTH, MTR_SOUTH, MTR_EAST, MTR_WEST]
MTR_WEST = "MOT:MTR0103"
MTR_EAST = "MOT:MTR0104"
UNDERLYING_MTRS = OrderedDict([("N", MTR_NORTH),
("S", MTR_SOUTH),
("E", MTR_EAST),
("W", MTR_WEST)])

def setUp(self):
self._ioc = IOCRegister.get_running("jaws")
self.ca = ChannelAccess(default_timeout=30)
for mtr in self.UNDERLYING_MTRS:
for mtr in self.UNDERLYING_MTRS.values():
self.ca.set_pv_value("{}.VMAX".format(mtr), 100)
self.ca.set_pv_value("{}.VELO".format(mtr), 100)

Expand All @@ -58,45 +62,13 @@ def setUp(self):
self.ca.set_pv_value("MOT:JAWS1:HGAP:SP", 0)
self.ca.set_pv_value("MOT:JAWS1:VGAP:SP", 0)

def test_GIVEN_ioc_started_THEN_underlying_mtr_north_fields_can_be_read(self):
underlying_mtr = self.MTR_NORTH
direction_key = "JN"

expected = self.ca.get_pv_value("{}.VELO".format(underlying_mtr))
jaw_blade_pv = "{}:{}".format(JAWS_BASE_PV, direction_key)

actual = self.ca.get_pv_value("{}:MTR.VELO".format(jaw_blade_pv))

self.assertEqual(expected, actual)

def test_GIVEN_ioc_started_THEN_underlying_mtr_south_fields_can_be_read(self):
underlying_mtr = self.MTR_SOUTH
direction_key = "JS"
@parameterized.expand(parameterized_list(DIRECTIONS))
def test_GIVEN_ioc_started_THEN_underlying_mtr_fields_can_be_read(self, _, direction):
underlying_mtr = self.UNDERLYING_MTRS[direction]

expected = self.ca.get_pv_value("{}.VELO".format(underlying_mtr))
jaw_blade_pv = "{}:{}".format(JAWS_BASE_PV, direction_key)

actual = self.ca.get_pv_value("{}:MTR.VELO".format(jaw_blade_pv))

self.assertEqual(expected, actual)

def test_GIVEN_ioc_started_THEN_underlying_mtr_east_fields_can_be_read(self):
underlying_mtr = self.MTR_EAST
direction_key = "JE"

expected = self.ca.get_pv_value("{}.VELO".format(underlying_mtr))
jaw_blade_pv = "{}:{}".format(JAWS_BASE_PV, direction_key)

actual = self.ca.get_pv_value("{}:MTR.VELO".format(jaw_blade_pv))

self.assertEqual(expected, actual)

def test_GIVEN_ioc_started_THEN_underlying_mtr_west_fields_can_be_read(self):
underlying_mtr = self.MTR_WEST
direction_key = "JW"

expected = self.ca.get_pv_value("{}.VELO".format(underlying_mtr))
jaw_blade_pv = "{}:{}".format(JAWS_BASE_PV, direction_key)
jaw_blade_pv = "{}:J{}".format(JAWS_BASE_PV, direction)

actual = self.ca.get_pv_value("{}:MTR.VELO".format(jaw_blade_pv))

Expand Down Expand Up @@ -139,9 +111,9 @@ def test_GIVEN_jaws_closed_at_centre_WHEN_hgap_opened_THEN_east_and_west_jaws_mo
("able", "Enable")])
def test_GIVEN_all_jaws_have_state_set_THEN_overall_state_is_set(self, key, expected):
enabled_val = 0
for mtr in self.UNDERLYING_MTRS:
for mtr in self.UNDERLYING_MTRS.values():
mtr_status_pv = "{}_{}".format(mtr, key)
self.ca.set_pv_value(mtr_status_pv.format(JAWS_BASE_PV), enabled_val)
self.ca.set_pv_value(mtr_status_pv, enabled_val)

jaws_status_readback_pv = "{}:{}".format(JAWS_BASE_PV, key.upper())
actual = self.ca.get_pv_value(jaws_status_readback_pv)
Expand All @@ -152,9 +124,9 @@ def test_GIVEN_all_jaws_have_state_set_THEN_overall_state_is_set(self, key, expe
("able", "Disable")])
def test_GIVEN_no_jaws_have_state_set_THEN_overall_state_is_not_set(self, key, expected):
disabled_val = 1
for mtr in self.UNDERLYING_MTRS:
for mtr in self.UNDERLYING_MTRS.values():
mtr_status_pv = "{}_{}".format(mtr, key)
self.ca.set_pv_value(mtr_status_pv.format(JAWS_BASE_PV), disabled_val)
self.ca.set_pv_value(mtr_status_pv, disabled_val)

jaws_status_readback_pv = "{}:{}".format(JAWS_BASE_PV, key.upper())
actual = self.ca.get_pv_value(jaws_status_readback_pv)
Expand All @@ -166,14 +138,44 @@ def test_GIVEN_no_jaws_have_state_set_THEN_overall_state_is_not_set(self, key, e
def test_GIVEN_some_jaws_have_state_set_THEN_overall_state_is_unknown(self, key, expected):
disabled_val = 0
enabled_val = 1
for mtr in self.UNDERLYING_MTRS[:2]:
for mtr in self.UNDERLYING_MTRS.values()[:2]:
mtr_status_pv = "{}_{}".format(mtr, key)
self.ca.set_pv_value(mtr_status_pv.format(JAWS_BASE_PV), enabled_val)
for mtr in self.UNDERLYING_MTRS[2:]:
self.ca.set_pv_value(mtr_status_pv, enabled_val)
for mtr in self.UNDERLYING_MTRS.values()[2:]:
mtr_status_pv = "{}_{}".format(mtr, key)
self.ca.set_pv_value(mtr_status_pv.format(JAWS_BASE_PV), disabled_val)
self.ca.set_pv_value(mtr_status_pv, disabled_val)

jaws_status_readback_pv = "{}:{}".format(JAWS_BASE_PV, key.upper())
actual = self.ca.get_pv_value(jaws_status_readback_pv)

self.assertEqual(expected, actual)

@parameterized.expand(parameterized_list(DIRECTIONS))
def test_GIVEN_underlying_mtr_adel_value_THEN_jaws_ADEL_field_mirrored(self, _, direction):
motor_adel_pv = "{}.ADEL".format(self.UNDERLYING_MTRS[direction])
jaw_adel_pv = "{}:J{}.ADEL".format(JAWS_BASE_PV, direction)

self.ca.set_pv_value(motor_adel_pv, 0.0)
self.ca.assert_that_pv_is(motor_adel_pv, 0.0)

test_values = [1e-4, 1.2, 12.3]

for test_value in test_values:
self.ca.set_pv_value(motor_adel_pv, test_value)

self.ca.assert_that_pv_is_number(motor_adel_pv, test_value)
self.ca.assert_that_pv_is_number(jaw_adel_pv, test_value)

@parameterized.expand([("V", MTR_NORTH),
("H", MTR_EAST)])
def test_GIVEN_underlying_mtr_adel_THEN_jaws_centre_and_gap_adel_mirrored(self, axis, underlying_mtr):
motor_pv = "{}.ADEL".format(underlying_mtr)

test_values = [1e-4, 1.2, 12.3]
for test_value in test_values:
self.ca.set_pv_value(motor_pv, test_value)

self.ca.assert_that_pv_is_number(motor_pv, test_value)

self.ca.assert_that_pv_is_number("{}:{}CENT.ADEL".format(JAWS_BASE_PV, axis), test_value)
self.ca.assert_that_pv_is_number("{}:{}GAP.ADEL".format(JAWS_BASE_PV, axis), test_value)
5 changes: 5 additions & 0 deletions tests/jaws_split.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from collections import OrderedDict

from utils.ioc_launcher import IOCRegister, get_default_ioc_dir
from utils.test_modes import TestModes
Expand Down Expand Up @@ -44,5 +45,9 @@
SplitJawsTests.MTR_EAST = mtr_east
SplitJawsTests.MTR_WEST = mtr_west
SplitJawsTests.UNDERLYING_MTRS = [mtr_north, mtr_south, mtr_east, mtr_west]
SplitJawsTests.UNDERLYING_MTRS = OrderedDict([("N", mtr_north),
("S", mtr_south),
("E", mtr_east),
("W", mtr_west)])

__all__ = ["SplitJawsTests"]

0 comments on commit 6750df5

Please sign in to comment.