Skip to content

Commit 54dcd33

Browse files
author
Sergei Voronezhskii
committed
Fix flake8
1 parent 240367a commit 54dcd33

File tree

3 files changed

+62
-40
lines changed

3 files changed

+62
-40
lines changed

lib/test.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import difflib
2+
import filecmp
3+
import gevent
14
import os
5+
import pprint
6+
import pytap13
27
import re
8+
import shutil
39
import sys
410
import time
5-
import filecmp
6-
import difflib
711
import traceback
8-
import gevent
9-
import pytap13
10-
import pprint
11-
import shutil
1212
from functools import partial
1313

1414
try:
@@ -17,8 +17,9 @@
1717
from StringIO import StringIO
1818

1919
import lib
20-
from lib.utils import non_empty_valgrind_logs, print_tail_n
2120
from lib.colorer import color_stdout
21+
from lib.utils import non_empty_valgrind_logs
22+
from lib.utils import print_tail_n
2223

2324

2425
class TestExecutionError(OSError):
@@ -37,7 +38,10 @@ def _run(self, *args, **kwargs):
3738
self.callable(*self.callable_args, **self.callable_kwargs)
3839

3940
def __repr__(self):
40-
return "<TestRunGreenlet at %s info='%s'>" % (hex(id(self)), getattr(self, "info", None))
41+
return "<TestRunGreenlet at {0} info='{1}'>".format(
42+
hex(id(self)),
43+
getattr(self, "info", None)
44+
)
4145

4246

4347
class FilteredStream:
@@ -134,7 +138,9 @@ def id(self):
134138

135139
def passed(self):
136140
"""Return true if this test was run successfully."""
137-
return self.is_executed and self.is_executed_ok and self.is_equal_result
141+
return (self.is_executed and
142+
self.is_executed_ok and
143+
self.is_equal_result)
138144

139145
def execute(self, server):
140146
# Note: don't forget to set 'server.current_test = self' in
@@ -180,8 +186,9 @@ def run(self, server):
180186
if e.__class__.__name__ == 'TarantoolStartError':
181187
# worker should stop
182188
raise
183-
color_stdout('\nTest.run() received the following error:\n' +
184-
traceback.format_exc() + '\n', schema='error')
189+
color_stdout('\nTest.run() received the following error:\n'
190+
'{0}\n'.format(traceback.format_exc()),
191+
schema='error')
185192
diagnostics = str(e)
186193
finally:
187194
if sys.stdout and sys.stdout != save_stdout:
@@ -193,7 +200,8 @@ def run(self, server):
193200
is_tap = False
194201
if not self.skip:
195202
if self.is_executed_ok and os.path.isfile(self.result):
196-
self.is_equal_result = filecmp.cmp(self.result, self.tmp_result)
203+
self.is_equal_result = filecmp.cmp(self.result,
204+
self.tmp_result)
197205
elif self.is_executed_ok:
198206
if lib.Options().args.is_verbose:
199207
color_stdout('\n')
@@ -216,12 +224,15 @@ def run(self, server):
216224
color_stdout("[ skip ]\n", schema='test_skip')
217225
if os.path.exists(self.tmp_result):
218226
os.remove(self.tmp_result)
219-
elif self.is_executed_ok and self.is_equal_result and self.is_valgrind_clean:
227+
elif (self.is_executed_ok and
228+
self.is_equal_result and
229+
self.is_valgrind_clean):
220230
short_status = 'pass'
221231
color_stdout("[ pass ]\n", schema='test_pass')
222232
if os.path.exists(self.tmp_result):
223233
os.remove(self.tmp_result)
224-
elif (self.is_executed_ok and not self.is_equal_result and not
234+
elif (self.is_executed_ok and not
235+
self.is_equal_result and not
225236
os.path.isfile(self.result)) and not is_tap:
226237
shutil.copy(self.tmp_result, self.result)
227238
short_status = 'new'
@@ -234,9 +245,11 @@ def run(self, server):
234245
where = ""
235246
if not self.is_crash_reported and not self.is_executed_ok:
236247
self.print_diagnostics(self.reject,
237-
"Test failed! Output from reject file {}:\n".format(self.reject))
248+
"Test failed! Output from reject file "
249+
"{0}:\n".format(self.reject))
238250
server.print_log(15)
239-
where = ": test execution aborted, reason '{0}'".format(diagnostics)
251+
where = ": test execution aborted, reason " \
252+
"'{0}'".format(diagnostics)
240253
elif not self.is_crash_reported and not self.is_equal_result:
241254
self.print_unidiff()
242255
server.print_log(15)
@@ -245,7 +258,8 @@ def run(self, server):
245258
os.remove(self.reject)
246259
for log_file in non_empty_logs:
247260
self.print_diagnostics(log_file,
248-
"Test failed! Output from log file {}:\n".format(log_file))
261+
"Test failed! Output from log file "
262+
"{0}:\n".format(log_file))
249263
where = ": there were warnings in the valgrind log file(s)"
250264
return short_status
251265

