1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

cmd tests improvement (#7181)

* cmd tests improvement

* fix sanity

* remove commented line

* fixed class init code
This commit is contained in:
Alexei Znamensky 2023-09-01 16:32:11 +12:00 committed by GitHub
parent 6303096648
commit d6ebba1aea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 8 deletions

View file

@ -6,7 +6,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
from collections import namedtuple
from itertools import chain, repeat
@ -19,16 +18,20 @@ RunCmdCall = namedtuple("RunCmdCall", ["command", "environ", "rc", "out", "err"]
class CmdRunnerTestHelper(object):
def __init__(self, command, test_cases):
self.command = command
def __init__(self, test_cases):
self._test_cases = test_cases
if isinstance(test_cases, (list, tuple)):
self.testcases = test_cases
else:
self.testcases = self._make_test_cases()
@property
def cmd_fixture(self):
@pytest.fixture
def patch_bin(mocker):
mocker.patch('ansible.module_utils.basic.AnsibleModule.get_bin_path', return_value=os.path.join('/testbin', self.command))
def mockie(self, path, *args, **kwargs):
return "/testbin/{0}".format(path)
mocker.patch('ansible.module_utils.basic.AnsibleModule.get_bin_path', mockie)
return patch_bin

View file

@ -16,7 +16,7 @@ from .cmd_runner_test_utils import CmdRunnerTestHelper
TESTED_MODULE = module.__name__
with open("tests/unit/plugins/modules/test_opkg.yaml", "r") as TEST_CASES:
helper = CmdRunnerTestHelper(command="opkg", test_cases=TEST_CASES)
helper = CmdRunnerTestHelper(test_cases=TEST_CASES)
patch_bin = helper.cmd_fixture

View file

@ -22,7 +22,7 @@ from .cmd_runner_test_utils import CmdRunnerTestHelper
TESTED_MODULE = module.__name__
with open("tests/unit/plugins/modules/test_xfconf.yaml", "r") as TEST_CASES:
helper = CmdRunnerTestHelper(command="xfconf-query", test_cases=TEST_CASES)
helper = CmdRunnerTestHelper(test_cases=TEST_CASES)
patch_bin = helper.cmd_fixture

View file

@ -15,7 +15,7 @@ from .cmd_runner_test_utils import CmdRunnerTestHelper
TESTED_MODULE = module.__name__
with open("tests/unit/plugins/modules/test_xfconf_info.yaml", "r") as TEST_CASES:
helper = CmdRunnerTestHelper(command="xfconf-query", test_cases=TEST_CASES)
helper = CmdRunnerTestHelper(test_cases=TEST_CASES)
patch_bin = helper.cmd_fixture