@@ -30,21 +30,26 @@ def setUp(self):
30
30
self .assertTrue (success )
31
31
32
32
def tearDown (self ):
33
- self . motor . disconnect ()
33
+ pass
34
34
35
35
def test_reset (self ):
36
36
self .motor .reset ()
37
37
self .assertEquals (self .motor .connection , None )
38
38
39
- def test_write_without_connection (self ):
40
- self .motor .disconnect ()
39
+ def test_write_with_lost_connection (self ):
40
+ self .motor .connection .is_open = False
41
+ old_method = getattr (self .motor , 'is_connected' )
42
+
43
+ def _temp ():
44
+ return True
45
+ setattr (self .motor , 'is_connected' , _temp )
46
+ self .assertTrue (self .motor .is_connected ())
41
47
self .assertRaises (RuntimeError , self .motor .calm_down )
48
+ setattr (self .motor , 'is_connected' , old_method )
42
49
43
- def test_write_with_lost_connection (self ):
44
- old_method = self .motor .is_connected
45
- self .motor .is_connected = lambda : False
50
+ def test_write_after_disconnect (self ):
51
+ self .motor .disconnect ()
46
52
self .assertRaises (RuntimeError , self .motor .calm_down )
47
- self .motor .is_connected = old_method
48
53
49
54
def test_version_compatible (self ):
50
55
self .robot .disconnect ()
@@ -144,6 +149,40 @@ def _move_head():
144
149
}
145
150
self .assertDictEqual (coords , expected_coords )
146
151
152
+ def test_halt (self ):
153
+ self .motor .home ()
154
+
155
+ self .motor .pause ()
156
+
157
+ def _move_head ():
158
+ self .assertRaises (
159
+ RuntimeWarning ,
160
+ self .motor .move_head ,
161
+ ** {'x' : 100 , 'y' : 0 , 'z' : 0 }
162
+ )
163
+
164
+ thread = Thread (target = _move_head )
165
+ thread .start ()
166
+
167
+ self .motor .halt ()
168
+
169
+ thread .join ()
170
+
171
+ coords = self .motor .get_head_position ()
172
+ expected_coords = {
173
+ 'target' : (0 , 400 , 100 ),
174
+ 'current' : (0 , 400 , 100 )
175
+ }
176
+ self .assertDictEqual (coords , expected_coords )
177
+
178
+ self .motor .move_head (x = 100 , y = 0 , z = 0 )
179
+ coords = self .motor .get_head_position ()
180
+ expected_coords = {
181
+ 'target' : (100 , 0 , 0 ),
182
+ 'current' : (100 , 0 , 0 )
183
+ }
184
+ self .assertDictEqual (coords , expected_coords )
185
+
147
186
def test_get_position (self ):
148
187
self .motor .home ()
149
188
self .motor .ot_version = None
@@ -174,14 +213,17 @@ def test_limit_hit_exception(self):
174
213
self .motor .home ()
175
214
176
215
def test_move_x (self ):
216
+ self .motor .ot_version = None
177
217
success = self .motor .move_head (x = 100 )
178
218
self .assertTrue (success )
179
219
180
220
def test_move_y (self ):
221
+ self .motor .ot_version = None
181
222
success = self .motor .move_head (y = 100 )
182
223
self .assertTrue (success )
183
224
184
225
def test_move_z (self ):
226
+ self .motor .ot_version = None
185
227
success = self .motor .move_head (z = 30 )
186
228
self .assertTrue (success )
187
229
0 commit comments