mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
test helper: Helper.from_module() injects test function into test module (#7560)
This commit is contained in:
parent
404782c9d7
commit
9b16392648
10 changed files with 14 additions and 29 deletions
|
@ -6,6 +6,7 @@
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from itertools import chain, repeat
|
from itertools import chain, repeat
|
||||||
|
@ -108,11 +109,13 @@ class Helper(object):
|
||||||
return helper
|
return helper
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_module(module):
|
def from_module(module, test_module_name):
|
||||||
basename = module.__name__.split(".")[-1]
|
basename = module.__name__.split(".")[-1]
|
||||||
test_spec = "tests/unit/plugins/modules/test_{0}.yaml".format(basename)
|
test_spec = "tests/unit/plugins/modules/test_{0}.yaml".format(basename)
|
||||||
helper = Helper.from_file(module.main, test_spec)
|
helper = Helper.from_file(module.main, test_spec)
|
||||||
return helper
|
|
||||||
|
setattr(sys.modules[test_module_name], "patch_bin", helper.cmd_fixture)
|
||||||
|
setattr(sys.modules[test_module_name], "test_module", helper.test_module)
|
||||||
|
|
||||||
def __init__(self, module_main, test_cases):
|
def __init__(self, module_main, test_cases):
|
||||||
self.module_main = module_main
|
self.module_main = module_main
|
||||||
|
|
|
@ -17,6 +17,4 @@ from ansible_collections.community.general.plugins.modules import cpanm
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(cpanm)
|
Helper.from_module(cpanm, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
|
@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import facter_facts
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(facter_facts)
|
Helper.from_module(facter_facts, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
|
@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import gconftool2
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(gconftool2)
|
Helper.from_module(gconftool2, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
|
@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import gconftool2_inf
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(gconftool2_info)
|
Helper.from_module(gconftool2_info, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
|
@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import gio_mime
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(gio_mime)
|
Helper.from_module(gio_mime, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
|
@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import opkg
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(opkg)
|
Helper.from_module(opkg, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
|
@ -17,6 +17,4 @@ from ansible_collections.community.general.plugins.modules import puppet
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(puppet)
|
Helper.from_module(puppet, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
|
@ -17,6 +17,4 @@ from ansible_collections.community.general.plugins.modules import xfconf
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(xfconf)
|
Helper.from_module(xfconf, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
|
@ -10,6 +10,4 @@ from ansible_collections.community.general.plugins.modules import xfconf_info
|
||||||
from .helper import Helper
|
from .helper import Helper
|
||||||
|
|
||||||
|
|
||||||
helper = Helper.from_module(xfconf_info)
|
Helper.from_module(xfconf_info, __name__)
|
||||||
patch_bin = helper.cmd_fixture
|
|
||||||
test_module = helper.test_module
|
|
||||||
|
|
Loading…
Reference in a new issue