@@ -1707,7 +1707,6 @@ def test_async(self):
17071707 )
17081708
17091709 alternating = []
1710- q = AQueue ()
17111710
17121711 async def producer (q ):
17131712 alternating .append (1 )
@@ -1722,19 +1721,20 @@ async def consumer(q):
17221721 self .assertEqual (msg , "hello" )
17231722 alternating .append (2 )
17241723
1725- loop = asyncio .get_event_loop ()
1726- fut = asyncio .gather (producer (q ), consumer (q ))
1727- loop .run_until_complete (fut )
1724+ async def main ():
1725+ q = AQueue ()
1726+ await asyncio .gather (producer (q ), consumer (q ))
1727+
1728+ asyncio .run (main ())
17281729 self .assertListEqual (alternating , [1 , 2 , 1 , 2 ])
17291730
17301731 def test_async_exc (self ):
17311732 py = create_tmp_test ("""exit(34)""" )
17321733
17331734 async def producer ():
1734- await python (py .name , _async = True )
1735+ await python (py .name , _async = True , _return_cmd = False )
17351736
1736- loop = asyncio .get_event_loop ()
1737- self .assertRaises (sh .ErrorReturnCode_34 , loop .run_until_complete , producer ())
1737+ self .assertRaises (sh .ErrorReturnCode_34 , asyncio .run , producer ())
17381738
17391739 def test_async_iter (self ):
17401740 py = create_tmp_test (
@@ -1743,7 +1743,6 @@ def test_async_iter(self):
17431743 print(i)
17441744"""
17451745 )
1746- q = AQueue ()
17471746
17481747 # this list will prove that our coroutines are yielding to eachother as each
17491748 # line is produced
@@ -1763,9 +1762,11 @@ async def consumer(q):
17631762 return
17641763 alternating .append (2 )
17651764
1766- loop = asyncio .get_event_loop ()
1767- res = asyncio .gather (producer (q ), consumer (q ))
1768- loop .run_until_complete (res )
1765+ async def main ():
1766+ q = AQueue ()
1767+ await asyncio .gather (producer (q ), consumer (q ))
1768+
1769+ asyncio .run (main ())
17691770 self .assertListEqual (alternating , [1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 ])
17701771
17711772 def test_async_iter_exc (self ):
@@ -1783,8 +1784,23 @@ async def producer():
17831784 async for line in python (py .name , _async = True ):
17841785 lines .append (int (line .strip ()))
17851786
1786- loop = asyncio .get_event_loop ()
1787- self .assertRaises (sh .ErrorReturnCode_34 , loop .run_until_complete , producer ())
1787+ self .assertRaises (sh .ErrorReturnCode_34 , asyncio .run , producer ())
1788+
1789+ def test_async_return_cmd (self ):
1790+ py = create_tmp_test (
1791+ """
1792+ import sys
1793+ sys.exit(0)
1794+ """
1795+ )
1796+
1797+ async def main ():
1798+ result = await python (py .name , _async = True , _return_cmd = True )
1799+ self .assertIsInstance (result , sh .RunningCommand )
1800+ result_str = await python (py .name , _async = True , _return_cmd = False )
1801+ self .assertIsInstance (result_str , str )
1802+
1803+ asyncio .run (main ())
17881804
17891805 def test_handle_both_out_and_err (self ):
17901806 py = create_tmp_test (
0 commit comments