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):
|
||||
@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
|
|
@ -16,11 +16,10 @@ __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)
|
||||
helper = CmdRunnerTestHelper.from_file(cpanm.main, "tests/unit/plugins/modules/test_cpanm.yaml")
|
||||
patch_bin = helper.cmd_fixture
|
||||
|
||||
|
||||
|
|
|
@ -9,12 +9,11 @@ __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)
|
||||
helper = CmdRunnerTestHelper.from_file(gconftool2.main, "tests/unit/plugins/modules/test_gconftool2.yaml")
|
||||
patch_bin = helper.cmd_fixture
|
||||
|
||||
|
||||
|
|
|
@ -10,11 +10,10 @@ __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)
|
||||
helper = CmdRunnerTestHelper.from_file(gconftool2_info.main, "tests/unit/plugins/modules/test_gconftool2_info.yaml")
|
||||
patch_bin = helper.cmd_fixture
|
||||
|
||||
|
||||
|
|
|
@ -9,12 +9,11 @@ __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)
|
||||
helper = CmdRunnerTestHelper.from_file(opkg.main, "tests/unit/plugins/modules/test_opkg.yaml")
|
||||
patch_bin = helper.cmd_fixture
|
||||
|
||||
|
||||
|
|
|
@ -15,12 +15,11 @@ __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)
|
||||
helper = CmdRunnerTestHelper.from_file(puppet.main, "tests/unit/plugins/modules/test_puppet.yaml")
|
||||
patch_bin = helper.cmd_fixture
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -15,12 +15,11 @@ __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)
|
||||
helper = CmdRunnerTestHelper.from_file(xfconf.main, "tests/unit/plugins/modules/test_xfconf.yaml")
|
||||
patch_bin = helper.cmd_fixture
|
||||
|
||||
|
||||
|
|
|
@ -8,12 +8,11 @@ __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)
|
||||
helper = CmdRunnerTestHelper.from_file(xfconf_info.main, "tests/unit/plugins/modules/test_xfconf_info.yaml")
|
||||
patch_bin = helper.cmd_fixture
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue