Skip to content

Commit 1541622

Browse files
committed
Adds tests for new genie CLI motor control
1 parent 400474b commit 1541622

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

test_genie_python_advanced.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,74 @@ def setUp(self):
1313
set_genie_python_raises_exceptions(True)
1414

1515
def test_GIVEN_manager_mode_WHEN_calling_get_manager_mode_THEN_returns_true(self):
16-
g.set_pv("CS:MANAGER", "Yes", True, True) # Check that the get_manager_mode() function works as expected.
16+
# Checks that the get_manager_mode() function works as expected.
17+
g.set_pv("CS:MANAGER", "Yes", True, True)
1718
assert g.adv.get_manager_mode()
1819

1920
g.set_pv("CS:MANAGER", "No", True, True)
2021
assert not g.adv.get_manager_mode()
2122

2223
def test_GIVEN_no_manager_mode_WHEN_setting_motor_position_THEN_exception_is_raised(self):
24+
# Checks that the user will not be allowed to change the motor position without being in manager mode
2325
g.set_pv("CS:MANAGER", "No", True, True)
2426

2527
with self.assertRaises(RuntimeError):
26-
# Check that the user will not be allowed to change the motor position without being in manager mode
2728
g.adv.set_motor_position("MTR0101", 1000)
2829

2930
def test_GIVEN_invalid_motor_name_WHEN_setting_motor_position_THEN_exception_is_raised(self):
31+
# Checks that the set_motor_position function will only accept motors it recognises
3032
g.set_pv("CS:MANAGER", "Yes", True, True)
3133

3234
with self.assertRaises(ValueError):
33-
# Check that the set_motor_position will only accept motors it recognises
3435
g.adv.set_motor_position("INVALID_MOTOR_NAME", 1000)
3536

36-
def test_GIVEN_manager_mode_and_valid_motor_name_WHEN_setting_motor_position_THEN_no_exception_raised(self):
37-
params = [(1000, "Frozen"), (-1000, "Frozen"), (1000, "Variable"), (-1000, "Variable")]
37+
def test_set_and_foff_change_before_after_setting_motor_position(self):
38+
# Before changing motor position, check that SET mode is on Set
39+
# and FOFF is on Frozen
40+
41+
pv_name = g.my_pv_prefix + "MOT:MTR0101"
42+
foff_value = "Variable"
43+
44+
g.set_pv(pv_name + ".FOFF", foff_value, True, True)
45+
46+
with g.adv.motor_in_set_mode(pv_name):
47+
assert g.get_pv(pv_name + ".SET", True) == "Set"
48+
assert g.get_pv(pv_name + ".FOFF", True) == "Frozen"
49+
50+
assert g.get_pv(pv_name + ".SET", True) == "Use"
51+
# Check that MOT:MTR0101.SET is in Use mode after calling set_motor_position()
52+
assert g.get_pv(pv_name + ".FOFF") == foff_value
53+
# Check that MOT:MTR0101.FFOF is in the same mode before and after calling set_motor_position()
54+
55+
def test_GIVEN_manager_mode_and_valid_motor_name_WHEN_setting_motor_position_THEN_motor_position_set(self):
56+
# Checks that for a combination of valid parameters there are no exceptions
57+
params = [1000, -1000]
3858
g.set_pv("CS:MANAGER", "Yes", True, True)
3959

40-
for motor_value, foff_value in params:
60+
pv_name = g.my_pv_prefix + "MOT:MTR0101"
4161

42-
g.set_pv(g.my_pv_prefix + "MOT:MTR0101.FOFF", foff_value, True, True)
62+
for motor_value in params:
4363

4464
g.adv.set_motor_position("MTR0101", motor_value)
4565

46-
assert motor_value == g.get_pv(g.my_pv_prefix + "MOT:MTR0101.VAL")
66+
assert motor_value == g.get_pv(pv_name + ".VAL")
4767
# Assert that the motor position changes after calling set_motor_position()
48-
assert g.get_pv(g.my_pv_prefix + "MOT:MTR0101.SET", True) == "Use"
49-
# Check that MOT:MTR0101.SET is in Use mode after calling set_motor_position()
50-
assert g.get_pv(g.my_pv_prefix + "MOT:MTR0101.FOFF") == foff_value
51-
# Check that MOT:MTR0101.FFOF is in the same mode before and after calling set_motor_position()
5268

5369
def test_GIVEN_motor_is_moving_WHEN_setting_motor_position_THEN_exception_raised(self):
70+
pv_name = g.my_pv_prefix + "MOT:MTR0101"
5471
g.set_pv("CS:MANAGER", "Yes", True, True)
55-
g.set_pv(g.my_pv_prefix + "MOT:MTR0101.SET", 0, True) # Use mode
72+
g.set_pv(pv_name + ".SET", 0, True) # Use mode
5673

57-
g.set_pv(g.my_pv_prefix + "MOT:MTR0101.VAL", 30000.0, False) # Set position so that motor begins moving
74+
g.set_pv(pv_name + ".VAL", 30000.0, False) # Set position so that motor begins moving
5875

5976
with self.assertRaises(RuntimeError) as e:
6077
print(e)
6178
g.adv.set_motor_position("MTR0101", 1000) # Check that it throws as exception as it is moving
6279

6380
def tearDown(self):
64-
g.set_pv(g.my_pv_prefix + "MOT:MTR0101.STOP", 1, True) # Make sure motor is not moving
65-
g.set_pv(g.my_pv_prefix + "MOT:MTR0101.SET", 1, True) # Set mode
66-
g.set_pv(g.my_pv_prefix + "MOT:MTR0101.VAL", 0.0, True) # Motor is repositioned
81+
pv_name = g.my_pv_prefix + "MOT:MTR0101"
82+
g.set_pv(pv_name + ".STOP", 1, True) # Make sure motor is not moving
83+
g.set_pv(pv_name + ".SET", 1, True) # Set mode
84+
g.set_pv(pv_name + ".VAL", 0.0, True) # Motor is repositioned
6785
g.set_pv("CS:MANAGER", "No", True, True) # Make sure not in manager mode
6886
set_genie_python_raises_exceptions(False)

0 commit comments

Comments
 (0)