mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-16 01:45:25 -07:00
Overhaul additional sanity tests. (#36803)
* Remove unnecessary sys.exit calls. * Add files filtering for code-smell tests. * Enhance test-constraints code-smell test. * Simplify compile sanity test. * Pass paths to importer on stdin. * Pass paths to yamllinter on stdin. * Add work-around for unicode path filtering. * Enhance configure-remoting-ps1 code-smell test. * Enhance integration-aliases code-smell test. * Enhance azure-requirements code-smell test. * Enhance no-illegal-filenames code-smell test.
This commit is contained in:
parent
5b5a79917d
commit
ac1698099d
23 changed files with 153 additions and 208 deletions
|
@ -6,6 +6,7 @@ import glob
|
|||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from lib.util import (
|
||||
ApplicationError,
|
||||
|
@ -233,6 +234,8 @@ class SanityCodeSmellTest(SanityTest):
|
|||
output = config.get('output')
|
||||
extensions = config.get('extensions')
|
||||
prefixes = config.get('prefixes')
|
||||
files = config.get('files')
|
||||
always = config.get('always')
|
||||
|
||||
if output == 'path-line-column-message':
|
||||
pattern = '^(?P<path>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+): (?P<message>.*)$'
|
||||
|
@ -243,18 +246,29 @@ class SanityCodeSmellTest(SanityTest):
|
|||
|
||||
paths = sorted(i.path for i in targets.include)
|
||||
|
||||
if always:
|
||||
paths = []
|
||||
|
||||
# short-term work-around for paths being str instead of unicode on python 2.x
|
||||
if sys.version_info[0] == 2:
|
||||
paths = [p.decode('utf-8') for p in paths]
|
||||
|
||||
if extensions:
|
||||
paths = [p for p in paths if os.path.splitext(p)[1] in extensions or (p.startswith('bin/') and '.py' in extensions)]
|
||||
|
||||
if prefixes:
|
||||
paths = [p for p in paths if any(p.startswith(pre) for pre in prefixes)]
|
||||
|
||||
if not paths:
|
||||
if files:
|
||||
paths = [p for p in paths if os.path.basename(p) in files]
|
||||
|
||||
if not paths and not always:
|
||||
return SanitySkipped(self.name)
|
||||
|
||||
data = '\n'.join(paths)
|
||||
|
||||
display.info(data, verbosity=4)
|
||||
if data:
|
||||
display.info(data, verbosity=4)
|
||||
try:
|
||||
stdout, stderr = run_command(args, cmd, data=data, env=env, capture=True)
|
||||
status = 0
|
||||
|
|
|
@ -15,6 +15,7 @@ from lib.sanity import (
|
|||
from lib.util import (
|
||||
SubprocessError,
|
||||
run_command,
|
||||
display,
|
||||
)
|
||||
|
||||
from lib.config import (
|
||||
|
@ -49,10 +50,14 @@ class CompileTest(SanityMultipleVersion):
|
|||
if not paths:
|
||||
return SanitySkipped(self.name, python_version=python_version)
|
||||
|
||||
cmd = ['python%s' % python_version, 'test/sanity/compile/compile.py'] + paths
|
||||
cmd = ['python%s' % python_version, 'test/sanity/compile/compile.py']
|
||||
|
||||
data = '\n'.join(paths)
|
||||
|
||||
display.info(data, verbosity=4)
|
||||
|
||||
try:
|
||||
stdout, stderr = run_command(args, cmd, capture=True)
|
||||
stdout, stderr = run_command(args, cmd, data=data, capture=True)
|
||||
status = 0
|
||||
except SubprocessError as ex:
|
||||
stdout = ex.stdout
|
||||
|
|
|
@ -17,6 +17,7 @@ from lib.util import (
|
|||
run_command,
|
||||
intercept_command,
|
||||
remove_tree,
|
||||
display,
|
||||
)
|
||||
|
||||
from lib.ansible_util import (
|
||||
|
@ -88,12 +89,17 @@ class ImportTest(SanityMultipleVersion):
|
|||
run_command(args, ['pip', 'uninstall', '--disable-pip-version-check', '-y', 'setuptools'], env=env)
|
||||
run_command(args, ['pip', 'uninstall', '--disable-pip-version-check', '-y', 'pip'], env=env)
|
||||
|
||||
cmd = ['importer.py'] + paths
|
||||
cmd = ['importer.py']
|
||||
|
||||
data = '\n'.join(paths)
|
||||
|
||||
display.info(data, verbosity=4)
|
||||
|
||||
results = []
|
||||
|
||||
try:
|
||||
stdout, stderr = intercept_command(args, cmd, target_name=self.name, env=env, capture=True, python_version=python_version, path=env['PATH'])
|
||||
stdout, stderr = intercept_command(args, cmd, data=data, target_name=self.name, env=env, capture=True, python_version=python_version,
|
||||
path=env['PATH'])
|
||||
|
||||
if stdout or stderr:
|
||||
raise SubprocessError(cmd, stdout=stdout, stderr=stderr)
|
||||
|
|
|
@ -15,6 +15,7 @@ from lib.sanity import (
|
|||
from lib.util import (
|
||||
SubprocessError,
|
||||
run_command,
|
||||
display,
|
||||
)
|
||||
|
||||
from lib.config import (
|
||||
|
@ -66,10 +67,14 @@ class YamllintTest(SanitySingleVersion):
|
|||
cmd = [
|
||||
'python%s' % args.python_version,
|
||||
'test/sanity/yamllint/yamllinter.py',
|
||||
] + paths
|
||||
]
|
||||
|
||||
data = '\n'.join(paths)
|
||||
|
||||
display.info(data, verbosity=4)
|
||||
|
||||
try:
|
||||
stdout, stderr = run_command(args, cmd, capture=True)
|
||||
stdout, stderr = run_command(args, cmd, data=data, capture=True)
|
||||
status = 0
|
||||
except SubprocessError as ex:
|
||||
stdout = ex.stdout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue