diff --git a/tests/unit/plugins/modules/cmd_runner_test_utils.py b/tests/unit/plugins/modules/helper.py similarity index 92% rename from tests/unit/plugins/modules/cmd_runner_test_utils.py rename to tests/unit/plugins/modules/helper.py index 62e3cb73cf..10e43242d5 100644 --- a/tests/unit/plugins/modules/cmd_runner_test_utils.py +++ b/tests/unit/plugins/modules/helper.py @@ -19,6 +19,17 @@ RunCmdCall = namedtuple("RunCmdCall", ["command", "environ", "rc", "out", "err"] class CmdRunnerTestHelper(object): + @staticmethod + def from_list(module_main, list_): + helper = CmdRunnerTestHelper(module_main, test_cases=list_) + return helper + + @staticmethod + def from_file(module_main, filename): + with open(filename, "r") as TEST_CASES: + helper = CmdRunnerTestHelper(module_main, test_cases=TEST_CASES) + return helper + def __init__(self, module_main, test_cases): self.module_main = module_main self._test_cases = test_cases diff --git a/tests/unit/plugins/modules/test_cpanm.py b/tests/unit/plugins/modules/test_cpanm.py index 8f2a592181..d508638f7f 100644 --- a/tests/unit/plugins/modules/test_cpanm.py +++ b/tests/unit/plugins/modules/test_cpanm.py @@ -16,12 +16,11 @@ __metaclass__ = type import pytest from ansible_collections.community.general.plugins.modules import cpanm -from .cmd_runner_test_utils import CmdRunnerTestHelper +from .helper import CmdRunnerTestHelper -with open("tests/unit/plugins/modules/test_cpanm.yaml", "r") as TEST_CASES: - helper = CmdRunnerTestHelper(cpanm.main, test_cases=TEST_CASES) - patch_bin = helper.cmd_fixture +helper = CmdRunnerTestHelper.from_file(cpanm.main, "tests/unit/plugins/modules/test_cpanm.yaml") +patch_bin = helper.cmd_fixture @pytest.mark.parametrize('patch_ansible_module, testcase', diff --git a/tests/unit/plugins/modules/test_gconftool2.py b/tests/unit/plugins/modules/test_gconftool2.py index b63709a94e..a1a4c6df51 100644 --- a/tests/unit/plugins/modules/test_gconftool2.py +++ b/tests/unit/plugins/modules/test_gconftool2.py @@ -9,13 +9,12 @@ __metaclass__ = type import pytest -from ansible_collections.community.general.plugins.modules import gconftool2 as module -from .cmd_runner_test_utils import CmdRunnerTestHelper +from ansible_collections.community.general.plugins.modules import gconftool2 +from .helper import CmdRunnerTestHelper -with open("tests/unit/plugins/modules/test_gconftool2.yaml", "r") as TEST_CASES: - helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES) - patch_bin = helper.cmd_fixture +helper = CmdRunnerTestHelper.from_file(gconftool2.main, "tests/unit/plugins/modules/test_gconftool2.yaml") +patch_bin = helper.cmd_fixture @pytest.mark.parametrize('patch_ansible_module, testcase', diff --git a/tests/unit/plugins/modules/test_gconftool2_info.py b/tests/unit/plugins/modules/test_gconftool2_info.py index e7b99f22a0..986e2632d6 100644 --- a/tests/unit/plugins/modules/test_gconftool2_info.py +++ b/tests/unit/plugins/modules/test_gconftool2_info.py @@ -10,12 +10,11 @@ __metaclass__ = type import pytest from ansible_collections.community.general.plugins.modules import gconftool2_info -from .cmd_runner_test_utils import CmdRunnerTestHelper +from .helper import CmdRunnerTestHelper -with open("tests/unit/plugins/modules/test_gconftool2_info.yaml", "r") as TEST_CASES: - helper = CmdRunnerTestHelper(gconftool2_info.main, test_cases=TEST_CASES) - patch_bin = helper.cmd_fixture +helper = CmdRunnerTestHelper.from_file(gconftool2_info.main, "tests/unit/plugins/modules/test_gconftool2_info.yaml") +patch_bin = helper.cmd_fixture @pytest.mark.parametrize('patch_ansible_module, testcase', diff --git a/tests/unit/plugins/modules/test_opkg.py b/tests/unit/plugins/modules/test_opkg.py index 9683de0254..62a4a2157a 100644 --- a/tests/unit/plugins/modules/test_opkg.py +++ b/tests/unit/plugins/modules/test_opkg.py @@ -9,13 +9,12 @@ __metaclass__ = type import pytest -from ansible_collections.community.general.plugins.modules import opkg as module -from .cmd_runner_test_utils import CmdRunnerTestHelper +from ansible_collections.community.general.plugins.modules import opkg +from .helper import CmdRunnerTestHelper -with open("tests/unit/plugins/modules/test_opkg.yaml", "r") as TEST_CASES: - helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES) - patch_bin = helper.cmd_fixture +helper = CmdRunnerTestHelper.from_file(opkg.main, "tests/unit/plugins/modules/test_opkg.yaml") +patch_bin = helper.cmd_fixture @pytest.mark.parametrize('patch_ansible_module, testcase', diff --git a/tests/unit/plugins/modules/test_puppet.py b/tests/unit/plugins/modules/test_puppet.py index 6a12516317..858c2c4365 100644 --- a/tests/unit/plugins/modules/test_puppet.py +++ b/tests/unit/plugins/modules/test_puppet.py @@ -15,13 +15,12 @@ __metaclass__ = type import pytest -from ansible_collections.community.general.plugins.modules import puppet as module -from .cmd_runner_test_utils import CmdRunnerTestHelper +from ansible_collections.community.general.plugins.modules import puppet +from .helper import CmdRunnerTestHelper -with open("tests/unit/plugins/modules/test_puppet.yaml", "r") as TEST_CASES: - helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES) - patch_bin = helper.cmd_fixture +helper = CmdRunnerTestHelper.from_file(puppet.main, "tests/unit/plugins/modules/test_puppet.yaml") +patch_bin = helper.cmd_fixture @pytest.mark.parametrize('patch_ansible_module, testcase', diff --git a/tests/unit/plugins/modules/test_snap.py b/tests/unit/plugins/modules/test_snap.py index 1286715c54..41e339c3b8 100644 --- a/tests/unit/plugins/modules/test_snap.py +++ b/tests/unit/plugins/modules/test_snap.py @@ -8,8 +8,8 @@ __metaclass__ = type import pytest -from .cmd_runner_test_utils import CmdRunnerTestHelper, ModuleTestCase, RunCmdCall -from ansible_collections.community.general.plugins.modules import snap as module +from .helper import CmdRunnerTestHelper, ModuleTestCase, RunCmdCall +from ansible_collections.community.general.plugins.modules import snap issue_6803_status_out = """Name Version Rev Tracking Publisher Notes @@ -444,8 +444,7 @@ TEST_CASES = [ ), ] - -helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES) +helper = CmdRunnerTestHelper.from_list(snap.main, 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 9d8785c580..001d2279dc 100644 --- a/tests/unit/plugins/modules/test_xfconf.py +++ b/tests/unit/plugins/modules/test_xfconf.py @@ -15,13 +15,12 @@ __metaclass__ = type import pytest -from ansible_collections.community.general.plugins.modules import xfconf as module -from .cmd_runner_test_utils import CmdRunnerTestHelper +from ansible_collections.community.general.plugins.modules import xfconf +from .helper import CmdRunnerTestHelper -with open("tests/unit/plugins/modules/test_xfconf.yaml", "r") as TEST_CASES: - helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES) - patch_bin = helper.cmd_fixture +helper = CmdRunnerTestHelper.from_file(xfconf.main, "tests/unit/plugins/modules/test_xfconf.yaml") +patch_bin = helper.cmd_fixture @pytest.mark.parametrize('patch_ansible_module, testcase', diff --git a/tests/unit/plugins/modules/test_xfconf_info.py b/tests/unit/plugins/modules/test_xfconf_info.py index 77bbfebe20..e24b6022ce 100644 --- a/tests/unit/plugins/modules/test_xfconf_info.py +++ b/tests/unit/plugins/modules/test_xfconf_info.py @@ -8,13 +8,12 @@ __metaclass__ = type import pytest -from ansible_collections.community.general.plugins.modules import xfconf_info as module -from .cmd_runner_test_utils import CmdRunnerTestHelper +from ansible_collections.community.general.plugins.modules import xfconf_info +from .helper import CmdRunnerTestHelper -with open("tests/unit/plugins/modules/test_xfconf_info.yaml", "r") as TEST_CASES: - helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES) - patch_bin = helper.cmd_fixture +helper = CmdRunnerTestHelper.from_file(xfconf_info.main, "tests/unit/plugins/modules/test_xfconf_info.yaml") +patch_bin = helper.cmd_fixture @pytest.mark.parametrize('patch_ansible_module, testcase',