提交 2b2f6fca 编写于 作者: C Cleber Rosa

raise/except statements: mass style change

This commit changes the idiom on (hopefully all) except statements,
from:
   except foo, details:

to:
   except foo as details:

Which is compatible with both Python 2 and 3.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 133a5634
......@@ -48,7 +48,7 @@ def fail_on(exceptions=None):
return func(*args, **kwargs)
except TestBaseException:
raise
except exceptions, details:
except exceptions as details:
raise TestFail(str(details))
return wrap
if func:
......
......@@ -109,9 +109,9 @@ class ReportModel(object):
try:
with open(sysinfo_path, 'r') as sysinfo_file:
sysinfo_contents = sysinfo_file.read()
except OSError, details:
except OSError as details:
sysinfo_contents = "Error reading %s: %s" % (sysinfo_path, details)
except IOError, details:
except IOError as details:
sysinfo_contents = os.uname()[1]
return sysinfo_contents
......@@ -261,7 +261,7 @@ class HTMLTestResult(TestResult):
v = view.View(open(template, 'r').read(), context)
report_contents = v.render('utf8') # encodes into ascii
report_contents = codecs.decode("utf8") # decode to unicode
except UnicodeDecodeError, details:
except UnicodeDecodeError as details:
# FIXME: Removeme when UnicodeDecodeError problem is fixed
import logging
ui = logging.getLogger("avocado.app")
......
......@@ -245,7 +245,7 @@ class Job(object):
loader.loader.load_plugins(self.args)
try:
suite = loader.loader.discover(urls)
except loader.LoaderUnhandledUrlError, details:
except loader.LoaderUnhandledUrlError as details:
self._remove_job_results()
raise exceptions.OptionValidationError(details)
except KeyboardInterrupt:
......@@ -397,7 +397,7 @@ class Job(object):
self.replay_sourcejob)
try:
test_suite = self._make_test_suite(self.urls)
except loader.LoaderError, details:
except loader.LoaderError as details:
stacktrace.log_exc_info(sys.exc_info(), 'avocado.app.debug')
self._remove_job_results()
raise exceptions.OptionValidationError(details)
......@@ -413,7 +413,7 @@ class Job(object):
else:
try:
mux = multiplexer.Mux(self.args)
except (IOError, ValueError), details:
except (IOError, ValueError) as details:
raise exceptions.OptionValidationError(details)
self.args.test_result_total = mux.get_number_of_tests(test_suite)
......@@ -469,17 +469,17 @@ class Job(object):
runtime.CURRENT_JOB = self
try:
return self._run()
except exceptions.JobBaseException, details:
except exceptions.JobBaseException as details:
self.status = details.status
fail_class = details.__class__.__name__
self.view.notify(event='error', msg=('\nAvocado job failed: %s: %s'
% (fail_class, details)))
return exit_codes.AVOCADO_JOB_FAIL
except exceptions.OptionValidationError, details:
except exceptions.OptionValidationError as details:
self.view.notify(event='error', msg='\n' + str(details))
return exit_codes.AVOCADO_JOB_FAIL
except Exception, details:
except Exception as details:
self.status = "ERROR"
exc_type, exc_value, exc_traceback = sys.exc_info()
tb_info = traceback.format_exception(exc_type, exc_value,
......
......@@ -217,7 +217,7 @@ class TestLoaderProxy(object):
for loader_plugin in self._initialized_plugins:
try:
tests.extend(loader_plugin.discover(None, which_tests))
except Exception, details:
except Exception as details:
handle_exception(loader_plugin, details)
else:
for url in urls:
......@@ -230,7 +230,7 @@ class TestLoaderProxy(object):
handled = True
if not which_tests:
break # Don't process other plugins
except Exception, details:
except Exception as details:
handle_exception(loader_plugin, details)
if not handled:
unhandled_urls.append(url)
......@@ -264,7 +264,7 @@ class TestLoaderProxy(object):
sys.path.insert(0, test_module_dir)
f, p, d = imp.find_module(module_name, [test_module_dir])
test_module = imp.load_module(module_name, f, p, d)
except ImportError, details:
except ImportError as details:
raise ImportError("Unable to import test's module with "
"sys.path=%s\n\n%s" % (", ".join(sys.path),
details))
......@@ -666,7 +666,7 @@ class FileLoader(TestLoader):
# Since a lot of things can happen here, the broad exception is
# justified. The user will get it unadulterated anyway, and avocado
# will not crash.
except BaseException, details: # Ugly python files can raise any exc
except BaseException as details: # Ugly python files can raise any exc
if isinstance(details, KeyboardInterrupt):
raise # Don't ignore ctrl+c
if os.access(test_path, os.X_OK):
......
......@@ -222,7 +222,7 @@ class RemoteTestRunner(TestRunner):
raise exceptions.JobError('Remote machine does not seem to have '
'avocado installed')
self._copy_files()
except Exception, details:
except Exception as details:
stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test')
raise exceptions.JobError(details)
results = self.run_test(self.job.urls, timeout)
......@@ -252,7 +252,7 @@ class RemoteTestRunner(TestRunner):
self.result.end_tests()
try:
self.tear_down()
except Exception, details:
except Exception as details:
stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test')
raise exceptions.JobError(details)
finally:
......
......@@ -98,7 +98,7 @@ class Remote(object):
warn_only=True,
timeout=timeout)
break
except fabric.network.NetworkError, details:
except fabric.network.NetworkError as details:
fabric_exception = details
timeout = end_time - time.time()
if time.time() < end_time:
......
......@@ -27,7 +27,7 @@ def list_brief(app):
"""
try:
data = app.connection.get_api_list()
except connection.UnexpectedHttpStatusCode, e:
except connection.UnexpectedHttpStatusCode as e:
if e.received == 403:
app.view.notify(event="error",
msg="Error: Access Forbidden")
......
......@@ -64,7 +64,7 @@ class TestStatus(object):
return self.queue.get()
# Let's catch all exceptions, since errors here mean a
# crash in avocado.
except Exception, details:
except Exception as details:
e_msg = ("\nError receiving message from test: %s -> %s" %
(details.__class__, details))
self.job.view.notify(event="error",
......
......@@ -241,7 +241,7 @@ class Settings(object):
try:
return convert_value_type(val, key_type)
except Exception, details:
except Exception as details:
raise SettingsValueError("Could not convert value %r to type %s "
"(settings key %s, section %s): %s" %
(val, key_type, key, section, details))
......
......@@ -287,11 +287,11 @@ class LogWatcher(Collectible):
finally:
out_messages.close()
in_messages.close()
except ValueError, e:
except ValueError as e:
log.info(e)
except (IOError, OSError):
log.debug("Not logging %s (lack of permissions)", self.path)
except Exception, e:
except Exception as e:
log.error("Log file %s collection failed: %s", self.path, e)
......@@ -420,7 +420,7 @@ class SysInfo(object):
# we have to probe and find out the correct path.
try:
self.end_test_collectibles.add(self._get_syslog_watcher())
except ValueError, details:
except ValueError as details:
log.info(details)
def _get_collectibles(self, hook):
......
......@@ -383,7 +383,7 @@ class Test(unittest.TestCase):
stderr_check_exception = None
try:
self.setUp()
except exceptions.TestSkipError, details:
except exceptions.TestSkipError as details:
stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test')
raise exceptions.TestSkipError(details)
except: # Old-style exceptions are not inherited from Exception()
......@@ -392,7 +392,7 @@ class Test(unittest.TestCase):
raise exceptions.TestSetupFail(details)
try:
testMethod()
except exceptions.TestSkipError, details:
except exceptions.TestSkipError as details:
stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test')
skip_illegal_msg = ('Calling skip() in places other than '
'setUp() is not allowed in avocado, you '
......@@ -408,7 +408,7 @@ class Test(unittest.TestCase):
finally:
try:
self.tearDown()
except exceptions.TestSkipError, details:
except exceptions.TestSkipError as details:
stacktrace.log_exc_info(sys.exc_info(), logger='avocado.test')
skip_illegal_msg = ('Calling skip() in places other than '
'setUp() is not allowed in avocado, '
......@@ -437,13 +437,13 @@ class Test(unittest.TestCase):
if not disable_output_check:
try:
self._check_reference_stdout()
except Exception, details:
except Exception as details:
stacktrace.log_exc_info(sys.exc_info(),
logger='avocado.test')
stdout_check_exception = details
try:
self._check_reference_stderr()
except Exception, details:
except Exception as details:
stacktrace.log_exc_info(sys.exc_info(),
logger='avocado.test')
stderr_check_exception = details
......@@ -493,17 +493,17 @@ class Test(unittest.TestCase):
try:
self._tag_start()
self._run_avocado()
except exceptions.TestBaseException, detail:
except exceptions.TestBaseException as detail:
self.status = detail.status
self.fail_class = detail.__class__.__name__
self.fail_reason = detail
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
except AssertionError, detail:
except AssertionError as detail:
self.status = 'FAIL'
self.fail_class = detail.__class__.__name__
self.fail_reason = detail
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
except Exception, detail:
except Exception as detail:
self.status = 'ERROR'
tb_info = stacktrace.tb_info(sys.exc_info())
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
......@@ -623,7 +623,7 @@ class SimpleTest(Test):
env=test_params)
self._log_detailed_cmd_info(result)
except process.CmdError, details:
except process.CmdError as details:
self._log_detailed_cmd_info(details.result)
raise exceptions.TestFail(details)
......
......@@ -34,7 +34,7 @@ class TestLister(object):
self.term_support = output.TermSupport()
try:
loader.loader.load_plugins(args)
except loader.LoaderError, details:
except loader.LoaderError as details:
sys.stderr.write(str(details))
sys.stderr.write('\n')
sys.exit(exit_codes.AVOCADO_FAIL)
......@@ -48,7 +48,7 @@ class TestLister(object):
try:
return loader.loader.discover(paths,
which_tests=which_tests)
except loader.LoaderUnhandledUrlError, details:
except loader.LoaderUnhandledUrlError as details:
self.view.notify(event="error", msg=str(details))
self.view.cleanup()
sys.exit(exit_codes.AVOCADO_FAIL)
......
......@@ -96,7 +96,7 @@ class Multiplex(CLICmd):
mux_tree = multiplexer.yaml2tree(args.multiplex_files,
args.filter_only, args.filter_out,
args.debug)
except IOError, details:
except IOError as details:
view.notify(event='error',
msg=details.strerror)
sys.exit(exit_codes.AVOCADO_JOB_FAIL)
......
......@@ -79,7 +79,7 @@ def make_dir_and_populate(basedir='/tmp'):
for _ in xrange(n_lines):
os.write(fd, generate_random_string(str_length))
os.close(fd)
except OSError, details:
except OSError as details:
log.error("Failed to generate dir in '%s' and populate: %s" %
(basedir, details))
return None
......
......@@ -345,7 +345,7 @@ class GDB(object):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True)
except OSError, details:
except OSError as details:
if details.errno == 2:
exc = OSError("File '%s' not found" % args[0])
exc.errno = 2
......@@ -663,7 +663,7 @@ class GDBServer(object):
stdout=self.stdout,
stderr=self.stderr,
close_fds=True)
except OSError, details:
except OSError as details:
if details.errno == 2:
exc = OSError("File '%s' not found" % args[0])
exc.errno = 2
......
......@@ -309,7 +309,7 @@ class SubProcess(object):
if sudo and os.getuid() != 0:
try:
sudo_cmd = '%s -n' % path.find_command('sudo')
except path.CmdNotFoundError, details:
except path.CmdNotFoundError as details:
log.error(details)
log.error('Parameter sudo=True provided, but sudo was '
'not found. Please consider adding sudo to '
......@@ -335,7 +335,7 @@ class SubProcess(object):
stderr=subprocess.PIPE,
shell=self.shell,
env=self.env)
except OSError, details:
except OSError as details:
if details.errno == 2:
exc = OSError("File '%s' not found" % self.cmd.split()[0])
exc.errno = 2
......
......@@ -442,7 +442,7 @@ class YumBackend(RpmBackend):
% (tmp_file.name, self.repo_file_path),
sudo=True)
return True
except (OSError, process.CmdError), details:
except (OSError, process.CmdError) as details:
log.error(details)
return False
......@@ -465,7 +465,7 @@ class YumBackend(RpmBackend):
% (tmp_file.name, self.repo_file_path),
sudo=True)
return True
except (OSError, process.CmdError), details:
except (OSError, process.CmdError) as details:
log.error(details)
return False
......@@ -501,7 +501,7 @@ class YumBackend(RpmBackend):
return None
try:
d_provides = self.yum_base.searchPackageProvides(args=[name])
except Exception, exc:
except Exception as exc:
log.error("Error searching for package that "
"provides %s: %s", name, exc)
d_provides = []
......@@ -767,7 +767,7 @@ class AptBackend(DpkgBackend):
process.system('cp %s %s'
% (tmp_file.name, self.repo_file_path),
sudo=True)
except (OSError, process.CmdError), details:
except (OSError, process.CmdError) as details:
log.error(details)
return False
......
......@@ -687,7 +687,7 @@ class PluginsXunitTest(AbsPluginsTest, unittest.TestCase):
(e_rc, result))
try:
xunit_doc = xml.dom.minidom.parseString(xml_output)
except Exception, detail:
except Exception as detail:
raise ParseXMLError("Failed to parse content: %s\n%s" %
(detail, xml_output))
......@@ -762,7 +762,7 @@ class PluginsJSONTest(AbsPluginsTest, unittest.TestCase):
(e_rc, result))
try:
json_data = json.loads(json_output)
except Exception, detail:
except Exception as detail:
raise ParseJSONError("Failed to parse content: %s\n%s" %
(detail, json_output))
self.assertTrue(json_data, "Empty JSON result:\n%s" % json_output)
......
......@@ -66,7 +66,7 @@ class JobTimeOutTest(unittest.TestCase):
(e_rc, result))
try:
xunit_doc = xml.dom.minidom.parseString(xml_output)
except Exception, detail:
except Exception as detail:
raise ParseXMLError("Failed to parse content: %s\n%s" %
(detail, xml_output))
......
......@@ -68,7 +68,7 @@ class xUnitSucceedTest(unittest.TestCase):
xml = fp.read()
try:
dom = minidom.parseString(xml)
except Exception, details:
except Exception as details:
raise ParseXMLError("Error parsing XML: '%s'.\nXML Contents:\n%s" % (details, xml))
self.assertTrue(dom)
els = dom.getElementsByTagName('testcase')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册