diff --git a/lib/galaxy/util/pastescript/serve.py b/lib/galaxy/util/pastescript/serve.py index 7fb10f669ae..04fd9c3fe63 100644 --- a/lib/galaxy/util/pastescript/serve.py +++ b/lib/galaxy/util/pastescript/serve.py @@ -21,11 +21,15 @@ from __future__ import print_function import atexit import errno +import grp import logging import optparse import os +import pwd import re +import resource import signal +import socket import subprocess import sys import textwrap @@ -662,7 +666,6 @@ class ServeCommand(Command): except AttributeError as e: # Capturing bad error response from paste if str(e) == "'WSGIThreadPoolServer' object has no attribute 'thread_pool'": - import socket raise socket.error(98, 'Address already in use') else: raise AttributeError(e) @@ -699,7 +702,6 @@ class ServeCommand(Command): # @@: Should we set the umask and cwd now? - import resource # Resource usage information. maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1] if maxfd == resource.RLIM_INFINITY: maxfd = MAXFD @@ -746,7 +748,7 @@ class ServeCommand(Command): print("Could not delete: %s" % e) return 2 return 1 - for j in range(10): + for _i in range(10): if not live_pidfile(pid_file): break os.kill(pid, signal.SIGTERM) @@ -820,15 +822,12 @@ class ServeCommand(Command): def change_user_group(self, user, group): if not user and not group: return - import pwd - import grp uid = gid = None if group: try: gid = int(group) group = grp.getgrgid(gid).gr_name except ValueError: - import grp try: entry = grp.getgrnam(group) except KeyError: @@ -983,15 +982,13 @@ def ensure_port_cleanup(bound_addresses, maxtries=30, sleeptime=2): def _cleanup_ports(bound_addresses, maxtries=30, sleeptime=2): # Wait for the server to bind to the port. - import socket - import errno for bound_address in bound_addresses: - for attempt in range(maxtries): + for _i in range(maxtries): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(bound_address) except socket.error as e: - if e.args[0] != errno.ECONNREFUSED: + if e.errno != errno.ECONNREFUSED: raise break else: diff --git a/test/base/driver_util.py b/test/base/driver_util.py index ee8e319f32a..310a3be5b8d 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -310,13 +310,15 @@ def _tool_data_table_config_path(default_tool_data_table_config_path=None): return tool_data_table_config_path -def nose_config_and_run(argv=None, env=None, ignore_files=[], plugins=None): +def nose_config_and_run(argv=None, env=None, ignore_files=None, plugins=None): """Setup a nose context and run tests. Tests are specified by argv (defaulting to sys.argv). """ if env is None: env = os.environ + if ignore_files is None: + ignore_files = [] if plugins is None: plugins = nose.plugins.manager.DefaultPluginManager() if argv is None: @@ -472,7 +474,7 @@ def get_webapp_global_conf(): def wait_for_http_server(host, port, sleep_amount=0.1, sleep_tries=150): """Wait for an HTTP server to boot up.""" # Test if the server is up - for i in range(sleep_tries): + for _ in range(sleep_tries): # directly test the app, not the proxy conn = http_client.HTTPConnection(host, port) try: @@ -497,7 +499,7 @@ def attempt_ports(port): raise Exception("An existing process seems bound to specified test server port [%s]" % port) else: random.seed() - for i in range(0, 9): + for _ in range(0, 9): port = str(random.randint(8000, 10000)) yield port @@ -515,7 +517,7 @@ def serve_webapp(webapp, port=None, host=None): server = httpserver.serve(webapp, host=host, port=port, start_loop=False) break except socket.error as e: - if e[0] == 98: + if e.errno == 98: continue raise @@ -947,7 +949,7 @@ class GalaxyTestDriver(TestDriver): # one - other just read the properties above and use the default # implementation from this file. galaxy_config = getattr(config_object, "galaxy_config", None) - if hasattr(galaxy_config, '__call__'): + if callable(galaxy_config): galaxy_config = galaxy_config() if galaxy_config is None: setup_galaxy_config_kwds = dict( @@ -1038,7 +1040,9 @@ class GalaxyTestDriver(TestDriver): return test_classes return functional.test_toolbox - def run_tool_test(self, tool_id, index=0, resource_parameters={}): + def run_tool_test(self, tool_id, index=0, resource_parameters=None): + if resource_parameters is None: + resource_parameters = {} host, port, url = target_url_parts() galaxy_interactor_kwds = { "galaxy_url": url,