@@ -21,11 +21,14 @@ def setUp(self):
21
21
self ._comm ._errorValue = None
22
22
self ._comm ._clear_to_send = mock .Mock ()
23
23
self ._comm ._error_message_hooks = dict ()
24
+ self ._comm ._trigger_emergency_stop = mock .Mock ()
24
25
25
26
# settings
26
27
self ._comm ._ignore_errors = False
27
28
self ._comm ._disconnect_on_errors = True
29
+ self ._comm ._send_m112_on_error = True
28
30
self ._comm .isPrinting .return_value = True
31
+ self ._comm .isSdPrinting .return_value = False
29
32
self ._comm .isError .return_value = False
30
33
31
34
@ddt .data (
@@ -132,6 +135,7 @@ def test_other_error_disconnect(self, line):
132
135
self .assertEqual (line , result )
133
136
134
137
# what should have happened
138
+ self .assert_m112_sent ()
135
139
self .assert_disconnected ()
136
140
137
141
# what should not have happened
@@ -140,6 +144,24 @@ def test_other_error_disconnect(self, line):
140
144
self .assert_not_print_cancelled ()
141
145
self .assert_not_cleared_to_send ()
142
146
147
+ @ddt .data ("Error: Printer on fire" )
148
+ def test_other_error_no_m112 (self , line ):
149
+ """Should trigger escalation"""
150
+ self ._comm ._send_m112_on_error = False
151
+
152
+ result = self ._comm ._handle_errors (line )
153
+ self .assertEqual (line , result )
154
+
155
+ # what should have happened
156
+ self .assert_disconnected ()
157
+
158
+ # what should not have happened
159
+ self .assert_not_handle_ok ()
160
+ self .assert_not_last_comm_error ()
161
+ self .assert_not_print_cancelled ()
162
+ self .assert_not_cleared_to_send ()
163
+ self .assert_not_m112_sent ()
164
+
143
165
@ddt .data ("Error: Printer on fire" )
144
166
def test_other_error_cancel (self , line ):
145
167
"""Should trigger print cancel"""
@@ -155,6 +177,7 @@ def test_other_error_cancel(self, line):
155
177
# what should not have happened
156
178
self .assert_not_handle_ok ()
157
179
self .assert_not_last_comm_error ()
180
+ self .assert_not_m112_sent ()
158
181
self .assert_not_disconnected ()
159
182
160
183
@ddt .data ("Error: Printer on fire" )
@@ -172,6 +195,8 @@ def test_other_error_ignored(self, line):
172
195
self .assert_not_handle_ok ()
173
196
self .assert_not_last_comm_error ()
174
197
self .assert_not_print_cancelled ()
198
+ self .assert_not_m112_sent ()
199
+ self .assert_not_disconnected ()
175
200
176
201
def test_not_an_error (self ):
177
202
"""Should pass"""
@@ -205,6 +230,12 @@ def assert_last_comm_error(self):
205
230
def assert_not_last_comm_error (self ):
206
231
self .assertIsNone (self ._comm ._lastCommError )
207
232
233
+ def assert_m112_sent (self ):
234
+ self ._comm ._trigger_emergency_stop .assert_called_once_with (close = False )
235
+
236
+ def assert_not_m112_sent (self ):
237
+ self ._comm ._trigger_emergency_stop .assert_not_called ()
238
+
208
239
def assert_disconnected (self ):
209
240
self .assertIsNotNone (self ._comm ._errorValue )
210
241
self ._comm ._changeState .assert_called_with (self ._comm .STATE_ERROR )
0 commit comments