Skip to content

Commit

Permalink
Switch to FullArgSpec since Py 3.11 no longer has ArgSpec, deprec…
Browse files Browse the repository at this point in the history
…ated since Py 3.0

Signed-off-by: Pedro Algarvio <[email protected]>
  • Loading branch information
s0undt3ch committed Jun 19, 2023
1 parent b8e3a0a commit 7d57774
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions tests/unit/states/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


import logging
from inspect import ArgSpec
from inspect import FullArgSpec

import salt.states.module as module
from tests.support.mixins import LoaderModuleMockMixin
Expand Down Expand Up @@ -117,11 +117,25 @@ def setup_loader_modules(self):

@classmethod
def setUpClass(cls):
cls.aspec = ArgSpec(
args=["hello", "world"], varargs=None, keywords=None, defaults=False
cls.aspec = FullArgSpec(
args=["hello", "world"],
varargs=None,
varkw=None,
defaults=False,
kwonlyargs=None,
kwonlydefaults=None,
annotations=None,
)

cls.bspec = ArgSpec(args=[], varargs="names", keywords="kwargs", defaults=None)
cls.bspec = FullArgSpec(
args=[],
varargs="names",
varkw=None,
defaults=None,
kwonlyargs="kwargs",
kwonlydefaults=None,
annotations=None,
)

@classmethod
def tearDownClass(cls):
Expand All @@ -137,8 +151,8 @@ def test_run_module_not_available(self):
module.__opts__, {"use_superseded": ["module.run"]}
):
ret = module.run(**{CMD: None})
if ret["comment"] != "Unavailable function: {}.".format(CMD) or ret["result"]:
self.fail("module.run did not fail as expected: {}".format(ret))
if ret["comment"] != f"Unavailable function: {CMD}." or ret["result"]:
self.fail(f"module.run did not fail as expected: {ret}")

def test_run_module_not_available_testmode(self):
"""
Expand All @@ -151,10 +165,10 @@ def test_run_module_not_available_testmode(self):
):
ret = module.run(**{CMD: None})
if (
ret["comment"] != "Unavailable function: {}.".format(CMD)
ret["comment"] != f"Unavailable function: {CMD}."
or ret["result"] is not False
):
self.fail("module.run did not fail as expected: {}".format(ret))
self.fail(f"module.run did not fail as expected: {ret}")

def test_run_module_noop(self):
"""
Expand All @@ -166,7 +180,7 @@ def test_run_module_noop(self):
):
ret = module.run()
if ret["comment"] != "No function provided." or ret["result"] is not False:
self.fail("module.run did not fail as expected: {}".format(ret))
self.fail(f"module.run did not fail as expected: {ret}")

def test_module_run_hidden_varargs(self):
"""
Expand All @@ -189,10 +203,10 @@ def test_run_testmode(self):
):
ret = module.run(**{CMD: None})
if (
ret["comment"] != "Function {} to be executed.".format(CMD)
ret["comment"] != f"Function {CMD} to be executed."
or ret["result"] is not None
):
self.fail("module.run failed: {}".format(ret))
self.fail(f"module.run failed: {ret}")

def test_run_missing_arg(self):
"""
Expand All @@ -203,9 +217,7 @@ def test_run_missing_arg(self):
module.__opts__, {"use_superseded": ["module.run"]}
):
ret = module.run(**{CMD: None})
self.assertEqual(
ret["comment"], "'{}' failed: Missing arguments: name".format(CMD)
)
self.assertEqual(ret["comment"], f"'{CMD}' failed: Missing arguments: name")

def test_run_correct_arg(self):
"""
Expand All @@ -216,8 +228,8 @@ def test_run_correct_arg(self):
module.__opts__, {"use_superseded": ["module.run"]}
):
ret = module.run(**{CMD: ["Fred"]})
if ret["comment"] != "{}: Success".format(CMD) or not ret["result"]:
self.fail("module.run failed: {}".format(ret))
if ret["comment"] != f"{CMD}: Success" or not ret["result"]:
self.fail(f"module.run failed: {ret}")

def test_run_state_apply_result_false(self):
"""
Expand Down Expand Up @@ -294,9 +306,7 @@ def test_func(arg1, arg2, **kwargs):
):
ret = module.run(**{CMD: ["bla", {"example": "bla"}]})
self.assertFalse(ret["result"])
self.assertEqual(
ret["comment"], "'{}' failed: Missing arguments: arg2".format(CMD)
)
self.assertEqual(ret["comment"], f"'{CMD}' failed: Missing arguments: arg2")

def test_run_42270_kwargs_to_args(self):
"""
Expand Down Expand Up @@ -390,19 +400,15 @@ def test_module_run_module_not_available(self):
with patch.dict(module.__salt__, {}, clear=True):
ret = module._legacy_run(CMD)
self.assertFalse(ret["result"])
self.assertEqual(
ret["comment"], "Module function {} is not available".format(CMD)
)
self.assertEqual(ret["comment"], f"Module function {CMD} is not available")

def test_module_run_test_true(self):
"""
Tests the return of module.run state when test=True is passed in
"""
with patch.dict(module.__opts__, {"test": True}):
ret = module._legacy_run(CMD)
self.assertEqual(
ret["comment"], "Module function {} is set to execute".format(CMD)
)
self.assertEqual(ret["comment"], f"Module function {CMD} is set to execute")

def test_module_run_missing_arg(self):
"""
Expand Down

0 comments on commit 7d57774

Please sign in to comment.