Skip to content

Commit f894ac7

Browse files
claws1st1
authored andcommitted
Fix code style in unittest
1 parent 77dc53e commit f894ac7

File tree

10 files changed

+38
-73
lines changed

10 files changed

+38
-73
lines changed

tests/test_aiohttp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
else:
77
skip_tests = False
88

9-
import asyncio
10-
import uvloop
119
import unittest
1210

1311
from uvloop import _testbase as tb

tests/test_base.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def cb():
131131

132132
loop.set_debug(debug)
133133
if debug:
134-
msg = ("Non-thread-safe operation invoked on an event loop other "
135-
"than the current one")
134+
msg = ("Non-thread-safe operation invoked on an "
135+
"event loop other than the current one")
136136
with self.assertRaisesRegex(RuntimeError, msg):
137137
loop.call_soon(cb)
138138
with self.assertRaisesRegex(RuntimeError, msg):
@@ -189,6 +189,7 @@ def test_thread(loop, debug, create_loop=False):
189189

190190
def test_run_once_in_executor_plain(self):
191191
called = []
192+
192193
def cb(arg):
193194
called.append(arg)
194195

@@ -206,18 +207,17 @@ def test_set_debug(self):
206207
self.assertFalse(self.loop.get_debug())
207208

208209
def test_run_until_complete_type_error(self):
209-
self.assertRaises(TypeError,
210-
self.loop.run_until_complete, 'blah')
210+
self.assertRaises(
211+
TypeError, self.loop.run_until_complete, 'blah')
211212

212213
def test_run_until_complete_loop(self):
213214
task = asyncio.Future(loop=self.loop)
214215
other_loop = self.new_loop()
215216
self.addCleanup(other_loop.close)
216-
self.assertRaises(ValueError,
217-
other_loop.run_until_complete, task)
217+
self.assertRaises(
218+
ValueError, other_loop.run_until_complete, task)
218219

219220
def test_run_until_complete_error(self):
220-
task = asyncio.Future(loop=self.loop)
221221
async def foo():
222222
raise ValueError('aaa')
223223
with self.assertRaisesRegex(ValueError, 'aaa'):
@@ -228,7 +228,7 @@ def test_default_exc_handler_callback(self):
228228

229229
def zero_error(fut):
230230
fut.set_result(True)
231-
1/0
231+
1 / 0
232232

233233
logger = logging.getLogger('asyncio')
234234

@@ -258,11 +258,12 @@ def test_set_exc_handler_custom(self):
258258
def run_loop():
259259
def zero_error():
260260
self.loop.stop()
261-
1/0
261+
1 / 0
262262
self.loop.call_soon(zero_error)
263263
self.loop.run_forever()
264264

265265
errors = []
266+
266267
def handler(loop, exc):
267268
errors.append(exc)
268269

@@ -278,8 +279,8 @@ def handler(loop, exc):
278279
with mock.patch.object(logger, 'error') as log:
279280
run_loop()
280281
log.assert_called_with(
281-
self.mock_pattern('Exception in callback.*zero'),
282-
exc_info=mock.ANY)
282+
self.mock_pattern('Exception in callback.*zero'),
283+
exc_info=mock.ANY)
283284

284285
self.assertEqual(len(errors), 1)
285286

@@ -289,7 +290,7 @@ def test_set_exc_handler_broken(self):
289290
def run_loop():
290291
def zero_error():
291292
self.loop.stop()
292-
1/0
293+
1 / 0
293294
self.loop.call_soon(zero_error)
294295
self.loop.run_forever()
295296

@@ -328,7 +329,7 @@ def default_exception_handler(self, context):
328329
def run_loop():
329330
def zero_error():
330331
loop.stop()
331-
1/0
332+
1 / 0
332333
loop.call_soon(zero_error)
333334
loop.run_forever()
334335

@@ -358,7 +359,8 @@ def custom_handler(loop, context):
358359

359360
def test_set_task_factory_invalid(self):
360361
with self.assertRaisesRegex(
361-
TypeError, 'task factory must be a callable or None'):
362+
TypeError,
363+
'task factory must be a callable or None'):
362364

363365
self.loop.set_task_factory(1)
364366

tests/test_dns.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import asyncio
21
import socket
3-
import uvloop
42
import unittest
53

64
from uvloop import _testbase as tb
@@ -136,6 +134,6 @@ async def run():
136134

137135

138136
class Test_AIO_DNS(BaseTestDNS, tb.AIOTestCase):
139-
pass
137+
140138
def test_getaddrinfo_11(self):
141139
self._test_getaddrinfo(_HOST.encode(), str(_PORT))

tests/test_pipes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def test_write_pipe(self):
147147
transport.write(b'1')
148148

149149
data = bytearray()
150+
150151
def reader(data):
151152
chunk = os.read(rpipe, 1024)
152153
data += chunk
@@ -205,6 +206,7 @@ def test_write_pty(self):
205206
transport.write(b'1')
206207

207208
data = bytearray()
209+
208210
def reader(data):
209211
chunk = os.read(master, 1024)
210212
data += chunk

tests/test_process.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import asyncio
22
import contextlib
33
import signal
4-
import socket
54
import subprocess
65
import sys
76
import tempfile
8-
import uvloop
97

108
from asyncio import test_utils
119
from uvloop import _testbase as tb
12-
from test import support
1310

1411

