@@ -13,56 +13,74 @@ def setUp(self):
13
13
set_genie_python_raises_exceptions (True )
14
14
15
15
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 )
17
18
assert g .adv .get_manager_mode ()
18
19
19
20
g .set_pv ("CS:MANAGER" , "No" , True , True )
20
21
assert not g .adv .get_manager_mode ()
21
22
22
23
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
23
25
g .set_pv ("CS:MANAGER" , "No" , True , True )
24
26
25
27
with self .assertRaises (RuntimeError ):
26
- # Check that the user will not be allowed to change the motor position without being in manager mode
27
28
g .adv .set_motor_position ("MTR0101" , 1000 )
28
29
29
30
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
30
32
g .set_pv ("CS:MANAGER" , "Yes" , True , True )
31
33
32
34
with self .assertRaises (ValueError ):
33
- # Check that the set_motor_position will only accept motors it recognises
34
35
g .adv .set_motor_position ("INVALID_MOTOR_NAME" , 1000 )
35
36
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 ]
38
58
g .set_pv ("CS:MANAGER" , "Yes" , True , True )
39
59
40
- for motor_value , foff_value in params :
60
+ pv_name = g . my_pv_prefix + "MOT:MTR0101"
41
61
42
- g . set_pv ( g . my_pv_prefix + "MOT:MTR0101.FOFF" , foff_value , True , True )
62
+ for motor_value in params :
43
63
44
64
g .adv .set_motor_position ("MTR0101" , motor_value )
45
65
46
- assert motor_value == g .get_pv (g . my_pv_prefix + "MOT:MTR0101 .VAL" )
66
+ assert motor_value == g .get_pv (pv_name + ".VAL" )
47
67
# 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()
52
68
53
69
def test_GIVEN_motor_is_moving_WHEN_setting_motor_position_THEN_exception_raised (self ):
70
+ pv_name = g .my_pv_prefix + "MOT:MTR0101"
54
71
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
56
73
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
58
75
59
76
with self .assertRaises (RuntimeError ) as e :
60
77
print (e )
61
78
g .adv .set_motor_position ("MTR0101" , 1000 ) # Check that it throws as exception as it is moving
62
79
63
80
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
67
85
g .set_pv ("CS:MANAGER" , "No" , True , True ) # Make sure not in manager mode
68
86
set_genie_python_raises_exceptions (False )
0 commit comments