22from types import TracebackType
33import weakref
44import 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+ )
618from pathlib import Path
719
820from pytestqt .exceptions import TimeoutError , ScreenshotError
@@ -190,7 +202,9 @@ def _should_raise(self, raising_arg: Optional[bool]) -> bool:
190202 else :
191203 return True
192204
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 :
194208 """
195209 Adds a widget to be tracked by this bot. This is not required, but will ensure that the
196210 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
208222 raise TypeError (f"Need to pass a QWidget to addWidget: { widget !r} " )
209223 _add_widget (self ._request .node , widget , before_close_func = before_close_func )
210224
211- def waitActive (self , widget : QWidget , * , timeout : int = 5000 ) -> "_WaitWidgetContextManager" :
225+ def waitActive (
226+ self , widget : QWidget , * , timeout : int = 5000
227+ ) -> "_WaitWidgetContextManager" :
212228 """
213229 Context manager that waits for ``timeout`` milliseconds or until the window is active.
214230 If window is not exposed within ``timeout`` milliseconds, raise
@@ -235,7 +251,9 @@ def waitActive(self, widget: QWidget, *, timeout: int = 5000) -> "_WaitWidgetCon
235251 "qWaitForWindowActive" , "activated" , widget , timeout
236252 )
237253
238- def waitExposed (self , widget : QWidget , * , timeout : int = 5000 ) -> "_WaitWidgetContextManager" :
254+ def waitExposed (
255+ self , widget : QWidget , * , timeout : int = 5000
256+ ) -> "_WaitWidgetContextManager" :
239257 """
240258 Context manager that waits for ``timeout`` milliseconds or until the window is exposed.
241259 If the window is not exposed within ``timeout`` milliseconds, raise
@@ -387,10 +405,10 @@ def waitSignals(
387405 self ,
388406 signals : List [SignalInstance ],
389407 * ,
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" ,
394412 ) -> "MultiSignalBlocker" :
395413 """
396414 .. versionadded:: 1.4
@@ -486,7 +504,9 @@ def wait(self, ms: int) -> None:
486504 blocker .wait ()
487505
488506 @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 ]:
490510 """
491511 .. versionadded:: 1.11
492512
@@ -507,7 +527,9 @@ def assertNotEmitted(self, signal: SignalInstance, *, wait: int=0) -> Generator[
507527 yield
508528 spy .assert_not_emitted ()
509529
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 :
511533 """
512534 .. versionadded:: 2.0
513535
@@ -578,7 +600,9 @@ def timed_out():
578600 raise TimeoutError (timeout_msg )
579601 self .wait (10 )
580602
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" :
582606 """
583607 .. versionadded:: 3.1
584608
@@ -644,7 +668,9 @@ def captureExceptions(self) -> Generator["CapturedExceptions", None, None]:
644668 with capture_exceptions () as exceptions :
645669 yield exceptions
646670
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 :
648674 """
649675 .. versionadded:: 4.1
650676
@@ -799,7 +825,9 @@ class _WaitWidgetContextManager:
799825 Context manager implementation used by ``waitActive`` and ``waitExposed`` methods.
800826 """
801827
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 :
803831 """
804832 :param str method_name: name to the ``QtTest`` method to call to check if widget is active/exposed.
805833 :param str adjective_name: "activated" or "exposed".
@@ -815,7 +843,12 @@ def __enter__(self) -> Self:
815843 __tracebackhide__ = True
816844 return self
817845
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 :
819852 __tracebackhide__ = True
820853 try :
821854 if exc_type is None :
0 commit comments