1512
class _TestProcess:
@@ -276,12 +273,12 @@ def test_stdin_not_inheritable(self):
276273
def len_message(message):
277274
code = 'import sys; data = sys.stdin.read(); print(len(data))'
278275
proc = yield from asyncio.create_subprocess_exec(
279-
sys.executable, '-c', code,
280-
stdin=asyncio.subprocess.PIPE,
281-
stdout=asyncio.subprocess.PIPE,
282-
stderr=asyncio.subprocess.PIPE,
283-
close_fds=False,
284-
loop=self.loop)
276+
sys.executable, '-c', code,
277+
stdin=asyncio.subprocess.PIPE,
278+
stdout=asyncio.subprocess.PIPE,
279+
stderr=asyncio.subprocess.PIPE,
280+
close_fds=False,
281+
loop=self.loop)
285282
stdout, stderr = yield from proc.communicate(message)
286283
exitcode = yield from proc.wait()
287284
return (stdout, exitcode)
@@ -296,10 +293,10 @@ def test_stdin_stdout(self):
296293
@asyncio.coroutine
297294
def run(data):
298295
proc = yield from asyncio.create_subprocess_exec(
299-
*args,
300-
stdin=subprocess.PIPE,
301-
stdout=subprocess.PIPE,
302-
loop=self.loop)
296+
*args,
297+
stdin=subprocess.PIPE,
298+
stdout=subprocess.PIPE,
299+
loop=self.loop)
303300

304301
# feed data
305302
proc.stdin.write(data)
@@ -323,10 +320,10 @@ def test_communicate(self):
323320
@asyncio.coroutine
324321
def run(data):
325322
proc = yield from asyncio.create_subprocess_exec(
326-
*args,
327-
stdin=subprocess.PIPE,
328-
stdout=subprocess.PIPE,
329-
loop=self.loop)
323+
*args,
324+
stdin=subprocess.PIPE,
325+
stdout=subprocess.PIPE,
326+
loop=self.loop)
330327
stdout, stderr = yield from proc.communicate(data)
331328
return proc.returncode, stdout
332329

@@ -389,35 +386,14 @@ def send_signal(proc):
389386
returncode = self.loop.run_until_complete(send_signal(proc))
390387
self.assertEqual(-signal.SIGHUP, returncode)
391388

392-
def test_stdin_not_inheritable(self):
393-
# asyncio issue #209: stdin must not be inheritable, otherwise
394-
# the Process.communicate() hangs
395-
@asyncio.coroutine
396-
def len_message(message):
397-
code = 'import sys; data = sys.stdin.read(); print(len(data))'
398-
proc = yield from asyncio.create_subprocess_exec(
399-
sys.executable, '-c', code,
400-
stdin=asyncio.subprocess.PIPE,
401-
stdout=asyncio.subprocess.PIPE,
402-
stderr=asyncio.subprocess.PIPE,
403-
close_fds=False,
404-
loop=self.loop)
405-
stdout, stderr = yield from proc.communicate(message)
406-
exitcode = yield from proc.wait()
407-
return (stdout, exitcode)
408-
409-
output, exitcode = self.loop.run_until_complete(len_message(b'abc'))
410-
self.assertEqual(output.rstrip(), b'3')
411-
self.assertEqual(exitcode, 0)
412-
413389
def test_cancel_process_wait(self):
414390
# Issue #23140: cancel Process.wait()
415391

416392
@asyncio.coroutine
417393
def cancel_wait():
418394
proc = yield from asyncio.create_subprocess_exec(
419-
*self.PROGRAM_BLOCKED,
420-
loop=self.loop)
395+
*self.PROGRAM_BLOCKED,
396+
loop=self.loop)
421397

422398
# Create an internal future waiting on the process exit
423399
task = self.loop.create_task(proc.wait())

tests/test_signals.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import subprocess
44
import sys
55
import time
6-
import uvloop
76

87
from uvloop import _testbase as tb
98

tests/test_sockets.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import asyncio
21
import socket
3-
import uvloop
42

53
from uvloop import _testbase as tb
64

tests/test_tcp.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import asyncio
2-
import logging
32
import socket
43
import uvloop
5-
import ssl
64
import sys
7-
import warnings
85

96
from uvloop import _testbase as tb
107

tests/test_udp.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import asyncio
2-
import logging
32
import socket
43
import uvloop
5-
import ssl
64
import sys
7-
import warnings
85

96
from asyncio import test_utils
107
from uvloop import _testbase as tb

tests/test_unix.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import os
33
import socket
44
import tempfile
5-
import uvloop
6-
import unittest.mock
75

86
from uvloop import _testbase as tb
97

@@ -114,7 +112,6 @@ async def start_server_sock():
114112
for srv_sock in srv_socks:
115113
self.assertEqual(srv_sock.fileno(), -1)
116114

117-
118115
self.loop.run_until_complete(start_server())
119116
self.assertEqual(CNT, TOTAL_CNT)
120117

@@ -246,7 +243,8 @@ def run(coro):
246243
for _ in range(TOTAL_CNT):
247244
tasks.append(coro(srv.addr))
248245

249-
self.loop.run_until_complete(asyncio.gather(*tasks, loop=self.loop))
246+
self.loop.run_until_complete(
247+
asyncio.gather(*tasks, loop=self.loop))
250248
srv.join()
251249
self.assertEqual(CNT, TOTAL_CNT)
252250

@@ -293,7 +291,7 @@ async def client():
293291

294292
self.assertEqual(len(excs), 1)
295293
self.assertIn(excs[0].__class__,
296-
(BrokenPipeError, ConnectionResetError))
294+
(BrokenPipeError, ConnectionResetError))
297295

298296
def test_transport_fromsock_get_extra_info(self):
299297
async def test(sock):

0 commit comments

Comments
 (0)