Skip to content

Commit 624b5c9

Browse files
authored
Merge pull request #107 from ISISComputingGroup/Ticket8411_motor_control_cli_tests
Ticket8411_motor_control_genie_cli_tests
2 parents dc56385 + 19cabb7 commit 624b5c9

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" ?>
2+
<blocks xmlns="http://epics.isis.rl.ac.uk/schema/blocks/1.0" xmlns:blk="http://epics.isis.rl.ac.uk/schema/blocks/1.0" xmlns:xi="http://www.w3.org/2001/XInclude"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" ?>
2+
<components xmlns="http://epics.isis.rl.ac.uk/schema/components/1.0" xmlns:comp="http://epics.isis.rl.ac.uk/schema/components/1.0" xmlns:xi="http://www.w3.org/2001/XInclude"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" ?>
2+
<groups xmlns="http://epics.isis.rl.ac.uk/schema/groups/1.0" xmlns:grp="http://epics.isis.rl.ac.uk/schema/groups/1.0" xmlns:xi="http://www.w3.org/2001/XInclude"/>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
<iocs xmlns="http://epics.isis.rl.ac.uk/schema/iocs/1.0" xmlns:ioc="http://epics.isis.rl.ac.uk/schema/iocs/1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
3+
<ioc name="GALIL_01" autostart="true" restart="true" remotePvPrefix="" simlevel="recsim">
4+
<macros>
5+
<macro name="ENCAVNSAMP" value=""/>
6+
<macro name="GALILADDR" value="0.0.0.0"/>
7+
<macro name="MTRCTRL" value="1"/>
8+
</macros>
9+
<pvs/>
10+
<pvsets/>
11+
</ioc>
12+
</iocs>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<meta>
3+
<description>Testing genie python advanced scripts</description>
4+
<synoptic>-- NONE --</synoptic>
5+
<edits>
6+
<edit>2024-07-08 13:01:05</edit>
7+
</edits>
8+
<isProtected>false</isProtected>
9+
<isDynamic>false</isDynamic>
10+
<configuresBlockGWAndArchiver>false</configuresBlockGWAndArchiver>
11+
</meta>

