未验证 提交 d0fb1f15 编写于 作者: C Cleber Rosa

Merge remote-tracking branch 'cacarrara/enables-pylint-w0702'

Signed-off-by: NCleber Rosa <crosa@redhat.com>
...@@ -339,7 +339,7 @@ class TestLoaderProxy(object): ...@@ -339,7 +339,7 @@ class TestLoaderProxy(object):
sys.path.insert(0, test_module_dir) sys.path.insert(0, test_module_dir)
f, p, d = imp.find_module(module_name, [test_module_dir]) f, p, d = imp.find_module(module_name, [test_module_dir])
test_module = imp.load_module(module_name, f, p, d) test_module = imp.load_module(module_name, f, p, d)
except: except: # pylint: disable=W0702
# On load_module exception we fake the test class and pass # On load_module exception we fake the test class and pass
# the exc_info as parameter to be logged. # the exc_info as parameter to be logged.
test_parameters['methodName'] = 'test' test_parameters['methodName'] = 'test'
......
...@@ -827,7 +827,7 @@ class Test(unittest.TestCase, TestData): ...@@ -827,7 +827,7 @@ class Test(unittest.TestCase, TestData):
except exceptions.TestCancel as details: except exceptions.TestCancel as details:
stacktrace.log_exc_info(sys.exc_info(), logger=LOG_JOB) stacktrace.log_exc_info(sys.exc_info(), logger=LOG_JOB)
raise raise
except: # Old-style exceptions are not inherited from Exception() except: # Old-style exceptions are not inherited from Exception() pylint: disable=W0702
stacktrace.log_exc_info(sys.exc_info(), logger=LOG_JOB) stacktrace.log_exc_info(sys.exc_info(), logger=LOG_JOB)
details = sys.exc_info()[1] details = sys.exc_info()[1]
if not isinstance(details, Exception): # Avoid passing nasty exc if not isinstance(details, Exception): # Avoid passing nasty exc
...@@ -852,7 +852,7 @@ class Test(unittest.TestCase, TestData): ...@@ -852,7 +852,7 @@ class Test(unittest.TestCase, TestData):
except exceptions.TestCancel as details: except exceptions.TestCancel as details:
stacktrace.log_exc_info(sys.exc_info(), logger=LOG_JOB) stacktrace.log_exc_info(sys.exc_info(), logger=LOG_JOB)
raise raise
except: # avoid old-style exception failures except: # avoid old-style exception failures pylint: disable=W0702
stacktrace.log_exc_info(sys.exc_info(), logger=LOG_JOB) stacktrace.log_exc_info(sys.exc_info(), logger=LOG_JOB)
details = sys.exc_info()[1] details = sys.exc_info()[1]
cleanup_exception = exceptions.TestSetupFail(details) cleanup_exception = exceptions.TestSetupFail(details)
......
...@@ -43,5 +43,5 @@ class TestsTmpDir(JobPre, JobPost): ...@@ -43,5 +43,5 @@ class TestsTmpDir(JobPre, JobPost):
try: try:
shutil.rmtree(self._dirname) shutil.rmtree(self._dirname)
del os.environ[self._varname] del os.environ[self._varname]
except: except Exception:
pass pass
...@@ -157,7 +157,7 @@ class Asset(object): ...@@ -157,7 +157,7 @@ class Asset(object):
with FileLock(asset_file, 1): with FileLock(asset_file, 1):
if self._verify(asset_file): if self._verify(asset_file):
return asset_file return asset_file
except: except Exception:
exc_type, exc_value = sys.exc_info()[:2] exc_type, exc_value = sys.exc_info()[:2]
log.error('%s: %s', exc_type.__name__, exc_value) log.error('%s: %s', exc_type.__name__, exc_value)
...@@ -188,7 +188,7 @@ class Asset(object): ...@@ -188,7 +188,7 @@ class Asset(object):
try: try:
if fetch(urlobj, asset_file): if fetch(urlobj, asset_file):
return asset_file return asset_file
except: except Exception:
exc_type, exc_value = sys.exc_info()[:2] exc_type, exc_value = sys.exc_info()[:2]
log.error('%s: %s', exc_type.__name__, exc_value) log.error('%s: %s', exc_type.__name__, exc_value)
......
...@@ -56,7 +56,7 @@ class FileLock(object): ...@@ -56,7 +56,7 @@ class FileLock(object):
os.close(fd) os.close(fd)
self.locked = True self.locked = True
return self return self
except: except Exception:
try: try:
# Read the file to realize what's happening. # Read the file to realize what's happening.
with open(self.filename, 'r') as f: with open(self.filename, 'r') as f:
...@@ -90,7 +90,7 @@ class FileLock(object): ...@@ -90,7 +90,7 @@ class FileLock(object):
except: except:
raise LockFailed('Not able to lock.') raise LockFailed('Not able to lock.')
except: except Exception:
# If we cannot read the lock file, let's just # If we cannot read the lock file, let's just
# go on. Maybe in next iteration (if we have time) # go on. Maybe in next iteration (if we have time)
# we have a better luck. # we have a better luck.
...@@ -111,5 +111,5 @@ class FileLock(object): ...@@ -111,5 +111,5 @@ class FileLock(object):
try: try:
os.remove(self.filename) os.remove(self.filename)
self.locked = False self.locked = False
except: except Exception:
pass pass
...@@ -44,7 +44,7 @@ class Mail(JobPre, JobPost): ...@@ -44,7 +44,7 @@ class Mail(JobPre, JobPost):
smtp = smtplib.SMTP(self.server) smtp = smtplib.SMTP(self.server)
smtp.sendmail(self.sender, [self.rcpt], msg.as_string()) smtp.sendmail(self.sender, [self.rcpt], msg.as_string())
smtp.quit() smtp.quit()
except: except Exception:
LOG_UI.error("Failure to send email notification: " LOG_UI.error("Failure to send email notification: "
"please check your mail configuration") "please check your mail configuration")
......
...@@ -17,7 +17,7 @@ class Env(Test): ...@@ -17,7 +17,7 @@ class Env(Test):
def get_proc_content(rel_path): def get_proc_content(rel_path):
try: try:
return genio.read_file(os.path.join(p_dir, rel_path)).strip() return genio.read_file(os.path.join(p_dir, rel_path)).strip()
except: except OSError:
return "<NOT AVAILABLE>" return "<NOT AVAILABLE>"
self.log.debug('Process ID: %s', pid) self.log.debug('Process ID: %s', pid)
......
...@@ -17,9 +17,12 @@ ...@@ -17,9 +17,12 @@
import sys import sys
try: try:
import os import os
import time
import tempfile import tempfile
import traceback import traceback
except:
from avocado.core import data_dir
except ImportError:
sys.stderr.write("Unable to import basic python libraries, please " sys.stderr.write("Unable to import basic python libraries, please "
"reinstall avocado and dependencies.\n") "reinstall avocado and dependencies.\n")
# This exit code is replicated from avocado/core/exit_codes.py and not # This exit code is replicated from avocado/core/exit_codes.py and not
...@@ -27,6 +30,12 @@ except: ...@@ -27,6 +30,12 @@ except:
sys.exit(-1) sys.exit(-1)
def get_crash_dir():
crash_dir_path = os.path.join(data_dir.get_data_dir(), "crashes")
os.makedirs(crash_dir_path)
return crash_dir_path
def handle_exception(*exc_info): def handle_exception(*exc_info):
# Print traceback if AVOCADO_LOG_DEBUG environment variable is set # Print traceback if AVOCADO_LOG_DEBUG environment variable is set
msg = "Avocado crashed:\n" + "".join(traceback.format_exception(*exc_info)) msg = "Avocado crashed:\n" + "".join(traceback.format_exception(*exc_info))
...@@ -34,18 +43,9 @@ def handle_exception(*exc_info): ...@@ -34,18 +43,9 @@ def handle_exception(*exc_info):
if os.environ.get("AVOCADO_LOG_DEBUG"): if os.environ.get("AVOCADO_LOG_DEBUG"):
os.write(2, msg.encode('utf-8')) os.write(2, msg.encode('utf-8'))
# Store traceback in data_dir or TMPDIR # Store traceback in data_dir or TMPDIR
crash_dir = None
prefix = "avocado-traceback-" prefix = "avocado-traceback-"
try: prefix += time.strftime("%F_%T") + "-"
import time tmp, name = tempfile.mkstemp(".log", prefix, get_crash_dir())
prefix += time.strftime("%F_%T") + "-"
from avocado.core import data_dir # pylint: disable=E0611
_crash_dir = os.path.join(data_dir.get_data_dir(), "crashes")
os.makedirs(_crash_dir)
crash_dir = _crash_dir
except:
pass
tmp, name = tempfile.mkstemp(".log", prefix, crash_dir)
os.write(tmp, msg.encode('utf-8')) os.write(tmp, msg.encode('utf-8'))
os.close(tmp) os.close(tmp)
# Print friendly message in console-like output # Print friendly message in console-like output
......
...@@ -169,7 +169,8 @@ results_dir_content() { ...@@ -169,7 +169,8 @@ results_dir_content() {
[ "$SKIP_RESULTSDIR_CHECK" ] || RESULTS_DIR_CONTENT="$(ls $RESULTS_DIR 2> /dev/null)" [ "$SKIP_RESULTSDIR_CHECK" ] || RESULTS_DIR_CONTENT="$(ls $RESULTS_DIR 2> /dev/null)"
LINT_CMD="inspekt lint --exclude=.git" LINT_CMD="inspekt lint --exclude=.git"
PYLINT_ENABLE="--enable R0401,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0111,W0120,W0122,W0123,W0124,W0125,W0150,W0199,W0211,W0222,W0223,W0232,W0233,W0301,W0311,W0312,W0401,W0404,W0406,W0410,W0601,W0602,W0603,W0604,W0611,W0612,W0613,W0614,W0621,W0622,W0623,W0631,W0640,W0705,W0711,W1201,W1202,W1300,W1301,W1302,W1303,W1304,W1305,W1306,W1307,W1401,W1402,W1501,W1503,W1645" PYLINT_ENABLE="--enable R0401,W0101,W0102,W0104,W0105,W0106,W0107,W0108,W0109,W0111,W0120,W0122,W0123,W0124,W0125,W0150,W0199,W0211,W0222,W0223,W0232,W0233,W0301,W0311,W0312,W0401,W0404,W0406,W0410,W0601,W0602,W0603,W0604,W0611,W0612,W0613,W0614,W0621,W0622,W0623,W0631,W0640,W0702,W0705,W0711,W1201,W1202,W1300,W1301,W1302,W1303,W1304,W1305,W1306,W1307,W1401,W1402,W1501,W1503,W1645"
if [ "$AVOCADO_PARALLEL_LINT" ]; then if [ "$AVOCADO_PARALLEL_LINT" ]; then
LINT_CMD="$LINT_CMD --parallel=$AVOCADO_PARALLEL_LINT" LINT_CMD="$LINT_CMD --parallel=$AVOCADO_PARALLEL_LINT"
fi fi
......
...@@ -29,7 +29,7 @@ def has_no_external_connectivity(): ...@@ -29,7 +29,7 @@ def has_no_external_connectivity():
try: try:
urllib.urlopen('http://docs.python.org/objects.inv') urllib.urlopen('http://docs.python.org/objects.inv')
return False return False
except: except Exception:
return True return True
......
...@@ -186,7 +186,7 @@ class FileLockTest(unittest.TestCase): ...@@ -186,7 +186,7 @@ class FileLockTest(unittest.TestCase):
args = [(self.tmpdir, players, timeout)] * players args = [(self.tmpdir, players, timeout)] * players
try: try:
pool.map(file_lock_action, args) pool.map(file_lock_action, args)
except: except Exception:
msg = 'Failed to run FileLock with %s players:\n%s' msg = 'Failed to run FileLock with %s players:\n%s'
msg %= (players, prepare_exc_info(sys.exc_info())) msg %= (players, prepare_exc_info(sys.exc_info()))
self.fail(msg) self.fail(msg)
......
...@@ -59,7 +59,7 @@ class PhoneHome(unittest.TestCase): ...@@ -59,7 +59,7 @@ class PhoneHome(unittest.TestCase):
conn.request('POST', url) conn.request('POST', url)
try: try:
conn.getresponse() conn.getresponse()
except: except Exception:
pass pass
finally: finally:
conn.close() conn.close()
......
...@@ -7,7 +7,7 @@ from xml.dom import minidom ...@@ -7,7 +7,7 @@ from xml.dom import minidom
try: try:
from io import BytesIO from io import BytesIO
except: except ImportError:
from BytesIO import BytesIO from BytesIO import BytesIO
try: try:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册