From dc71c2197f62203e519abf0c517ca57877199e99 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 28 Feb 2018 00:50:00 -0800 Subject: [PATCH] More code-smell sanity test updates. (#36830) * Add test for missing Azure requirements. * Improve readability. * Enhance no-unicode-literals code-smell test. --- test/runner/lib/sanity/__init__.py | 1 + test/sanity/code-smell/azure-requirements.py | 8 ++++++ .../code-smell/no-unicode-literals.json | 6 +++++ test/sanity/code-smell/no-unicode-literals.py | 27 +++++++++++++++++++ test/sanity/code-smell/no-unicode-literals.sh | 17 ------------ 5 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 test/sanity/code-smell/no-unicode-literals.json create mode 100755 test/sanity/code-smell/no-unicode-literals.py delete mode 100755 test/sanity/code-smell/no-unicode-literals.sh diff --git a/test/runner/lib/sanity/__init__.py b/test/runner/lib/sanity/__init__.py index e9fe96d536..a773e917fb 100644 --- a/test/runner/lib/sanity/__init__.py +++ b/test/runner/lib/sanity/__init__.py @@ -269,6 +269,7 @@ class SanityCodeSmellTest(SanityTest): if data: display.info(data, verbosity=4) + try: stdout, stderr = run_command(args, cmd, data=data, env=env, capture=True) status = 0 diff --git a/test/sanity/code-smell/azure-requirements.py b/test/sanity/code-smell/azure-requirements.py index 95ab47d0f4..dc3554c698 100755 --- a/test/sanity/code-smell/azure-requirements.py +++ b/test/sanity/code-smell/azure-requirements.py @@ -9,6 +9,14 @@ def main(): src = 'packaging/requirements/requirements-azure.txt' dst = 'test/runner/requirements/integration.cloud.azure.txt' + missing = [p for p in [src, dst] if not os.path.isfile(p)] + + if missing: + for path in missing: + print('%s: missing required file' % path) + + return + if not filecmp.cmp(src, dst): print('%s: must be identical to `%s`' % (dst, src)) diff --git a/test/sanity/code-smell/no-unicode-literals.json b/test/sanity/code-smell/no-unicode-literals.json new file mode 100644 index 0000000000..776590b74d --- /dev/null +++ b/test/sanity/code-smell/no-unicode-literals.json @@ -0,0 +1,6 @@ +{ + "extensions": [ + ".py" + ], + "output": "path-line-column-message" +} diff --git a/test/sanity/code-smell/no-unicode-literals.py b/test/sanity/code-smell/no-unicode-literals.py new file mode 100755 index 0000000000..f12b18efbf --- /dev/null +++ b/test/sanity/code-smell/no-unicode-literals.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +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'(unicode_literals)', text) + + if match: + print('%s:%d:%d: do not use `unicode_literals`' % ( + path, line + 1, match.start(1) + 1)) + + +if __name__ == '__main__': + main() diff --git a/test/sanity/code-smell/no-unicode-literals.sh b/test/sanity/code-smell/no-unicode-literals.sh deleted file mode 100755 index e659242b18..0000000000 --- a/test/sanity/code-smell/no-unicode-literals.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -UNICODE_LITERALS_USERS=$(grep -r unicode_literals . \ - --exclude-dir .git \ - --exclude-dir .tox \ - --exclude no-unicode-literals.sh \ - --exclude no-unicode-literals.rst | - grep -v ./test/results | \ - grep -v ansible.egg-info/SOURCES.txt \ - ) - -if [ "${UNICODE_LITERALS_USERS}" ]; then - echo "${UNICODE_LITERALS_USERS}" - exit 1 -fi - -exit 0