Intercept code-smell tests using subprocess.

Some code-smell sanity tests for ansible-base use subprocess to invoke ansible commands.
Intercept these commands to make sure the correct script and python version are used.
This commit is contained in:
Matt Clay 2020-06-10 14:40:17 -07:00
parent d30fc6c0b3
commit 6c2be04b6f
4 changed files with 11 additions and 1 deletions

View file

@ -34,6 +34,7 @@ from ..util import (
from ..util_common import ( from ..util_common import (
run_command, run_command,
intercept_command,
handle_layout_messages, handle_layout_messages,
) )
@ -690,6 +691,7 @@ class SanityCodeSmellTest(SanityTest):
self.files = self.config.get('files') # type: t.List[str] self.files = self.config.get('files') # type: t.List[str]
self.text = self.config.get('text') # type: t.Optional[bool] self.text = self.config.get('text') # type: t.Optional[bool]
self.ignore_self = self.config.get('ignore_self') # type: bool self.ignore_self = self.config.get('ignore_self') # type: bool
self.intercept = self.config.get('intercept') # type: bool
self.__all_targets = self.config.get('all_targets') # type: bool self.__all_targets = self.config.get('all_targets') # type: bool
self.__no_targets = self.config.get('no_targets') # type: bool self.__no_targets = self.config.get('no_targets') # type: bool
@ -702,6 +704,7 @@ class SanityCodeSmellTest(SanityTest):
self.files = [] self.files = []
self.text = None # type: t.Optional[bool] self.text = None # type: t.Optional[bool]
self.ignore_self = False self.ignore_self = False
self.intercept = False
self.__all_targets = False self.__all_targets = False
self.__no_targets = True self.__no_targets = True
@ -805,7 +808,11 @@ class SanityCodeSmellTest(SanityTest):
display.info(data, verbosity=4) display.info(data, verbosity=4)
try: try:
if self.intercept:
stdout, stderr = intercept_command(args, cmd, target_name='sanity.%s' % self.name, data=data, env=env, capture=True, disable_coverage=True)
else:
stdout, stderr = run_command(args, cmd, data=data, env=env, capture=True) stdout, stderr = run_command(args, cmd, data=data, env=env, capture=True)
status = 0 status = 0
except SubprocessError as ex: except SubprocessError as ex:
stdout = ex.stdout stdout = ex.stdout

View file

@ -1,4 +1,5 @@
{ {
"intercept": true,
"prefixes": [ "prefixes": [
"changelogs/fragments/" "changelogs/fragments/"
], ],

View file

@ -1,4 +1,5 @@
{ {
"intercept": true,
"disabled": true, "disabled": true,
"no_targets": true, "no_targets": true,
"output": "path-line-column-message" "output": "path-line-column-message"

View file

@ -1,4 +1,5 @@
{ {
"intercept": true,
"disabled": true, "disabled": true,
"all_targets": true, "all_targets": true,
"output": "path-message" "output": "path-message"