More code-smell sanity test updates. (#36830)
* Add test for missing Azure requirements. * Improve readability. * Enhance no-unicode-literals code-smell test.
This commit is contained in:
parent
a031e02ab0
commit
dc71c2197f
5 changed files with 42 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
6
test/sanity/code-smell/no-unicode-literals.json
Normal file
6
test/sanity/code-smell/no-unicode-literals.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"extensions": [
|
||||
".py"
|
||||
],
|
||||
"output": "path-line-column-message"
|
||||
}
|
27
test/sanity/code-smell/no-unicode-literals.py
Executable file
27
test/sanity/code-smell/no-unicode-literals.py
Executable file
|
@ -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()
|
|
@ -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
|
Loading…
Reference in a new issue