@@ -61,8 +61,10 @@ def setup_function(function):
61
61
'test_servo_close' ,
62
62
'test_servo_pulse_width' ,
63
63
'test_servo_values' ,
64
+ 'test_servo_initial_values' ,
64
65
'test_angular_servo_range' ,
65
66
'test_angular_servo_angles' ,
67
+ 'test_angular_servo_initial_angles' ,
66
68
) else MockPin
67
69
68
70
def teardown_function (function ):
@@ -1014,7 +1016,7 @@ def test_servo_pins_nonpwm():
1014
1016
1015
1017
def test_servo_close ():
1016
1018
p = Device .pin_factory .pin (2 )
1017
- with Servo (1 ) as device :
1019
+ with Servo (2 ) as device :
1018
1020
device .close ()
1019
1021
assert device .closed
1020
1022
assert device .pwm_device .pin is None
@@ -1023,7 +1025,7 @@ def test_servo_close():
1023
1025
1024
1026
def test_servo_pulse_width ():
1025
1027
p = Device .pin_factory .pin (2 )
1026
- with Servo (1 , min_pulse_width = 5 / 10000 , max_pulse_width = 25 / 10000 ) as device :
1028
+ with Servo (2 , min_pulse_width = 5 / 10000 , max_pulse_width = 25 / 10000 ) as device :
1027
1029
assert isclose (device .min_pulse_width , 5 / 10000 )
1028
1030
assert isclose (device .max_pulse_width , 25 / 10000 )
1029
1031
assert isclose (device .frame_width , 20 / 1000 )
@@ -1035,6 +1037,19 @@ def test_servo_pulse_width():
1035
1037
device .value = None
1036
1038
assert device .pulse_width is None
1037
1039
1040
+ def test_servo_initial_values ():
1041
+ p = Device .pin_factory .pin (2 )
1042
+ with Servo (2 ) as device :
1043
+ assert device .value == 0
1044
+ with Servo (2 , initial_value = - 1 ) as device :
1045
+ assert device .value == - 1
1046
+ with Servo (2 , initial_value = 0 ) as device :
1047
+ assert device .value == 0
1048
+ with Servo (2 , initial_value = 1 ) as device :
1049
+ assert device .value == 1
1050
+ with Servo (2 , initial_value = None ) as device :
1051
+ assert device .value is None
1052
+
1038
1053
def test_servo_values ():
1039
1054
p = Device .pin_factory .pin (1 )
1040
1055
with Servo (1 ) as device :
@@ -1068,6 +1083,19 @@ def test_angular_servo_range():
1068
1083
assert device .min_angle == 0
1069
1084
assert device .max_angle == 90
1070
1085
1086
+ def test_angular_servo_initial_angles ():
1087
+ p = Device .pin_factory .pin (1 )
1088
+ with AngularServo (1 ) as device :
1089
+ assert device .angle == 0
1090
+ with AngularServo (1 , initial_angle = - 90 ) as device :
1091
+ assert device .angle == - 90
1092
+ with AngularServo (1 , initial_angle = 0 ) as device :
1093
+ assert device .angle == 0
1094
+ with AngularServo (1 , initial_angle = 90 ) as device :
1095
+ assert device .angle == 90
1096
+ with AngularServo (1 , initial_angle = None ) as device :
1097
+ assert device .angle is None
1098
+
1071
1099
def test_angular_servo_angles ():
1072
1100
p = Device .pin_factory .pin (1 )
1073
1101
with AngularServo (1 ) as device :
0 commit comments