@@ -700,34 +700,40 @@ class SubprocessPidfdWatcherTests(SubprocessWatcherMixin,
700
700
test_utils .TestCase ):
701
701
Watcher = unix_events .PidfdChildWatcher
702
702
703
- else :
704
- # Windows
705
- class SubprocessProactorTests (SubprocessMixin , test_utils .TestCase ):
706
-
707
- def setUp (self ):
708
- super ().setUp ()
709
- self .loop = asyncio .ProactorEventLoop ()
710
- self .set_event_loop (self .loop )
711
703
704
+ class GenericWatcherTests (test_utils .TestCase ):
712
705
713
- class GenericWatcherTests :
706
+ def test_create_subprocess_fails_with_inactive_watcher (self ):
707
+ watcher = mock .create_autospec (
708
+ asyncio .AbstractChildWatcher ,
709
+ ** {"__enter__.return_value.is_active.return_value" : False }
710
+ )
714
711
715
- def test_create_subprocess_fails_with_inactive_watcher (self ):
712
+ async def execute ():
713
+ asyncio .set_child_watcher (watcher )
716
714
717
- async def execute ():
718
- watcher = mock .create_authspec (asyncio .AbstractChildWatcher )
719
- watcher .is_active .return_value = False
720
- asyncio .set_child_watcher (watcher )
715
+ with self .assertRaises (RuntimeError ):
716
+ await subprocess .create_subprocess_exec (
717
+ os_helper .FakePath (sys .executable ), '-c' , 'pass' )
721
718
722
- with self .assertRaises (RuntimeError ):
723
- await subprocess .create_subprocess_exec (
724
- os_helper .FakePath (sys .executable ), '-c' , 'pass' )
719
+ watcher .add_child_handler .assert_not_called ()
725
720
726
- watcher .add_child_handler .assert_not_called ()
727
-
728
- self .assertIsNone (self .loop .run_until_complete (execute ()))
721
+ with asyncio .Runner (loop_factory = asyncio .new_event_loop ) as runner :
722
+ self .assertIsNone (runner .run (execute ()))
723
+ self .assertListEqual (watcher .mock_calls , [
724
+ mock .call .__enter__ (),
725
+ mock .call .__enter__ ().is_active (),
726
+ mock .call .__exit__ (RuntimeError , mock .ANY , mock .ANY ),
727
+ ])
729
728
729
+ else :
730
+ # Windows
731
+ class SubprocessProactorTests (SubprocessMixin , test_utils .TestCase ):
730
732
733
+ def setUp (self ):
734
+ super ().setUp ()
735
+ self .loop = asyncio .ProactorEventLoop ()
736
+ self .set_event_loop (self .loop )
731
737
732
738
733
739
if __name__ == '__main__' :
0 commit comments