2
2
from types import TracebackType
3
3
import weakref
4
4
import warnings
5
- from typing import TYPE_CHECKING , Callable , Generator , Iterator , List , Literal , Optional , Any , Self , Type , cast
5
+ from typing import (
6
+ TYPE_CHECKING ,
7
+ Callable ,
8
+ Generator ,
9
+ Iterator ,
10
+ List ,
11
+ Literal ,
12
+ Optional ,
13
+ Any ,
14
+ Self ,
15
+ Type ,
16
+ cast ,
17
+ )
6
18
from pathlib import Path
7
19
8
20
from pytestqt .exceptions import TimeoutError , ScreenshotError
@@ -190,7 +202,9 @@ def _should_raise(self, raising_arg: Optional[bool]) -> bool:
190
202
else :
191
203
return True
192
204
193
- def addWidget (self , widget : QWidget , * , before_close_func : Optional [BeforeCloseFunc ] = None ) -> None :
205
+ def addWidget (
206
+ self , widget : QWidget , * , before_close_func : Optional [BeforeCloseFunc ] = None
207
+ ) -> None :
194
208
"""
195
209
Adds a widget to be tracked by this bot. This is not required, but will ensure that the
196
210
widget gets closed by the end of the test, so it is highly recommended.
@@ -208,7 +222,9 @@ def addWidget(self, widget: QWidget, *, before_close_func: Optional[BeforeCloseF
208
222
raise TypeError (f"Need to pass a QWidget to addWidget: { widget !r} " )
209
223
_add_widget (self ._request .node , widget , before_close_func = before_close_func )
210
224
211
- def waitActive (self , widget : QWidget , * , timeout : int = 5000 ) -> "_WaitWidgetContextManager" :
225
+ def waitActive (
226
+ self , widget : QWidget , * , timeout : int = 5000
227
+ ) -> "_WaitWidgetContextManager" :
212
228
"""
213
229
Context manager that waits for ``timeout`` milliseconds or until the window is active.
214
230
If window is not exposed within ``timeout`` milliseconds, raise
@@ -235,7 +251,9 @@ def waitActive(self, widget: QWidget, *, timeout: int = 5000) -> "_WaitWidgetCon
235
251
"qWaitForWindowActive" , "activated" , widget , timeout
236
252
)
237
253
238
- def waitExposed (self , widget : QWidget , * , timeout : int = 5000 ) -> "_WaitWidgetContextManager" :
254
+ def waitExposed (
255
+ self , widget : QWidget , * , timeout : int = 5000
256
+ ) -> "_WaitWidgetContextManager" :
239
257
"""
240
258
Context manager that waits for ``timeout`` milliseconds or until the window is exposed.
241
259
If the window is not exposed within ``timeout`` milliseconds, raise
@@ -387,10 +405,10 @@ def waitSignals(
387
405
self ,
388
406
signals : List [SignalInstance ],
389
407
* ,
390
- timeout : int = 5000 ,
391
- raising :Optional [bool ]= None ,
392
- check_params_cbs :Optional [List [CheckParamsCb ]] = None ,
393
- order : WaitSignalsOrder = "none" ,
408
+ timeout : int = 5000 ,
409
+ raising : Optional [bool ] = None ,
410
+ check_params_cbs : Optional [List [CheckParamsCb ]] = None ,
411
+ order : WaitSignalsOrder = "none" ,
394
412
) -> "MultiSignalBlocker" :
395
413
"""
396
414
.. versionadded:: 1.4
@@ -486,7 +504,9 @@ def wait(self, ms: int) -> None:
486
504
blocker .wait ()
487
505
488
506
@contextlib .contextmanager
489
- def assertNotEmitted (self , signal : SignalInstance , * , wait : int = 0 ) -> Generator [None , None , None ]:
507
+ def assertNotEmitted (
508
+ self , signal : SignalInstance , * , wait : int = 0
509
+ ) -> Generator [None , None , None ]:
490
510
"""
491
511
.. versionadded:: 1.11
492
512
@@ -507,7 +527,9 @@ def assertNotEmitted(self, signal: SignalInstance, *, wait: int=0) -> Generator[
507
527
yield
508
528
spy .assert_not_emitted ()
509
529
510
- def waitUntil (self , callback : Callable [[], Optional [bool ]], * , timeout : int = 5000 ) -> None :
530
+ def waitUntil (
531
+ self , callback : Callable [[], Optional [bool ]], * , timeout : int = 5000
532
+ ) -> None :
511
533
"""
512
534
.. versionadded:: 2.0
513
535
@@ -578,7 +600,9 @@ def timed_out():
578
600
raise TimeoutError (timeout_msg )
579
601
self .wait (10 )
580
602
581
- def waitCallback (self , * , timeout : int = 5000 , raising : Optional [bool ] = None ) -> "CallbackBlocker" :
603
+ def waitCallback (
604
+ self , * , timeout : int = 5000 , raising : Optional [bool ] = None
605
+ ) -> "CallbackBlocker" :
582
606
"""
583
607
.. versionadded:: 3.1
584
608
@@ -644,7 +668,9 @@ def captureExceptions(self) -> Generator["CapturedExceptions", None, None]:
644
668
with capture_exceptions () as exceptions :
645
669
yield exceptions
646
670
647
- def screenshot (self , widget : QWidget , suffix : str = "" , region : Optional [QRect ]= None ) -> Path :
671
+ def screenshot (
672
+ self , widget : QWidget , suffix : str = "" , region : Optional [QRect ] = None
673
+ ) -> Path :
648
674
"""
649
675
.. versionadded:: 4.1
650
676
@@ -799,7 +825,9 @@ class _WaitWidgetContextManager:
799
825
Context manager implementation used by ``waitActive`` and ``waitExposed`` methods.
800
826
"""
801
827
802
- def __init__ (self , method_name : str , adjective_name : str , widget : QWidget , timeout : int ) -> None :
828
+ def __init__ (
829
+ self , method_name : str , adjective_name : str , widget : QWidget , timeout : int
830
+ ) -> None :
803
831
"""
804
832
:param str method_name: name to the ``QtTest`` method to call to check if widget is active/exposed.
805
833
:param str adjective_name: "activated" or "exposed".
@@ -815,7 +843,12 @@ def __enter__(self) -> Self:
815
843
__tracebackhide__ = True
816
844
return self
817
845
818
- def __exit__ (self , exc_type : Optional [Type [BaseException ]], exc_val : Optional [BaseException ], exc_tb : Optional [TracebackType ]) -> None :
846
+ def __exit__ (
847
+ self ,
848
+ exc_type : Optional [Type [BaseException ]],
849
+ exc_val : Optional [BaseException ],
850
+ exc_tb : Optional [TracebackType ],
851
+ ) -> None :
819
852
__tracebackhide__ = True
820
853
try :
821
854
if exc_type is None :
0 commit comments