diff --git a/tests/unit/plugins/modules/cmd_runner_test_utils.py b/tests/unit/plugins/modules/cmd_runner_test_utils.py index 189cba730d..1d097b8c7f 100644 --- a/tests/unit/plugins/modules/cmd_runner_test_utils.py +++ b/tests/unit/plugins/modules/cmd_runner_test_utils.py @@ -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 - self.testcases = self._make_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 diff --git a/tests/unit/plugins/modules/test_opkg.py b/tests/unit/plugins/modules/test_opkg.py index a2b1fc9d74..9085a5d17f 100644 --- a/tests/unit/plugins/modules/test_opkg.py +++ b/tests/unit/plugins/modules/test_opkg.py @@ -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 diff --git a/tests/unit/plugins/modules/test_xfconf.py b/tests/unit/plugins/modules/test_xfconf.py index 0f00a3f610..be622462ef 100644 --- a/tests/unit/plugins/modules/test_xfconf.py +++ b/tests/unit/plugins/modules/test_xfconf.py @@ -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 diff --git a/tests/unit/plugins/modules/test_xfconf_info.py b/tests/unit/plugins/modules/test_xfconf_info.py index 2727d2476a..cb8b8f1da0 100644 --- a/tests/unit/plugins/modules/test_xfconf_info.py +++ b/tests/unit/plugins/modules/test_xfconf_info.py @@ -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