1
0
Fork 0
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:
Alexei Znamensky 2023-09-12 16:42:33 +12:00 committed by GitHub
parent bc9dca4bc8
commit bdf8852e8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 37 deletions

View file

@ -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

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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

View file

@ -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',

View file

@ -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',