Skip to content

Commit 2e8bf49

Browse files
committed
testing driver halt and when usb is pulled out
1 parent 334dee6 commit 2e8bf49

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

opentrons/drivers/motor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def get_serial_ports_list(self):
199199
return result
200200

201201
def disconnect(self):
202-
if self.is_connected():
202+
if self.is_connected() and self.connection:
203203
self.connection.close()
204204
self.connection = None
205205

tests/opentrons/drivers/test_motor.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,26 @@ def setUp(self):
3030
self.assertTrue(success)
3131

3232
def tearDown(self):
33-
self.motor.disconnect()
33+
pass
3434

3535
def test_reset(self):
3636
self.motor.reset()
3737
self.assertEquals(self.motor.connection, None)
3838

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())
4147
self.assertRaises(RuntimeError, self.motor.calm_down)
48+
setattr(self.motor, 'is_connected', old_method)
4249

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()
4652
self.assertRaises(RuntimeError, self.motor.calm_down)
47-
self.motor.is_connected = old_method
4853

4954
def test_version_compatible(self):
5055
self.robot.disconnect()
@@ -144,6 +149,40 @@ def _move_head():
144149
}
145150
self.assertDictEqual(coords, expected_coords)
146151

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+
147186
def test_get_position(self):
148187
self.motor.home()
149188
self.motor.ot_version = None
@@ -174,14 +213,17 @@ def test_limit_hit_exception(self):
174213
self.motor.home()
175214

176215
def test_move_x(self):
216+
self.motor.ot_version = None
177217
success = self.motor.move_head(x=100)
178218
self.assertTrue(success)
179219

180220
def test_move_y(self):
221+
self.motor.ot_version = None
181222
success = self.motor.move_head(y=100)
182223
self.assertTrue(success)
183224

184225
def test_move_z(self):
226+
self.motor.ot_version = None
185227
success = self.motor.move_head(z=30)
186228
self.assertTrue(success)
187229

tests/opentrons/labware/test_pipette.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def setUp(self):
3232
channels=1
3333
)
3434

35+
self.p200.reset()
36+
3537
self.p200.calibrate_plunger(top=0, bottom=10, blow_out=12, drop_tip=13)
3638
self.robot.home(enqueue=False)
3739
_, _, starting_z = self.robot._driver.get_head_position()['current']

0 commit comments

Comments
 (0)