From cc0de90a0543dcae55acd734e831df5a8e2cdcb2 Mon Sep 17 00:00:00 2001 From: Sergei Voronezhskii Date: Sun, 19 Aug 2018 16:36:43 +0300 Subject: [PATCH] Fix flake8 --- lib/test.py | 60 +++++++++++++++++++++++++++++++++------------------ lib/worker.py | 20 +++++++++-------- listeners.py | 24 +++++++++++---------- 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/lib/test.py b/lib/test.py index 5cf8a78f..03360de1 100644 --- a/lib/test.py +++ b/lib/test.py @@ -1,14 +1,14 @@ +import difflib +import filecmp +import gevent import os +import pprint +import pytap13 import re +import shutil import sys import time -import filecmp -import difflib import traceback -import gevent -import pytap13 -import pprint -import shutil from functools import partial try: @@ -17,8 +17,9 @@ from StringIO import StringIO import lib -from lib.utils import non_empty_valgrind_logs, print_tail_n from lib.colorer import color_stdout +from lib.utils import non_empty_valgrind_logs +from lib.utils import print_tail_n class TestExecutionError(OSError): @@ -37,7 +38,10 @@ def _run(self, *args, **kwargs): self.callable(*self.callable_args, **self.callable_kwargs) def __repr__(self): - return "" % (hex(id(self)), getattr(self, "info", None)) + return "".format( + hex(id(self)), + getattr(self, "info", None) + ) class FilteredStream: @@ -134,7 +138,9 @@ def id(self): def passed(self): """Return true if this test was run successfully.""" - return self.is_executed and self.is_executed_ok and self.is_equal_result + return (self.is_executed and + self.is_executed_ok and + self.is_equal_result) def execute(self, server): # Note: don't forget to set 'server.current_test = self' in @@ -180,8 +186,9 @@ def run(self, server): if e.__class__.__name__ == 'TarantoolStartError': # worker should stop raise - color_stdout('\nTest.run() received the following error:\n' + - traceback.format_exc() + '\n', schema='error') + color_stdout('\nTest.run() received the following error:\n' + '{0}\n'.format(traceback.format_exc()), + schema='error') diagnostics = str(e) finally: if sys.stdout and sys.stdout != save_stdout: @@ -193,7 +200,8 @@ def run(self, server): is_tap = False if not self.skip: if self.is_executed_ok and os.path.isfile(self.result): - self.is_equal_result = filecmp.cmp(self.result, self.tmp_result) + self.is_equal_result = filecmp.cmp(self.result, + self.tmp_result) elif self.is_executed_ok: if lib.Options().args.is_verbose: color_stdout('\n') @@ -216,12 +224,15 @@ def run(self, server): color_stdout("[ skip ]\n", schema='test_skip') if os.path.exists(self.tmp_result): os.remove(self.tmp_result) - elif self.is_executed_ok and self.is_equal_result and self.is_valgrind_clean: + elif (self.is_executed_ok and + self.is_equal_result and + self.is_valgrind_clean): short_status = 'pass' color_stdout("[ pass ]\n", schema='test_pass') if os.path.exists(self.tmp_result): os.remove(self.tmp_result) - elif (self.is_executed_ok and not self.is_equal_result and not + elif (self.is_executed_ok and not + self.is_equal_result and not os.path.isfile(self.result)) and not is_tap: shutil.copy(self.tmp_result, self.result) short_status = 'new' @@ -234,9 +245,11 @@ def run(self, server): where = "" if not self.is_crash_reported and not self.is_executed_ok: self.print_diagnostics(self.reject, - "Test failed! Output from reject file {}:\n".format(self.reject)) + "Test failed! Output from reject file " + "{0}:\n".format(self.reject)) server.print_log(15) - where = ": test execution aborted, reason '{0}'".format(diagnostics) + where = ": test execution aborted, reason " \ + "'{0}'".format(diagnostics) elif not self.is_crash_reported and not self.is_equal_result: self.print_unidiff() server.print_log(15) @@ -245,7 +258,8 @@ def run(self, server): os.remove(self.reject) for log_file in non_empty_logs: self.print_diagnostics(log_file, - "Test failed! Output from log file {}:\n".format(log_file)) + "Test failed! Output from log file " + "{0}:\n".format(log_file)) where = ": there were warnings in the valgrind log file(s)" return short_status @@ -261,7 +275,8 @@ def print_unidiff(self): to establish the cause of a failure when .test differs from .result.""" - color_stdout("\nTest failed! Result content mismatch:\n", schema='error') + color_stdout("\nTest failed! Result content mismatch:\n", + schema='error') with open(self.result, "r") as result: with open(self.reject, "r") as reject: result_time = time.ctime(os.stat(self.result).st_mtime) @@ -306,7 +321,8 @@ def tap_parse_print_yaml(self, yml): def check_tap_output(self): """ Returns is_tap, is_ok """ if not os.path.isfile(self.tmp_result): - color_stdout('\nCannot find %s\n' % self.tmp_result, schema='error') + color_stdout('\nCannot find %s\n' % self.tmp_result, + schema='error') self.is_crash_reported = True return False with open(self.tmp_result, 'r') as f: @@ -315,7 +331,8 @@ def check_tap_output(self): try: tap.parse(content) except ValueError as e: - color_stdout('\nTAP13 parse failed: %s\n' % str(e), schema='error') + color_stdout('\nTAP13 parse failed: %s\n' % str(e), + schema='error') self.is_crash_reported = True return False, False is_ok = True @@ -334,6 +351,7 @@ def check_tap_output(self): self.tap_parse_print_yaml(test_case.yaml) is_ok = False if not is_ok: - color_stdout('Rejected result file: %s\n' % self.reject, schema='test_var') + color_stdout('Rejected result file: %s\n' % self.reject, + schema='test_var') self.is_crash_reported = True return True, is_ok diff --git a/lib/worker.py b/lib/worker.py index a5958bab..c6e8c58f 100644 --- a/lib/worker.py +++ b/lib/worker.py @@ -1,17 +1,18 @@ +import collections +import copy +import functools import os import signal import traceback import yaml -import copy -import functools -import collections import lib -from lib.utils import safe_makedirs -from lib.test_suite import TestSuite -from lib.test import get_result -from lib.colorer import color_stdout, color_log +from lib.colorer import color_log +from lib.colorer import color_stdout from lib.tarantool_server import TarantoolServer +from lib.test import get_result +from lib.test_suite import TestSuite +from lib.utils import safe_makedirs # Utils ####### @@ -287,7 +288,7 @@ def run_task(self, task_id): except KeyboardInterrupt: self.report_keyboard_interrupt() raise - except Exception as e: + except Exception: color_stdout( '\nWorker "%s" received the following error; stopping...\n' % self.name + traceback.format_exc() + '\n', schema='error') @@ -330,7 +331,8 @@ def run_all(self, task_queue, result_queue): try: self.run_loop(task_queue, result_queue) except (KeyboardInterrupt, Exception) as e: - if not isinstance(e, KeyboardInterrupt): + if not isinstance(e, KeyboardInterrupt) and \ + not isinstance(e, VoluntaryStopException): color_stdout('Exception: %s\n' % e, schema='error') self.stop_worker(task_queue, result_queue, cleanup=False) diff --git a/listeners.py b/listeners.py index 643f3775..5e95325e 100644 --- a/listeners.py +++ b/listeners.py @@ -4,9 +4,12 @@ import yaml import lib -from lib.worker import get_reproduce_file -from lib.worker import WorkerOutput, WorkerDone, WorkerTaskResult, WorkerCurrentTask from lib.colorer import color_stdout +from lib.worker import WorkerCurrentTask +from lib.worker import WorkerDone +from lib.worker import WorkerOutput +from lib.worker import WorkerTaskResult +from lib.worker import get_reproduce_file class BaseWatcher(object): @@ -170,8 +173,8 @@ class HangError(Exception): class HangWatcher(BaseWatcher): """Terminate all workers if no output received 'no_output_times' time.""" - def __init__(self, get_not_done_worker_ids, kill_all_workers, warn_timeout, - kill_timeout): + def __init__(self, get_not_done_worker_ids, kill_all_workers, + warn_timeout, kill_timeout): self.get_not_done_worker_ids = get_not_done_worker_ids self.kill_all_workers = kill_all_workers self.warn_timeout = warn_timeout @@ -195,17 +198,17 @@ def process_timeout(self, delta_seconds): if self.warned_seconds_ago < self.warn_timeout: return - color_stdout("No output during %d seconds. " - "Will abort after %d seconds without output. " - "List of workers not reporting the status:\n" % ( - self.inactivity, self.kill_timeout), - schema='test_var') + color_stdout( + "No output during {0.inactivity:.0f} seconds. " + "Will abort after {0.kill_timeout:.0f} seconds without output. " + "List of workers not reporting the status:\n".format(self), + schema='test_var') hung_tasks = [task for worker_id, task in self.worker_current_task.iteritems() if worker_id in worker_ids] for current_task in hung_tasks: - color_stdout("[{0:03d}] {1} {2}\n".format(current_task.worker_id, + color_stdout("- [{0:03d}, {1}, {2}]\n".format(current_task.worker_id, current_task.task_name, current_task.task_param), schema='test_var') @@ -215,7 +218,6 @@ def process_timeout(self, delta_seconds): lib.utils.print_tail_n(current_task.task_result_filepath, num_lines=15) - self.warned_seconds_ago = 0.0 if self.inactivity < self.kill_timeout: