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: Helper.from_module() injects test function into test module (#7560)

This commit is contained in:
Alexei Znamensky 2023-11-20 23:23:16 +13:00 committed by GitHub
parent 404782c9d7
commit 9b16392648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 29 deletions

View file

@ -6,6 +6,7 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import sys
import json
from collections import namedtuple
from itertools import chain, repeat
@ -108,11 +109,13 @@ class Helper(object):
return helper
@staticmethod
def from_module(module):
def from_module(module, test_module_name):
basename = module.__name__.split(".")[-1]
test_spec = "tests/unit/plugins/modules/test_{0}.yaml".format(basename)
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):
self.module_main = module_main

View file

@ -17,6 +17,4 @@ from ansible_collections.community.general.plugins.modules import cpanm
from .helper import Helper
helper = Helper.from_module(cpanm)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(cpanm, __name__)

View file

@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import facter_facts
from .helper import Helper
helper = Helper.from_module(facter_facts)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(facter_facts, __name__)

View file

@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import gconftool2
from .helper import Helper
helper = Helper.from_module(gconftool2)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(gconftool2, __name__)

View file

@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import gconftool2_inf
from .helper import Helper
helper = Helper.from_module(gconftool2_info)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(gconftool2_info, __name__)

View file

@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import gio_mime
from .helper import Helper
helper = Helper.from_module(gio_mime)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(gio_mime, __name__)

View file

@ -11,6 +11,4 @@ from ansible_collections.community.general.plugins.modules import opkg
from .helper import Helper
helper = Helper.from_module(opkg)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(opkg, __name__)

View file

@ -17,6 +17,4 @@ from ansible_collections.community.general.plugins.modules import puppet
from .helper import Helper
helper = Helper.from_module(puppet)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(puppet, __name__)

View file

@ -17,6 +17,4 @@ from ansible_collections.community.general.plugins.modules import xfconf
from .helper import Helper
helper = Helper.from_module(xfconf)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(xfconf, __name__)

View file

@ -10,6 +10,4 @@ from ansible_collections.community.general.plugins.modules import xfconf_info
from .helper import Helper
helper = Helper.from_module(xfconf_info)
patch_bin = helper.cmd_fixture
test_module = helper.test_module
Helper.from_module(xfconf_info, __name__)