@@ -58,15 +58,15 @@ def _quit_loop_by_timeout(self):
58
58
59
59
def _cleanup (self ):
60
60
# store timeout message before the data to construct it is lost
61
- self ._timeout_message = self .get_timeout_error_message ()
61
+ self ._timeout_message = self ._get_timeout_error_message ()
62
62
if self ._timer is not None :
63
63
_silent_disconnect (self ._timer .timeout , self ._quit_loop_by_timeout )
64
64
self ._timer .stop ()
65
65
self ._timer = None
66
66
67
- def get_timeout_error_message (self ):
67
+ def _get_timeout_error_message (self ):
68
68
"""Subclasses have to implement this, returning an appropriate error message for a SignalTimeoutError."""
69
- raise NotImplementedError
69
+ raise NotImplementedError # pragma: no cover
70
70
71
71
def _extract_pyqt_signal_name (self , potential_pyqt_signal ):
72
72
signal_name = potential_pyqt_signal .signal # type: str
@@ -84,9 +84,11 @@ def _extract_signal_from_signal_tuple(self, potential_signal_tuple):
84
84
"the second element is the signal's name)." )
85
85
signal_tuple = potential_signal_tuple
86
86
signal_name = signal_tuple [1 ]
87
- if not isinstance (signal_name , str ) or not signal_name :
88
- raise TypeError ("Invalid type for user- provided signal name, "
87
+ if not isinstance (signal_name , str ):
88
+ raise TypeError ("Invalid type for provided signal name, "
89
89
"expected str but got {}" .format (type (signal_name )))
90
+ if not signal_name :
91
+ raise ValueError ("The provided signal name may not be empty" )
90
92
return signal_name
91
93
return ""
92
94
@@ -226,7 +228,7 @@ def get_params_as_str(self):
226
228
227
229
return str (args_list )
228
230
229
- def get_timeout_error_message (self ):
231
+ def _get_timeout_error_message (self ):
230
232
if self .check_params_callback is not None :
231
233
return ("Signal {signal_name} emitted with parameters {params} "
232
234
"within {timeout} ms, but did not satisfy "
@@ -267,6 +269,10 @@ def __eq__(self, other):
267
269
get_ordinal_str = lambda n : "%d%s" % (n , {1 : "st" , 2 : "nd" , 3 : "rd" }.get (n if n < 20 else n % 10 , "th" ))
268
270
269
271
272
+ class NoMatchingIndexFoundError (Exception ):
273
+ pass
274
+
275
+
270
276
class MultiSignalBlocker (_AbstractSignalBlocker ):
271
277
"""
272
278
Returned by :meth:`pytestqt.qtbot.QtBot.waitSignals` method, blocks until
@@ -305,7 +311,7 @@ def add_signals(self, signals):
305
311
self ._create_signal_emitted_indices (signals )
306
312
self ._connect_unique_signals ()
307
313
308
- def get_timeout_error_message (self ):
314
+ def _get_timeout_error_message (self ):
309
315
if not self ._are_signal_names_available ():
310
316
error_message = self ._get_degenerate_error_message ()
311
317
else :
@@ -381,7 +387,7 @@ def _check_signal_match(self, unique_signal, *args):
381
387
try :
382
388
successful_index = self ._get_first_matching_index (unique_signal , * args )
383
389
self ._signals_emitted [successful_index ] = True
384
- except : # none found
390
+ except NoMatchingIndexFoundError : # none found
385
391
pass
386
392
elif self ._order == "simple" :
387
393
if self ._check_signal_matches_expected_index (unique_signal , * args ):
@@ -413,7 +419,7 @@ def _get_first_matching_index(self, unique_signal, *args):
413
419
successfully_emitted = True
414
420
break
415
421
if not successfully_emitted :
416
- raise Exception ( "No matching index was found" )
422
+ raise NoMatchingIndexFoundError
417
423
418
424
return successful_index
419
425
@@ -476,9 +482,9 @@ def _get_order_violation_message(self):
476
482
expected_signal_as_str = self ._get_signal_string_representation_for_index (self ._signal_expected_index )
477
483
actual_signal_as_str = str (self ._actual_signal_and_args_at_violation )
478
484
return ("Signal order violated! Expected {expected} as {ordinal} signal, "
479
- "but received {actual} instead. " ).format (expected = expected_signal_as_str ,
480
- ordinal = get_ordinal_str (self ._signal_expected_index + 1 ),
481
- actual = actual_signal_as_str )
485
+ "but received {actual} instead. " ).format (expected = expected_signal_as_str ,
486
+ ordinal = get_ordinal_str (self ._signal_expected_index + 1 ),
487
+ actual = actual_signal_as_str )
482
488
483
489
def _get_missing_signal_indices (self ):
484
490
return [index for index , value in enumerate (self ._signals_emitted ) if not self ._signals_emitted [index ]]
0 commit comments