Skip to content

Commit b8052e0

Browse files
committed
use context managers with aiofiles open
to make the tests more explicit and eliminate possible race conditions
1 parent af5a81e commit b8052e0

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

tests/test_process.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,9 +1210,7 @@ async def test_stdin_aiofile(self):
12101210
with open('stdin', 'w') as file:
12111211
file.write(data)
12121212

1213-
file = await aiofiles.open('stdin', 'r')
1214-
1215-
async with self.connect() as conn:
1213+
async with self.connect() as conn, aiofiles.open('stdin', 'r') as file:
12161214
result = await conn.run('echo', stdin=file)
12171215

12181216
self.assertEqual(result.stdout, data)
@@ -1227,9 +1225,7 @@ async def test_stdin_binary_aiofile(self):
12271225
with open('stdin', 'wb') as file:
12281226
file.write(data)
12291227

1230-
file = await aiofiles.open('stdin', 'rb')
1231-
1232-
async with self.connect() as conn:
1228+
async with self.connect() as conn, aiofiles.open('stdin', 'rb') as file:
12331229
result = await conn.run('echo', stdin=file, encoding=None)
12341230

12351231
self.assertEqual(result.stdout, data)
@@ -1241,9 +1237,7 @@ async def test_stdout_aiofile(self):
12411237

12421238
data = str(id(self))
12431239

1244-
file = await aiofiles.open('stdout', 'w')
1245-
1246-
async with self.connect() as conn:
1240+
async with self.connect() as conn, aiofiles.open('stdout', 'w') as file:
12471241
result = await conn.run('echo', input=data, stdout=file)
12481242

12491243
with open('stdout') as file:
@@ -1275,9 +1269,7 @@ async def test_stdout_binary_aiofile(self):
12751269

12761270
data = str(id(self)).encode() + b'\xff'
12771271

1278-
file = await aiofiles.open('stdout', 'wb')
1279-
1280-
async with self.connect() as conn:
1272+
async with self.connect() as conn, aiofiles.open('stdout', 'wb') as file:
12811273
result = await conn.run('echo', input=data, stdout=file,
12821274
encoding=None)
12831275

@@ -1297,9 +1289,7 @@ async def test_pause_async_file_reader(self):
12971289
with open('stdin', 'w') as file:
12981290
file.write(data)
12991291

1300-
file = await aiofiles.open('stdin', 'r')
1301-
1302-
async with self.connect() as conn:
1292+
async with self.connect() as conn, aiofiles.open('stdin', 'r') as file:
13031293
result = await conn.run('delay', stdin=file,
13041294
stderr=asyncssh.DEVNULL)
13051295

0 commit comments

Comments
 (0)