@@ -261,7 +275,8 @@ def print_unidiff(self):
261275
to establish the cause of a failure when .test differs
262276
from .result."""
263277

264-
color_stdout("\nTest failed! Result content mismatch:\n", schema='error')
278+
color_stdout("\nTest failed! Result content mismatch:\n",
279+
schema='error')
265280
with open(self.result, "r") as result:
266281
with open(self.reject, "r") as reject:
267282
result_time = time.ctime(os.stat(self.result).st_mtime)
@@ -306,7 +321,8 @@ def tap_parse_print_yaml(self, yml):
306321
def check_tap_output(self):
307322
""" Returns is_tap, is_ok """
308323
if not os.path.isfile(self.tmp_result):
309-
color_stdout('\nCannot find %s\n' % self.tmp_result, schema='error')
324+
color_stdout('\nCannot find %s\n' % self.tmp_result,
325+
schema='error')
310326
self.is_crash_reported = True
311327
return False
312328
with open(self.tmp_result, 'r') as f:
@@ -315,7 +331,8 @@ def check_tap_output(self):
315331
try:
316332
tap.parse(content)
317333
except ValueError as e:
318-
color_stdout('\nTAP13 parse failed: %s\n' % str(e), schema='error')
334+
color_stdout('\nTAP13 parse failed: %s\n' % str(e),
335+
schema='error')
319336
self.is_crash_reported = True
320337
return False, False
321338
is_ok = True
@@ -334,6 +351,7 @@ def check_tap_output(self):
334351
self.tap_parse_print_yaml(test_case.yaml)
335352
is_ok = False
336353
if not is_ok:
337-
color_stdout('Rejected result file: %s\n' % self.reject, schema='test_var')
354+
color_stdout('Rejected result file: %s\n' % self.reject,
355+
schema='test_var')
338356
self.is_crash_reported = True
339357
return True, is_ok

lib/worker.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
import collections
2+
import copy
3+
import functools
14
import os
25
import signal
36
import traceback
47
import yaml
5-
import copy
6-
import functools
7-
import collections
88

99
import lib
10-
from lib.utils import safe_makedirs
11-
from lib.test_suite import TestSuite
12-
from lib.test import get_result
13-
from lib.colorer import color_stdout, color_log
10+
from lib.colorer import color_log
11+
from lib.colorer import color_stdout
1412
from lib.tarantool_server import TarantoolServer
13+
from lib.test import get_result
14+
from lib.test_suite import TestSuite
15+
from lib.utils import safe_makedirs
1516

1617
# Utils
1718
#######
@@ -287,7 +288,7 @@ def run_task(self, task_id):
287288
except KeyboardInterrupt:
288289
self.report_keyboard_interrupt()
289290
raise
290-
except Exception as e:
291+
except Exception:
291292
color_stdout(
292293
'\nWorker "%s" received the following error; stopping...\n'
293294
% self.name + traceback.format_exc() + '\n', schema='error')
@@ -330,7 +331,8 @@ def run_all(self, task_queue, result_queue):
330331
try:
331332
self.run_loop(task_queue, result_queue)
332333
except (KeyboardInterrupt, Exception) as e:
333-
if not isinstance(e, KeyboardInterrupt):
334+
if not isinstance(e, KeyboardInterrupt) and \
335+
not isinstance(e, VoluntaryStopException):
334336
color_stdout('Exception: %s\n' % e, schema='error')
335337
self.stop_worker(task_queue, result_queue, cleanup=False)
336338

listeners.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import yaml
55

66
import lib
7-
from lib.worker import get_reproduce_file
8-
from lib.worker import WorkerOutput, WorkerDone, WorkerTaskResult, WorkerCurrentTask
97
from lib.colorer import color_stdout
8+
from lib.worker import WorkerCurrentTask
9+
from lib.worker import WorkerDone
10+
from lib.worker import WorkerOutput
11+
from lib.worker import WorkerTaskResult
12+
from lib.worker import get_reproduce_file
1013

1114

1215
class BaseWatcher(object):
@@ -170,8 +173,8 @@ class HangError(Exception):
170173

171174
class HangWatcher(BaseWatcher):
172175
"""Terminate all workers if no output received 'no_output_times' time."""
173-
def __init__(self, get_not_done_worker_ids, kill_all_workers, warn_timeout,
174-
kill_timeout):
176+
def __init__(self, get_not_done_worker_ids, kill_all_workers,
177+
warn_timeout, kill_timeout):
175178
self.get_not_done_worker_ids = get_not_done_worker_ids
176179
self.kill_all_workers = kill_all_workers
177180
self.warn_timeout = warn_timeout
@@ -195,11 +198,11 @@ def process_timeout(self, delta_seconds):
195198
if self.warned_seconds_ago < self.warn_timeout:
196199
return
197200

198-
color_stdout("No output during %d seconds. "
199-
"Will abort after %d seconds without output. "
200-
"List of workers not reporting the status:\n" % (
201-
self.inactivity, self.kill_timeout),
202-
schema='test_var')
201+
color_stdout(
202+
"No output during {0.inactivity:.0f} seconds. "
203+
"Will abort after {0.kill_timeout:.0f} seconds without output. "
204+
"List of workers not reporting the status:\n".format(self),
205+
schema='test_var')
203206

204207
hung_tasks = [task for worker_id, task
205208
in self.worker_current_task.iteritems()
@@ -215,7 +218,6 @@ def process_timeout(self, delta_seconds):
215218
lib.utils.print_tail_n(current_task.task_result_filepath,
216219
num_lines=15)
217220

218-
219221
self.warned_seconds_ago = 0.0
220222

221223
if self.inactivity < self.kill_timeout:

0 commit comments

Comments
 (0)