diff --git a/tests/unit/plugins/modules/test_cpanm.py b/tests/unit/plugins/modules/test_cpanm.py index 28090455f02..ec8e9d0f7a5 100644 --- a/tests/unit/plugins/modules/test_cpanm.py +++ b/tests/unit/plugins/modules/test_cpanm.py @@ -14,7 +14,7 @@ from ansible_collections.community.general.plugins.modules import cpanm -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(cpanm, __name__) +Helper.from_module(cpanm, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_cpanm.yaml b/tests/unit/plugins/modules/test_cpanm.yaml index ff4bd9c0f7e..979e85dafed 100644 --- a/tests/unit/plugins/modules/test_cpanm.yaml +++ b/tests/unit/plugins/modules/test_cpanm.yaml @@ -4,6 +4,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ_true: &env-def-true {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ_false: &env-def-false {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} +test_cases: - id: install_dancer_compatibility input: name: Dancer @@ -14,14 +18,14 @@ mocks: run_command: - command: [/testbin/cpanm, --version] - environ: &env-def-true {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ: *env-def-true rc: 0 out: | cpanm (App::cpanminus) version 1.7047 (/usr/local/bin/cpanm) perl version 5.041005 (/usr/local/bin/perl) err: "" - command: [/testbin/perl, -le, 'use Dancer;'] - environ: &env-def-false {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} + environ: *env-def-false rc: 2 out: "" err: "error, not installed" diff --git a/tests/unit/plugins/modules/test_django_check.py b/tests/unit/plugins/modules/test_django_check.py index 52210bdb768..e65b8454d9d 100644 --- a/tests/unit/plugins/modules/test_django_check.py +++ b/tests/unit/plugins/modules/test_django_check.py @@ -7,7 +7,7 @@ from ansible_collections.community.general.plugins.modules import django_check -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(django_check, __name__) +Helper.from_module(django_check, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_django_check.yaml b/tests/unit/plugins/modules/test_django_check.yaml index 74374c01c97..1b8b36a52cf 100644 --- a/tests/unit/plugins/modules/test_django_check.yaml +++ b/tests/unit/plugins/modules/test_django_check.yaml @@ -4,6 +4,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} +test_cases: - id: success input: settings: whatever.settings @@ -12,7 +15,7 @@ mocks: run_command: - command: [/testbin/python, -m, django, --version] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ: *env-def rc: 0 out: "5.1.2\n" err: "" diff --git a/tests/unit/plugins/modules/test_django_command.py b/tests/unit/plugins/modules/test_django_command.py index 8be910fd273..f26c05498e8 100644 --- a/tests/unit/plugins/modules/test_django_command.py +++ b/tests/unit/plugins/modules/test_django_command.py @@ -7,7 +7,7 @@ from ansible_collections.community.general.plugins.modules import django_command -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(django_command, __name__) +Helper.from_module(django_command, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_django_command.yaml b/tests/unit/plugins/modules/test_django_command.yaml index 960dc1a24f6..a98182385e5 100644 --- a/tests/unit/plugins/modules/test_django_command.yaml +++ b/tests/unit/plugins/modules/test_django_command.yaml @@ -4,6 +4,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} +test_cases: - id: command_success input: command: check @@ -16,7 +19,7 @@ mocks: run_command: - command: [/testbin/python, -m, django, --version] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ: *env-def rc: 0 out: "5.1.2\n" err: "" diff --git a/tests/unit/plugins/modules/test_django_createcachetable.py b/tests/unit/plugins/modules/test_django_createcachetable.py index 74bdf1cc639..6da0720d820 100644 --- a/tests/unit/plugins/modules/test_django_createcachetable.py +++ b/tests/unit/plugins/modules/test_django_createcachetable.py @@ -7,7 +7,7 @@ from ansible_collections.community.general.plugins.modules import django_createcachetable -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(django_createcachetable, __name__) +Helper.from_module(django_createcachetable, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_django_createcachetable.yaml b/tests/unit/plugins/modules/test_django_createcachetable.yaml index a58146144a2..e800fb65ac1 100644 --- a/tests/unit/plugins/modules/test_django_createcachetable.yaml +++ b/tests/unit/plugins/modules/test_django_createcachetable.yaml @@ -4,13 +4,16 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} +test_cases: - id: command_success input: settings: whatever.settings mocks: run_command: - command: [/testbin/python, -m, django, --version] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ: *env-def rc: 0 out: "5.1.2\n" err: "" diff --git a/tests/unit/plugins/modules/test_facter_facts.py b/tests/unit/plugins/modules/test_facter_facts.py index bb74216b88d..8d0896226b9 100644 --- a/tests/unit/plugins/modules/test_facter_facts.py +++ b/tests/unit/plugins/modules/test_facter_facts.py @@ -8,7 +8,7 @@ from ansible_collections.community.general.plugins.modules import facter_facts -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(facter_facts, __name__) +Helper.from_module(facter_facts, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_facter_facts.yaml b/tests/unit/plugins/modules/test_facter_facts.yaml index e53f7fe60f9..ffce162b27b 100644 --- a/tests/unit/plugins/modules/test_facter_facts.yaml +++ b/tests/unit/plugins/modules/test_facter_facts.yaml @@ -4,6 +4,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {check_rc: true} +test_cases: - id: simple run output: ansible_facts: @@ -14,7 +17,7 @@ mocks: run_command: - command: [/testbin/facter, --json] - environ: &env-def {check_rc: true} + environ: *env-def rc: 0 out: > { "a": 1, "b": 2, "c": 3 } diff --git a/tests/unit/plugins/modules/test_gconftool2.py b/tests/unit/plugins/modules/test_gconftool2.py index 2ba2e1c70e3..52698c5969a 100644 --- a/tests/unit/plugins/modules/test_gconftool2.py +++ b/tests/unit/plugins/modules/test_gconftool2.py @@ -8,7 +8,7 @@ from ansible_collections.community.general.plugins.modules import gconftool2 -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(gconftool2, __name__) +Helper.from_module(gconftool2, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_gconftool2.yaml b/tests/unit/plugins/modules/test_gconftool2.yaml index badbdf26149..12bf9099f48 100644 --- a/tests/unit/plugins/modules/test_gconftool2.yaml +++ b/tests/unit/plugins/modules/test_gconftool2.yaml @@ -4,6 +4,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} +test_cases: - id: test_simple_element_set input: state: present @@ -17,7 +20,7 @@ mocks: run_command: - command: [/testbin/gconftool-2, --version] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ: *env-def rc: 0 out: "3.2.6\n" err: "" diff --git a/tests/unit/plugins/modules/test_gconftool2_info.py b/tests/unit/plugins/modules/test_gconftool2_info.py index 4daa6557142..362f33e49aa 100644 --- a/tests/unit/plugins/modules/test_gconftool2_info.py +++ b/tests/unit/plugins/modules/test_gconftool2_info.py @@ -8,7 +8,7 @@ from ansible_collections.community.general.plugins.modules import gconftool2_info -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(gconftool2_info, __name__) +Helper.from_module(gconftool2_info, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_gconftool2_info.yaml b/tests/unit/plugins/modules/test_gconftool2_info.yaml index fac04430a07..269f0b4ea2e 100644 --- a/tests/unit/plugins/modules/test_gconftool2_info.yaml +++ b/tests/unit/plugins/modules/test_gconftool2_info.yaml @@ -4,6 +4,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} +test_cases: - id: test_simple_element_get input: key: /desktop/gnome/background/picture_filename @@ -12,7 +15,7 @@ mocks: run_command: - command: [/testbin/gconftool-2, --version] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ: *env-def rc: 0 out: "3.2.6\n" err: "" diff --git a/tests/unit/plugins/modules/test_gio_mime.py b/tests/unit/plugins/modules/test_gio_mime.py index 5e51320485f..24bac3de93f 100644 --- a/tests/unit/plugins/modules/test_gio_mime.py +++ b/tests/unit/plugins/modules/test_gio_mime.py @@ -8,7 +8,7 @@ from ansible_collections.community.general.plugins.modules import gio_mime -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(gio_mime, __name__) +Helper.from_module(gio_mime, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_gio_mime.yaml b/tests/unit/plugins/modules/test_gio_mime.yaml index 36454462918..c1a3c5def5a 100644 --- a/tests/unit/plugins/modules/test_gio_mime.yaml +++ b/tests/unit/plugins/modules/test_gio_mime.yaml @@ -4,6 +4,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} +test_cases: - id: test_set_handler input: handler: google-chrome.desktop @@ -14,7 +17,7 @@ mocks: run_command: - command: [/testbin/gio, --version] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ: *env-def rc: 0 out: "2.80.0\n" err: "" diff --git a/tests/unit/plugins/modules/test_krb_ticket.py b/tests/unit/plugins/modules/test_krb_ticket.py index 8c17e2e43b9..68e73159c9c 100644 --- a/tests/unit/plugins/modules/test_krb_ticket.py +++ b/tests/unit/plugins/modules/test_krb_ticket.py @@ -8,7 +8,7 @@ from ansible_collections.community.general.plugins.modules import krb_ticket -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(krb_ticket, __name__) +Helper.from_module(krb_ticket, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_krb_ticket.yaml b/tests/unit/plugins/modules/test_krb_ticket.yaml index 9882bf137d0..cfc9e212cbe 100644 --- a/tests/unit/plugins/modules/test_krb_ticket.yaml +++ b/tests/unit/plugins/modules/test_krb_ticket.yaml @@ -4,6 +4,11 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} + environ_data: &env-data {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true, data: cool_password} + environ_norc: &env-norc {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} +test_cases: - id: test_kinit_default input: state: present @@ -13,12 +18,12 @@ mocks: run_command: - command: [/testbin/klist] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} + environ: *env-def rc: 1 out: "" err: "" - command: [/testbin/kinit] - environ: &env-data {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true, data: cool_password} + environ: *env-data rc: 0 out: "" err: "" @@ -54,7 +59,7 @@ out: "" err: "" - command: [/testbin/kdestroy] - environ: &env-norc {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true} + environ: *env-norc rc: 0 out: "" err: "" diff --git a/tests/unit/plugins/modules/test_opkg.py b/tests/unit/plugins/modules/test_opkg.py index cfee3e11155..cdc93ee887e 100644 --- a/tests/unit/plugins/modules/test_opkg.py +++ b/tests/unit/plugins/modules/test_opkg.py @@ -8,7 +8,7 @@ from ansible_collections.community.general.plugins.modules import opkg -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(opkg, __name__) +Helper.from_module(opkg, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_opkg.yaml b/tests/unit/plugins/modules/test_opkg.yaml index 090a72c20c4..e6f627457d7 100644 --- a/tests/unit/plugins/modules/test_opkg.yaml +++ b/tests/unit/plugins/modules/test_opkg.yaml @@ -4,6 +4,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} +test_cases: - id: install_zlibdev input: name: zlib-dev @@ -13,7 +16,7 @@ mocks: run_command: - command: [/testbin/opkg, --version] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} + environ: *env-def rc: 0 out: "" err: "" diff --git a/tests/unit/plugins/modules/test_puppet.py b/tests/unit/plugins/modules/test_puppet.py index efdb042a5a5..d7c8f1bd0b6 100644 --- a/tests/unit/plugins/modules/test_puppet.py +++ b/tests/unit/plugins/modules/test_puppet.py @@ -14,7 +14,7 @@ from ansible_collections.community.general.plugins.modules import puppet -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(puppet, __name__) +Helper.from_module(puppet, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_puppet.yaml b/tests/unit/plugins/modules/test_puppet.yaml index 668571273ce..44cfb98d6f2 100644 --- a/tests/unit/plugins/modules/test_puppet.yaml +++ b/tests/unit/plugins/modules/test_puppet.yaml @@ -4,6 +4,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} +test_cases: - id: puppet_agent_plain input: {} output: @@ -11,7 +14,7 @@ mocks: run_command: - command: [/testbin/puppet, config, print, agent_disabled_lockfile] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} + environ: *env-def rc: 0 out: "blah, anything" err: "" diff --git a/tests/unit/plugins/modules/test_snap.py b/tests/unit/plugins/modules/test_snap.py index de7f35353a0..5ed366d724a 100644 --- a/tests/unit/plugins/modules/test_snap.py +++ b/tests/unit/plugins/modules/test_snap.py @@ -9,7 +9,7 @@ import sys from ansible_collections.community.general.plugins.modules import snap -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock issue_6803_status_out = """Name Version Rev Tracking Publisher Notes @@ -475,4 +475,4 @@ ), ] -Helper.from_spec(sys.modules[__name__], snap, TEST_CASES) +Helper.from_spec(sys.modules[__name__], snap, TEST_CASES, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_xfconf.py b/tests/unit/plugins/modules/test_xfconf.py index f902797ee34..550345b112c 100644 --- a/tests/unit/plugins/modules/test_xfconf.py +++ b/tests/unit/plugins/modules/test_xfconf.py @@ -14,7 +14,7 @@ from ansible_collections.community.general.plugins.modules import xfconf -from .helper import Helper, RunCommandMock # pylint: disable=unused-import +from .helper import Helper, RunCommandMock -Helper.from_module(xfconf, __name__) +Helper.from_module(xfconf, __name__, mocks=[RunCommandMock]) diff --git a/tests/unit/plugins/modules/test_xfconf.yaml b/tests/unit/plugins/modules/test_xfconf.yaml index c52c8f7c1b5..f306bfdfa06 100644 --- a/tests/unit/plugins/modules/test_xfconf.yaml +++ b/tests/unit/plugins/modules/test_xfconf.yaml @@ -4,6 +4,16 @@ # SPDX-License-Identifier: GPL-3.0-or-later --- +anchors: + environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} + version_out: &version-output | + xfconf-query 4.18.1 + + Copyright (c) 2008-2023 + The Xfce development team. All rights reserved. + + Please report bugs to . +test_cases: - id: test_missing_input input: {} output: @@ -25,15 +35,9 @@ mocks: run_command: - command: [/testbin/xfconf-query, --version] - environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false} + environ: *env-def rc: 0 - out: &version-output | - xfconf-query 4.18.1 - - Copyright (c) 2008-2023 - The Xfce development team. All rights reserved. - - Please report bugs to . + out: *version-output err: "" - command: [/testbin/xfconf-query, --channel, xfwm4, --property, /general/inactive_opacity] environ: *env-def