From 06d83bae056bbc9de904a238e480acf1147fe80e Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 5 Feb 2019 14:56:04 -0800 Subject: [PATCH] Support `ignore_changes` in code-smell tests. --- test/runner/lib/sanity/__init__.py | 7 ++++- .../sanity/code-smell/action-plugin-docs.json | 9 +++++- test/sanity/code-smell/action-plugin-docs.py | 31 +++++++++++-------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/test/runner/lib/sanity/__init__.py b/test/runner/lib/sanity/__init__.py index 724d1fcab5b..8710201a799 100644 --- a/test/runner/lib/sanity/__init__.py +++ b/test/runner/lib/sanity/__init__.py @@ -255,6 +255,7 @@ class SanityCodeSmellTest(SanityTest): files = self.config.get('files') always = self.config.get('always') text = self.config.get('text') + ignore_changes = self.config.get('ignore_changes') if output == 'path-line-column-message': pattern = '^(?P[^:]*):(?P[0-9]+):(?P[0-9]+): (?P.*)$' @@ -263,7 +264,11 @@ class SanityCodeSmellTest(SanityTest): else: pattern = ApplicationError('Unsupported output type: %s' % output) - paths = sorted(i.path for i in targets.include) + if ignore_changes: + paths = sorted(i.path for i in targets.targets) + always = False + else: + paths = sorted(i.path for i in targets.include) if always: paths = [] diff --git a/test/sanity/code-smell/action-plugin-docs.json b/test/sanity/code-smell/action-plugin-docs.json index 39ac4bd57f0..d029aaf7d67 100644 --- a/test/sanity/code-smell/action-plugin-docs.json +++ b/test/sanity/code-smell/action-plugin-docs.json @@ -1,4 +1,11 @@ { - "always": true, + "ignore_changes": true, + "prefixes": [ + "lib/ansible/modules/", + "lib/ansible/plugins/action/" + ], + "extensions": [ + ".py" + ], "output": "path-message" } diff --git a/test/sanity/code-smell/action-plugin-docs.py b/test/sanity/code-smell/action-plugin-docs.py index db0b853da8d..76de98ea4d7 100755 --- a/test/sanity/code-smell/action-plugin-docs.py +++ b/test/sanity/code-smell/action-plugin-docs.py @@ -2,6 +2,7 @@ """Test to verify action plugins have an associated module to provide documentation.""" import os +import sys def main(): @@ -40,31 +41,35 @@ def main(): 'vyos', ]) + paths = sys.argv[1:] or sys.stdin.read().splitlines() + module_names = set() - for root, dirs, files in os.walk('lib/ansible/modules'): - for filename in files: - name, ext = os.path.splitext(filename) + for path in paths: + if not path.startswith('lib/ansible/modules/'): + continue + + name = os.path.splitext(os.path.basename(path))[0] - if ext == '.py' and name != '__init__': - if name.startswith('_'): - name = name[1:] + if name != '__init__': + if name.startswith('_'): + name = name[1:] - module_names.add(name) + module_names.add(name) - action_plugin_dir = 'lib/ansible/plugins/action' unused_skip = set(skip) - for filename in os.listdir(action_plugin_dir): - name, ext = os.path.splitext(filename) + for path in paths: + if not path.startswith('lib/ansible/plugins/action/'): + continue - if ext == '.py' and name not in module_names: + name = os.path.splitext(os.path.basename(path))[0] + + if name not in module_names: if name in skip: unused_skip.remove(name) continue - path = os.path.join(action_plugin_dir, filename) - print('%s: action plugin has no matching module to provide documentation' % path) for filename in sorted(unused_skip):