mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
test helper: create static methods .from_file() and .from_list() (#7239)
create static methods .from_file() and .from_list()
This commit is contained in:
parent
bc9dca4bc8
commit
bdf8852e8d
9 changed files with 40 additions and 37 deletions
|
@ -19,6 +19,17 @@ RunCmdCall = namedtuple("RunCmdCall", ["command", "environ", "rc", "out", "err"]
|
||||||
|
|
||||||
|
|
||||||
class CmdRunnerTestHelper(object):
|
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):
|
def __init__(self, module_main, test_cases):
|
||||||
self.module_main = module_main
|
self.module_main = module_main
|
||||||
self._test_cases = test_cases
|
self._test_cases = test_cases
|
|
@ -16,12 +16,11 @@ __metaclass__ = type
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.modules import cpanm
|
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.from_file(cpanm.main, "tests/unit/plugins/modules/test_cpanm.yaml")
|
||||||
helper = CmdRunnerTestHelper(cpanm.main, test_cases=TEST_CASES)
|
patch_bin = helper.cmd_fixture
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
||||||
|
|
|
@ -9,13 +9,12 @@ __metaclass__ = type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.modules import gconftool2 as module
|
from ansible_collections.community.general.plugins.modules import gconftool2
|
||||||
from .cmd_runner_test_utils import CmdRunnerTestHelper
|
from .helper import CmdRunnerTestHelper
|
||||||
|
|
||||||
|
|
||||||
with open("tests/unit/plugins/modules/test_gconftool2.yaml", "r") as TEST_CASES:
|
helper = CmdRunnerTestHelper.from_file(gconftool2.main, "tests/unit/plugins/modules/test_gconftool2.yaml")
|
||||||
helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES)
|
patch_bin = helper.cmd_fixture
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
||||||
|
|
|
@ -10,12 +10,11 @@ __metaclass__ = type
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.modules import gconftool2_info
|
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.from_file(gconftool2_info.main, "tests/unit/plugins/modules/test_gconftool2_info.yaml")
|
||||||
helper = CmdRunnerTestHelper(gconftool2_info.main, test_cases=TEST_CASES)
|
patch_bin = helper.cmd_fixture
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
||||||
|
|
|
@ -9,13 +9,12 @@ __metaclass__ = type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.modules import opkg as module
|
from ansible_collections.community.general.plugins.modules import opkg
|
||||||
from .cmd_runner_test_utils import CmdRunnerTestHelper
|
from .helper import CmdRunnerTestHelper
|
||||||
|
|
||||||
|
|
||||||
with open("tests/unit/plugins/modules/test_opkg.yaml", "r") as TEST_CASES:
|
helper = CmdRunnerTestHelper.from_file(opkg.main, "tests/unit/plugins/modules/test_opkg.yaml")
|
||||||
helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES)
|
patch_bin = helper.cmd_fixture
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
||||||
|
|
|
@ -15,13 +15,12 @@ __metaclass__ = type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.modules import puppet as module
|
from ansible_collections.community.general.plugins.modules import puppet
|
||||||
from .cmd_runner_test_utils import CmdRunnerTestHelper
|
from .helper import CmdRunnerTestHelper
|
||||||
|
|
||||||
|
|
||||||
with open("tests/unit/plugins/modules/test_puppet.yaml", "r") as TEST_CASES:
|
helper = CmdRunnerTestHelper.from_file(puppet.main, "tests/unit/plugins/modules/test_puppet.yaml")
|
||||||
helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES)
|
patch_bin = helper.cmd_fixture
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
||||||
|
|
|
@ -8,8 +8,8 @@ __metaclass__ = type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from .cmd_runner_test_utils import CmdRunnerTestHelper, ModuleTestCase, RunCmdCall
|
from .helper import CmdRunnerTestHelper, ModuleTestCase, RunCmdCall
|
||||||
from ansible_collections.community.general.plugins.modules import snap as module
|
from ansible_collections.community.general.plugins.modules import snap
|
||||||
|
|
||||||
|
|
||||||
issue_6803_status_out = """Name Version Rev Tracking Publisher Notes
|
issue_6803_status_out = """Name Version Rev Tracking Publisher Notes
|
||||||
|
@ -444,8 +444,7 @@ TEST_CASES = [
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
helper = CmdRunnerTestHelper.from_list(snap.main, TEST_CASES)
|
||||||
helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES)
|
|
||||||
patch_bin = helper.cmd_fixture
|
patch_bin = helper.cmd_fixture
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,12 @@ __metaclass__ = type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.modules import xfconf as module
|
from ansible_collections.community.general.plugins.modules import xfconf
|
||||||
from .cmd_runner_test_utils import CmdRunnerTestHelper
|
from .helper import CmdRunnerTestHelper
|
||||||
|
|
||||||
|
|
||||||
with open("tests/unit/plugins/modules/test_xfconf.yaml", "r") as TEST_CASES:
|
helper = CmdRunnerTestHelper.from_file(xfconf.main, "tests/unit/plugins/modules/test_xfconf.yaml")
|
||||||
helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES)
|
patch_bin = helper.cmd_fixture
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
||||||
|
|
|
@ -8,13 +8,12 @@ __metaclass__ = type
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.modules import xfconf_info as module
|
from ansible_collections.community.general.plugins.modules import xfconf_info
|
||||||
from .cmd_runner_test_utils import CmdRunnerTestHelper
|
from .helper import CmdRunnerTestHelper
|
||||||
|
|
||||||
|
|
||||||
with open("tests/unit/plugins/modules/test_xfconf_info.yaml", "r") as TEST_CASES:
|
helper = CmdRunnerTestHelper.from_file(xfconf_info.main, "tests/unit/plugins/modules/test_xfconf_info.yaml")
|
||||||
helper = CmdRunnerTestHelper(module.main, test_cases=TEST_CASES)
|
patch_bin = helper.cmd_fixture
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
@pytest.mark.parametrize('patch_ansible_module, testcase',
|
||||||
|
|
Loading…
Reference in a new issue