From d910c971b43875bb3a698ec8794f2399715bca74 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 12 Jul 2019 21:58:19 -0700 Subject: [PATCH] Minor ansible-test code cleanup. (#59052) * Minor ansible-test code cleanup. * Fix type annotations. --- test/runner/injector/python.py | 2 ++ test/runner/lib/cloud/hcloud.py | 3 +++ test/runner/lib/sanity/__init__.py | 4 ++-- test/runner/lib/util.py | 4 +++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/test/runner/injector/python.py b/test/runner/injector/python.py index 264a05ea450..48198805110 100755 --- a/test/runner/injector/python.py +++ b/test/runner/injector/python.py @@ -26,9 +26,11 @@ def main(): # noinspection PyUnresolvedReferences found = bool(importlib.util.find_spec('coverage')) else: + # noinspection PyDeprecation import imp try: + # noinspection PyDeprecation imp.find_module('coverage') found = True except ImportError: diff --git a/test/runner/lib/cloud/hcloud.py b/test/runner/lib/cloud/hcloud.py index d523eb10658..29a437b7cee 100644 --- a/test/runner/lib/cloud/hcloud.py +++ b/test/runner/lib/cloud/hcloud.py @@ -94,6 +94,9 @@ class HcloudCloudEnvironment(CloudEnvironment): """ def get_environment_config(self): + """ + :rtype: CloudEnvironmentConfig + """ parser = ConfigParser() parser.read(self.config_path) diff --git a/test/runner/lib/sanity/__init__.py b/test/runner/lib/sanity/__init__.py index 4a5de4f0994..ff8b7b22bd8 100644 --- a/test/runner/lib/sanity/__init__.py +++ b/test/runner/lib/sanity/__init__.py @@ -142,7 +142,7 @@ def command_sanity(args): def collect_code_smell_tests(): """ - :rtype: tuple[SanityCodeSmellTest] + :rtype: tuple[SanityFunc] """ skip_file = 'test/sanity/code-smell/skip.txt' skip_tests = read_lines_without_comments(skip_file, remove_blank_lines=True, optional=True) @@ -383,7 +383,7 @@ SANITY_TESTS = ( def sanity_init(): """Initialize full sanity test list (includes code-smell scripts determined at runtime).""" import_plugins('sanity') - sanity_plugins = {} # type: t.Dict[str, type] + sanity_plugins = {} # type: t.Dict[str, t.Type[SanityFunc]] load_plugins(SanityFunc, sanity_plugins) sanity_tests = tuple([plugin() for plugin in sanity_plugins.values()]) global SANITY_TESTS # pylint: disable=locally-disabled, global-statement diff --git a/test/runner/lib/util.py b/test/runner/lib/util.py index 06858a4d4d5..d00182f2fc1 100644 --- a/test/runner/lib/util.py +++ b/test/runner/lib/util.py @@ -31,7 +31,7 @@ try: # noinspection PyCompatibility from configparser import ConfigParser except ImportError: - # noinspection PyCompatibility + # noinspection PyCompatibility,PyUnresolvedReferences from ConfigParser import SafeConfigParser as ConfigParser try: @@ -788,9 +788,11 @@ def load_module(path, name): # type: (str, str) -> None sys.modules[name] = module else: + # noinspection PyDeprecation import imp with open(path, 'r') as module_file: + # noinspection PyDeprecation imp.load_module(name, module_file, path, ('.py', 'r', imp.PY_SOURCE))