Skip to content

Commit cadb031

Browse files
gsauthofronf
authored andcommitted
use context managers with aiofiles open
to make the tests more explicit and eliminate possible race conditions
1 parent 9ef1a23 commit cadb031

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

tests/test_process.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,10 +1210,9 @@ 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:
1216-
result = await conn.run('echo', stdin=file)
1213+
async with aiofiles.open('stdin', 'r') as file:
1214+
async with self.connect() as conn:
1215+
result = await conn.run('echo', stdin=file)
12171216

12181217
self.assertEqual(result.stdout, data)
12191218
self.assertEqual(result.stderr, data)
@@ -1227,10 +1226,9 @@ async def test_stdin_binary_aiofile(self):
12271226
with open('stdin', 'wb') as file:
12281227
file.write(data)
12291228

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

12351233
self.assertEqual(result.stdout, data)
12361234
self.assertEqual(result.stderr, data)
@@ -1241,10 +1239,9 @@ async def test_stdout_aiofile(self):
12411239

12421240
data = str(id(self))
12431241

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

12491246
with open('stdout') as file:
12501247
stdout_data = file.read()
@@ -1275,11 +1272,10 @@ async def test_stdout_binary_aiofile(self):
12751272

12761273
data = str(id(self)).encode() + b'\xff'
12771274

1278-
file = await aiofiles.open('stdout', 'wb')
1279-
1280-
async with self.connect() as conn:
1281-
result = await conn.run('echo', input=data, stdout=file,
1282-
encoding=None)
1275+
async with aiofiles.open('stdout', 'wb') as file:
1276+
async with self.connect() as conn:
1277+
result = await conn.run('echo', input=data, stdout=file,
1278+
encoding=None)
12831279

12841280
with open('stdout', 'rb') as file:
12851281
stdout_data = file.read()
@@ -1297,11 +1293,10 @@ async def test_pause_async_file_reader(self):
12971293
with open('stdin', 'w') as file:
12981294
file.write(data)
12991295

1300-
file = await aiofiles.open('stdin', 'r')
1301-
1302-
async with self.connect() as conn:
1303-
result = await conn.run('delay', stdin=file,
1304-
stderr=asyncssh.DEVNULL)
1296+
async with aiofiles.open('stdin', 'r') as file:
1297+
async with self.connect() as conn:
1298+
result = await conn.run('delay', stdin=file,
1299+
stderr=asyncssh.DEVNULL)
13051300

13061301
self.assertEqual(result.stdout, data)
13071302

0 commit comments

Comments
 (0)