Code cleanup in ansible-test.

pull/69558/head
Matt Clay 6 years ago
parent ed4fd9be67
commit c495c92a6e

@ -0,0 +1,3 @@
bugfixes:
- ansible-test - Use ``sys.exit`` instead of ``exit``.
- ansible-test - Code cleanup.

@ -37,7 +37,8 @@ def main():
found = False found = False
if not found: if not found:
exit('ERROR: Could not find `coverage` module. Did you use a virtualenv created without --system-site-packages or with the wrong interpreter?') sys.exit('ERROR: Could not find `coverage` module. '
'Did you use a virtualenv created without --system-site-packages or with the wrong interpreter?')
if name == 'python.py': if name == 'python.py':
if sys.argv[1] == '-c': if sys.argv[1] == '-c':

@ -191,7 +191,7 @@ def main():
test_python_module(path, name, base_dir, messages) test_python_module(path, name, base_dir, messages)
if messages: if messages:
exit(10) sys.exit(10)
def test_python_module(path, name, base_dir, messages): def test_python_module(path, name, base_dir, messages):
"""Test the given python module by importing it. """Test the given python module by importing it.

@ -25,7 +25,7 @@ class BlacklistEntry:
""" """
self.alternative = alternative self.alternative = alternative
self.modules_only = modules_only self.modules_only = modules_only
self.names = set(names) if names else None self.names = set(names) if names else set()
self.ignore_paths = ignore_paths self.ignore_paths = ignore_paths
def applies_to(self, path, name=None): def applies_to(self, path, name=None):

@ -183,15 +183,15 @@ def main():
display.review_warnings() display.review_warnings()
except ApplicationWarning as ex: except ApplicationWarning as ex:
display.warning(u'%s' % ex) display.warning(u'%s' % ex)
exit(0) sys.exit(0)
except ApplicationError as ex: except ApplicationError as ex:
display.error(u'%s' % ex) display.error(u'%s' % ex)
exit(1) sys.exit(1)
except KeyboardInterrupt: except KeyboardInterrupt:
exit(2) sys.exit(2)
except IOError as ex: except IOError as ex:
if ex.errno == errno.EPIPE: if ex.errno == errno.EPIPE:
exit(3) sys.exit(3)
raise raise
@ -675,7 +675,7 @@ def key_value(argparse, value): # type: (argparse_module, str) -> t.Tuple[str,
if len(parts) != 2: if len(parts) != 2:
raise argparse.ArgumentTypeError('"%s" must be in the format "key=value"' % value) raise argparse.ArgumentTypeError('"%s" must be in the format "key=value"' % value)
return tuple(parts) return parts[0], parts[1]
# noinspection PyProtectedMember # noinspection PyProtectedMember

@ -14,6 +14,7 @@ from ..util import (
find_executable, find_executable,
display, display,
ConfigParser, ConfigParser,
ApplicationError,
) )
from ..docker_util import ( from ..docker_util import (
@ -85,8 +86,7 @@ class VcenterProvider(CloudProvider):
self._use_static_config() self._use_static_config()
self._setup_static() self._setup_static()
else: else:
display.error('Unknown vmware_test_platform: %s' % self.vmware_test_platform) raise ApplicationError('Unknown vmware_test_platform: %s' % self.vmware_test_platform)
exit(1)
def get_docker_run_options(self): def get_docker_run_options(self):
"""Get any additional options needed when delegating tests to a docker container. """Get any additional options needed when delegating tests to a docker container.
@ -161,8 +161,8 @@ class VcenterProvider(CloudProvider):
def _setup_static(self): def _setup_static(self):
if not os.path.exists(self.config_static_path): if not os.path.exists(self.config_static_path):
display.error('Configuration file does not exist: %s' % self.config_static_path) raise ApplicationError('Configuration file does not exist: %s' % self.config_static_path)
exit(1)
parser = ConfigParser({ parser = ConfigParser({
'vcenter_port': '443', 'vcenter_port': '443',
'vmware_proxy_host': '', 'vmware_proxy_host': '',

@ -665,7 +665,7 @@ class SanityTest(ABC):
"""A tuple of supported Python versions or None if the test does not depend on specific Python versions.""" """A tuple of supported Python versions or None if the test does not depend on specific Python versions."""
return tuple(python_version for python_version in SUPPORTED_PYTHON_VERSIONS if python_version.startswith('3.')) return tuple(python_version for python_version in SUPPORTED_PYTHON_VERSIONS if python_version.startswith('3.'))
def filter_targets(self, targets): # type: (t.List[TestTarget]) -> t.List[TestTarget] def filter_targets(self, targets): # type: (t.List[TestTarget]) -> t.List[TestTarget] # pylint: disable=unused-argument
"""Return the given list of test targets, filtered to include only those relevant for the test.""" """Return the given list of test targets, filtered to include only those relevant for the test."""
if self.no_targets: if self.no_targets:
return [] return []

Loading…
Cancel
Save