@@ -793,6 +793,51 @@ async def mycoro():
793793 assert not loop .is_running ()
794794
795795
796+ def test_async_slot (loop ):
797+ no_args_called = asyncio .Event ()
798+ with_args_called = asyncio .Event ()
799+ trailing_args_called = asyncio .Event ()
800+
801+ async def slot_no_args ():
802+ no_args_called .set ()
803+
804+ async def slot_with_args (flag : bool ):
805+ assert flag
806+ with_args_called .set ()
807+
808+ async def slot_trailing_args (flag : bool ):
809+ assert flag
810+ trailing_args_called .set ()
811+
812+ async def slot_signature_mismatch (_ : bool ): ...
813+
814+ async def main ():
815+ # passing kwargs to the underlying Slot such as name, arguments, return
816+ sig = qasync ._make_signaller (qasync .QtCore )
817+ sig .signal .connect (qasync .asyncSlot (name = "slot" )(slot_no_args ))
818+ sig .signal .emit ()
819+
820+ sig1 = qasync ._make_signaller (qasync .QtCore , bool )
821+ sig1 .signal .connect (qasync .asyncSlot (bool )(slot_with_args ))
822+ sig1 .signal .emit (True )
823+
824+ # when a signal produces more arguments than a slot, trailing args are removed
825+ sig2 = qasync ._make_signaller (qasync .QtCore , bool , bool )
826+ sig2 .signal .connect (qasync .asyncSlot ()(slot_trailing_args ))
827+ sig2 .signal .emit (True , False )
828+
829+ # signature mismatch when called
830+ with pytest .raises (TypeError ):
831+ qasync .asyncSlot (bool )(slot_signature_mismatch )()
832+
833+ all_done = asyncio .gather (
834+ no_args_called .wait (), with_args_called .wait (), trailing_args_called .wait ()
835+ )
836+ await asyncio .wait_for (all_done , timeout = 1.0 )
837+
838+ loop .run_until_complete (main ())
839+
840+
796841@pytest .mark .parametrize (
797842 "async_wrap, expect_async_called, expect_exception" ,
798843 [(False , False , True ), (True , True , False )],
@@ -829,7 +874,6 @@ async def main():
829874 await coro # avoid warnings about unawaited coroutines
830875 assert res == 1
831876 main_called = True
832-
833877
834878 exceptions = []
835879 loop .set_exception_handler (lambda loop , context : exceptions .append (context ))
@@ -917,6 +961,7 @@ async def coro():
917961
918962 thread .join () # Ensure thread cleanup
919963
964+
920965def teardown_module (module ):
921966 """
922967 Remove handlers from all loggers
0 commit comments