@@ -384,40 +384,20 @@ async def test_exceptions(self) -> None:
384384 async def first_test () -> None :
385385 await test_object_connection .raise_base_exception ()
386386
387- loop = get_running_loop ()
388-
389- t1 = loop .create_task (first_test ())
390-
391- try :
392- await wait_for (t1 , timeout = 1 )
393- except DbusFailedError :
394- ...
395-
396- self .assertRaises (DbusFailedError , t1 .result )
387+ with self .assertRaises (DbusFailedError ):
388+ await wait_for (first_test (), timeout = 1 )
397389
398390 async def second_test () -> None :
399391 await test_object_connection .raise_derived_exception ()
400392
401- t2 = loop .create_task (second_test ())
402-
403- try :
404- await wait_for (t2 , timeout = 1 )
405- except DbusFileExistsError :
406- ...
407-
408- self .assertRaises (DbusFileExistsError , t2 .result )
393+ with self .assertRaises (DbusFileExistsError ):
394+ await wait_for (second_test (), timeout = 1 )
409395
410396 async def third_test () -> None :
411397 await test_object_connection .raise_custom_error ()
412398
413- t3 = loop .create_task (third_test ())
414-
415- try :
416- await wait_for (t3 , timeout = 1 )
417- except DbusFailedError :
418- ...
419-
420- self .assertRaises (DbusErrorTest , t3 .result )
399+ with self .assertRaises (DbusErrorTest ):
400+ await wait_for (third_test (), timeout = 1 )
421401
422402 def bad_exception_error_name_used () -> None :
423403 class BadDbusError (DbusFailedError ):
@@ -434,14 +414,8 @@ class BadDbusError(DbusFailedError):
434414 async def test_unmapped_expection () -> None :
435415 await test_object_connection .raise_and_unmap_error ()
436416
437- t4 = loop .create_task (test_unmapped_expection ())
438-
439- try :
440- await wait_for (t4 , timeout = 1 )
441- except SdBusUnmappedMessageError :
442- ...
443-
444- self .assertRaises (SdBusUnmappedMessageError , t4 .result )
417+ with self .assertRaises (SdBusUnmappedMessageError ):
418+ await wait_for (test_unmapped_expection (), timeout = 1 )
445419
446420 async def test_no_reply_method (self ) -> None :
447421 test_object , test_object_connection = initialize_object ()
@@ -460,16 +434,9 @@ async def test_interface_remove(self) -> None:
460434
461435 collect ()
462436
463- loop = get_running_loop ()
464-
465- t = loop .create_task (test_object_connection .dbus_introspect ())
466-
467- try :
468- await wait_for (t , timeout = 0.2 )
469- except DbusUnknownObjectError :
470- ...
471-
472- self .assertRaises (DbusUnknownObjectError , t .result )
437+ with self .assertRaises (DbusUnknownObjectError ):
438+ await wait_for (test_object_connection .dbus_introspect (),
439+ timeout = 0.2 )
473440
474441 def test_docstring (self ) -> None :
475442 test_object , test_object_connection = initialize_object ()
@@ -576,21 +543,13 @@ def test_constant(self) -> str:
576543 async def test_bus_close (self ) -> None :
577544 test_object , test_object_connection = initialize_object ()
578545
579- loop = get_running_loop ()
580-
581546 async def too_long_wait () -> None :
582547 await test_object_connection .looong_method ()
583548
584- t1 = loop .create_task (too_long_wait ())
585-
586549 self .bus .close ()
587550
588- try :
589- await wait_for (t1 , timeout = 1 )
590- except SdBusLibraryError :
591- ...
592-
593- self .assertRaises (SdBusLibraryError , t1 .result )
551+ with self .assertRaises (SdBusLibraryError ):
552+ await wait_for (too_long_wait (), timeout = 1 )
594553
595554 async def test_singal_queue_wildcard_match (self ) -> None :
596555 test_object , test_object_connection = initialize_object ()
0 commit comments