test_genie_python_advanced.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import unittest
2+
from parameterized import parameterized as param
3+
4+
from utilities.utilities import load_config_if_not_already_loaded, g, \
5+
set_genie_python_raises_exceptions
6+
7+
ADV_CONFIG_NAME = "advanced"
8+
9+
10+
class TestAdvancedMotorControls(unittest.TestCase):
11+
def setUp(self):
12+
g.set_instrument(None)
13+
load_config_if_not_already_loaded(ADV_CONFIG_NAME)
14+
set_genie_python_raises_exceptions(True)
15+
16+
@param.expand([True, False])
17+
def test_GIVEN_manager_mode_WHEN_calling_get_manager_mode_THEN_returns_true(self, manager_mode):
18+
# Checks that the get_manager_mode() function works as expected.
19+
g.set_pv("CS:MANAGER", manager_mode, wait=True, is_local=True)
20+
self.assertTrue(g.adv.get_manager_mode() == manager_mode)
21+
22+
def test_GIVEN_no_manager_mode_WHEN_setting_motor_position_THEN_exception_is_raised(self):
23+
# Checks that the user will not be allowed to change the motor position without being in manager mode
24+
g.set_pv("CS:MANAGER", "No", wait=True, is_local=True)
25+
26+
with self.assertRaises(RuntimeError):
27+
g.adv.redefine_motor_position("MTR0101", 1000)
28+
29+
def test_GIVEN_invalid_motor_name_WHEN_setting_motor_position_THEN_exception_is_raised(self):
30+
# Checks that the set_motor_position function will only accept motors it recognises
31+
g.set_pv("CS:MANAGER", "Yes", wait=True, is_local=True)
32+
33+
with self.assertRaises(ValueError):
34+
g.adv.redefine_motor_position("INVALID_MOTOR_NAME", 1000)
35+
36+
def test_GIVEN_foff_is_variable_and_set_is_use_WHEN_setting_motor_position_THEN_foff_and_set_change_before_and_after(self):
37+
# Before changing motor position, check that SET mode is on Set
38+
# and FOFF is on Frozen
39+
40+
foff_value = "Variable"
41+
set_value = "Use"
42+
43+
g.set_pv("MOT:MTR0101.FOFF", foff_value, wait=True, is_local=True) # Frozen mode
44+
g.set_pv("MOT:MTR0101.SET", set_value, wait=True, is_local=True) # Use mode
45+
46+
with g.adv.motor_in_set_mode(g.my_pv_prefix + "MOT:MTR0101"):
47+
self.assertTrue(g.get_pv("MOT:MTR0101.SET", to_string=True, is_local=True) == "Set")
48+
self.assertTrue(g.get_pv("MOT:MTR0101.FOFF", to_string=True, is_local=True) == "Frozen")
49+
50+
self.assertTrue(g.get_pv("MOT:MTR0101.SET", to_string=True, is_local=True) == "Use")
51+
# Check that MOT:MTR0101.SET is in Use mode after calling set_motor_position()
52+
self.assertTrue(g.get_pv("MOT:MTR0101.FOFF", to_string=True, is_local=True) == foff_value)
53+
# Check that MOT:MTR0101.FFOF is in the same mode before and after calling set_motor_position()
54+
55+
@param.expand([1000, -1000])
56+
def test_GIVEN_manager_mode_and_valid_motor_name_WHEN_setting_motor_position_THEN_motor_position_set(self, motor_value):
57+
# Checks that for a combination of valid parameters there are no exceptions
58+
g.set_pv("CS:MANAGER", "Yes", wait=True, is_local=True)
59+
60+
g.adv.redefine_motor_position("MTR0101", motor_value)
61+
62+
self.assertTrue(motor_value == g.get_pv("MOT:MTR0101.VAL", to_string=False, is_local=True))
63+
# Assert that the motor position changes after calling set_motor_position()
64+
65+
def test_GIVEN_motor_is_moving_WHEN_setting_motor_position_THEN_exception_raised(self):
66+
# Checks that the motor is not allowed to be repositioned while it is already moving
67+
g.set_pv("CS:MANAGER", "Yes", wait=True, is_local=True)
68+
g.set_pv("MOT:MTR0101.SET", 0, wait=True, is_local=True) # Use mode
69+
70+
g.set_pv("MOT:MTR0101.VAL", 30000.0, wait=False, is_local=True) # Set position so that motor begins moving
71+
72+
with self.assertRaises(RuntimeError):
73+
g.adv.redefine_motor_position("MTR0101", 1000) # Check that it throws as exception as it is moving
74+
75+
def test_GIVEN_invalid_pv_WHEN_calling_motor_in_set_mode_THEN_exception_raised(self):
76+
# Checks that the function motor_in_set_mode will not accept an invalid pv
77+
with self.assertRaises(ValueError):
78+
with g.adv.motor_in_set_mode(g.my_pv_prefix + "MOT:INVALID_MOTOR_NAME"): None
79+
80+
def test_GIVEN_valid_pv_but_not_a_motor_pv_WHEN_calling_motor_in_set_mode_THEN_exception_raised(self):
81+
# Checks that the function motor_in_set_mode will not accept a valid pv that does not point to a motor
82+
with self.assertRaises(ValueError):
83+
with g.adv.motor_in_set_mode(g.my_pv_prefix + "CS:MANAGER"): None
84+
85+
def tearDown(self):
86+
g.set_pv("MOT:MTR0101.STOP", 1, wait=True, is_local=True) # Make sure motor is not moving
87+
g.set_pv("MOT:MTR0101.SET", 1, wait=True, is_local=True) # Set mode
88+
g.set_pv("MOT:MTR0101.VAL", 0.0, wait=True, is_local=True) # Motor is repositioned
89+
g.set_pv("CS:MANAGER", "No", wait=True, is_local=True) # Make sure not in manager mode
90+
set_genie_python_raises_exceptions(False)

0 commit comments

Comments
 (0)