diff --git a/test/runner/lib/sanity/__init__.py b/test/runner/lib/sanity/__init__.py index 78af3694632..66be78a6eaf 100644 --- a/test/runner/lib/sanity/__init__.py +++ b/test/runner/lib/sanity/__init__.py @@ -577,6 +577,7 @@ class SanityCodeSmellTest(SanityTest): always = self.config.get('always') text = self.config.get('text') ignore_changes = self.config.get('ignore_changes') + ignore_self = self.config.get('ignore_self') if output == 'path-line-column-message': pattern = '^(?P[^:]*):(?P[0-9]+):(?P[0-9]+): (?P.*)$' @@ -609,6 +610,12 @@ class SanityCodeSmellTest(SanityTest): if files: paths = [p for p in paths if os.path.basename(p) in files] + if ignore_self and data_context().content.is_ansible: + relative_self_path = os.path.relpath(self.path, data_context().content.root) + + if relative_self_path in paths: + paths.remove(relative_self_path) + paths = settings.filter_skipped_paths(paths) if not paths and not always: diff --git a/test/sanity/code-smell/future-import-boilerplate.py b/test/sanity/code-smell/future-import-boilerplate.py index 52e42bb24da..373fd4d6f22 100755 --- a/test/sanity/code-smell/future-import-boilerplate.py +++ b/test/sanity/code-smell/future-import-boilerplate.py @@ -6,21 +6,7 @@ import sys def main(): - # We classify files in these directories as ones we don't care about fixing (at least for now) - prune = ( - 'contrib/inventory/', - 'contrib/vault/', - 'docs/', - 'examples/', - 'test/integration/', - 'test/legacy/', - 'test/units/', - ) - for path in sys.argv[1:] or sys.stdin.read().splitlines(): - if any(path.startswith(p) for p in prune): - continue - with open(path, 'rb') as path_fd: lines = path_fd.read().splitlines() diff --git a/test/sanity/code-smell/metaclass-boilerplate.py b/test/sanity/code-smell/metaclass-boilerplate.py index 6e146891529..cc211a36172 100755 --- a/test/sanity/code-smell/metaclass-boilerplate.py +++ b/test/sanity/code-smell/metaclass-boilerplate.py @@ -6,21 +6,7 @@ import sys def main(): - # These files pre-date the boilerplate test and should be fixed up as time goes on - prune = ( - 'contrib/inventory/', - 'contrib/vault/', - 'docs/', - 'examples/', - 'test/integration/', - 'test/legacy/', - 'test/units/', - ) - for path in sys.argv[1:] or sys.stdin.read().splitlines(): - if any(path.startswith(p) for p in prune): - continue - with open(path, 'rb') as path_fd: lines = path_fd.read().splitlines() diff --git a/test/sanity/code-smell/no-basestring.json b/test/sanity/code-smell/no-basestring.json index 776590b74d2..88858aeb613 100644 --- a/test/sanity/code-smell/no-basestring.json +++ b/test/sanity/code-smell/no-basestring.json @@ -2,5 +2,6 @@ "extensions": [ ".py" ], + "ignore_self": true, "output": "path-line-column-message" } diff --git a/test/sanity/code-smell/no-basestring.py b/test/sanity/code-smell/no-basestring.py index 25704bd1865..a35650efade 100755 --- a/test/sanity/code-smell/no-basestring.py +++ b/test/sanity/code-smell/no-basestring.py @@ -2,20 +2,12 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os import re import sys def main(): - skip = set([ - 'test/sanity/code-smell/%s' % os.path.basename(__file__), - ]) - for path in sys.argv[1:] or sys.stdin.read().splitlines(): - if path in skip: - continue - with open(path, 'r') as path_fd: for line, text in enumerate(path_fd.readlines()): match = re.search(r'(isinstance.*basestring)', text) diff --git a/test/sanity/code-smell/no-dict-iteritems.json b/test/sanity/code-smell/no-dict-iteritems.json index 776590b74d2..88858aeb613 100644 --- a/test/sanity/code-smell/no-dict-iteritems.json +++ b/test/sanity/code-smell/no-dict-iteritems.json @@ -2,5 +2,6 @@ "extensions": [ ".py" ], + "ignore_self": true, "output": "path-line-column-message" } diff --git a/test/sanity/code-smell/no-dict-iteritems.py b/test/sanity/code-smell/no-dict-iteritems.py index 6f9111d204e..e28b24f4a98 100755 --- a/test/sanity/code-smell/no-dict-iteritems.py +++ b/test/sanity/code-smell/no-dict-iteritems.py @@ -2,20 +2,12 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import os import re import sys def main(): - skip = set([ - 'test/sanity/code-smell/%s' % os.path.basename(__file__), - ]) - for path in sys.argv[1:] or sys.stdin.read().splitlines(): - if path in skip: - continue - with open(path, 'r') as path_fd: for line, text in enumerate(path_fd.readlines()): match = re.search(r'(?