1
1
import unittest
2
+ from parameterized import parameterized as param
2
3
3
4
from utilities .utilities import load_config_if_not_already_loaded , g , \
4
5
set_genie_python_raises_exceptions
@@ -12,75 +13,78 @@ def setUp(self):
12
13
load_config_if_not_already_loaded (ADV_CONFIG_NAME )
13
14
set_genie_python_raises_exceptions (True )
14
15
15
- def test_GIVEN_manager_mode_WHEN_calling_get_manager_mode_THEN_returns_true (self ):
16
+ @param .expand ([True , False ])
17
+ def test_GIVEN_manager_mode_WHEN_calling_get_manager_mode_THEN_returns_true (self , manager_mode ):
16
18
# Checks that the get_manager_mode() function works as expected.
17
- g .set_pv ("CS:MANAGER" , "Yes" , True , True )
18
- assert g .adv .get_manager_mode ()
19
-
20
- g .set_pv ("CS:MANAGER" , "No" , True , True )
21
- assert not g .adv .get_manager_mode ()
19
+ g .set_pv ("CS:MANAGER" , manager_mode , wait = True , is_local = True )
20
+ self .assertTrue (g .adv .get_manager_mode () == manager_mode )
22
21
23
22
def test_GIVEN_no_manager_mode_WHEN_setting_motor_position_THEN_exception_is_raised (self ):
24
23
# Checks that the user will not be allowed to change the motor position without being in manager mode
25
- g .set_pv ("CS:MANAGER" , "No" , True , True )
24
+ g .set_pv ("CS:MANAGER" , "No" , wait = True , is_local = True )
26
25
27
26
with self .assertRaises (RuntimeError ):
28
- g .adv .set_motor_position ("MTR0101" , 1000 )
27
+ g .adv .redefine_motor_position ("MTR0101" , 1000 )
29
28
30
29
def test_GIVEN_invalid_motor_name_WHEN_setting_motor_position_THEN_exception_is_raised (self ):
31
30
# Checks that the set_motor_position function will only accept motors it recognises
32
- g .set_pv ("CS:MANAGER" , "Yes" , True , True )
31
+ g .set_pv ("CS:MANAGER" , "Yes" , wait = True , is_local = True )
33
32
34
33
with self .assertRaises (ValueError ):
35
- g .adv .set_motor_position ("INVALID_MOTOR_NAME" , 1000 )
34
+ g .adv .redefine_motor_position ("INVALID_MOTOR_NAME" , 1000 )
36
35
37
- def test_set_and_foff_change_before_after_setting_motor_position (self ):
36
+ def test_GIVEN_foff_is_variable_and_set_is_use_WHEN_setting_motor_position_THEN_foff_and_set_change_before_and_after (self ):
38
37
# Before changing motor position, check that SET mode is on Set
39
38
# and FOFF is on Frozen
40
39
41
- pv_name = g .my_pv_prefix + "MOT:MTR0101"
42
40
foff_value = "Variable"
41
+ set_value = "Use"
43
42
44
- g .set_pv (pv_name + ".FOFF" , foff_value , True , True )
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
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"
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
49
50
- assert g .get_pv (pv_name + " .SET" , True ) == "Use"
50
+ self . assertTrue ( g .get_pv ("MOT:MTR0101 .SET" , to_string = True , is_local = True ) == "Use" )
51
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
52
+ self . assertTrue ( g .get_pv ("MOT:MTR0101 .FOFF", to_string = True , is_local = True ) == foff_value )
53
53
# Check that MOT:MTR0101.FFOF is in the same mode before and after calling set_motor_position()
54
54
55
- def test_GIVEN_manager_mode_and_valid_motor_name_WHEN_setting_motor_position_THEN_motor_position_set (self ):
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 ):
56
57
# Checks that for a combination of valid parameters there are no exceptions
57
- params = [1000 , - 1000 ]
58
- g .set_pv ("CS:MANAGER" , "Yes" , True , True )
58
+ g .set_pv ("CS:MANAGER" , "Yes" , wait = True , is_local = True )
59
59
60
- pv_name = g . my_pv_prefix + "MOT: MTR0101"
60
+ g . adv . redefine_motor_position ( " MTR0101", motor_value )
61
61
62
- for motor_value in params :
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()
63
64
64
- g .adv .set_motor_position ("MTR0101" , motor_value )
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
65
69
66
- assert motor_value == g .get_pv (pv_name + ".VAL" )
67
- # Assert that the motor position changes after calling set_motor_position()
70
+ g .set_pv ("MOT:MTR0101.VAL" , 30000.0 , wait = False , is_local = True ) # Set position so that motor begins moving
68
71
69
- def test_GIVEN_motor_is_moving_WHEN_setting_motor_position_THEN_exception_raised (self ):
70
- pv_name = g .my_pv_prefix + "MOT:MTR0101"
71
- g .set_pv ("CS:MANAGER" , "Yes" , True , True )
72
- g .set_pv (pv_name + ".SET" , 0 , True ) # Use mode
72
+ with self .assertRaises (RuntimeError ):
73
+ g .adv .redefine_motor_position ("MTR0101" , 1000 ) # Check that it throws as exception as it is moving
73
74
74
- g .set_pv (pv_name + ".VAL" , 30000.0 , False ) # Set position so that motor begins moving
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
75
79
76
- with self .assertRaises (RuntimeError ) as e :
77
- print (e )
78
- g .adv .set_motor_position ("MTR0101" , 1000 ) # Check that it throws as exception as it is moving
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
79
84
80
85
def tearDown (self ):
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
85
- g .set_pv ("CS:MANAGER" , "No" , True , True ) # Make sure not in manager mode
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
86
90
set_genie_python_raises_exceptions (False )
0 commit comments