Skip to content

Commit

Permalink
Reset self.result, run reset in the beginning of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrosi committed Apr 18, 2024
1 parent c6abe50 commit f97bfa2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/unit/test_bootloader_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class InputValidator(unittest.TestCase):
def reset_vars(self):
self.mock_module.run_command.reset_mock()
self.mock_module.fail_json.reset_mock()
self.result = dict(changed=False, actions=list())
try:
del self.kernel
except AttributeError:
Expand All @@ -190,6 +191,7 @@ def assert_error_msg(self, err, *cmd_args):
self.mock_module.fail_json.assert_called_once_with(err)

def test_validate_kernels(self):
self.reset_vars()
self.kernel_action, self.kernel = bootloader_settings.validate_kernels(
self.mock_module, SETTINGS[0], FACTS
)
Expand Down Expand Up @@ -251,7 +253,6 @@ def test_validate_kernels(self):
self.assert_error_msg(err, *cmd_args)
self.assertIsNone(self.kernel_action)
self.assertIsNone(self.kernel)

self.reset_vars()

self.kernel_action, self.kernel = bootloader_settings.validate_kernels(
Expand Down Expand Up @@ -294,6 +295,7 @@ def test_validate_kernels(self):
self.reset_vars()

def test_add_kernel(self):
self.reset_vars()
self.kernel = bootloader_settings.get_create_kernel(SETTINGS[8]["kernel"])
bootloader_settings.add_kernel(
self.mock_module, self.result, SETTINGS[8]["options"], self.kernel
Expand All @@ -308,11 +310,12 @@ def test_add_kernel(self):
self.result["changed"], True
)
self.assertEqual(
self.result["actions"][-1], expected_cmd
self.result["actions"][0], expected_cmd
)
self.reset_vars()

def test_rm_kernel(self):
self.reset_vars()
self.kernel = bootloader_settings.get_single_kernel(SETTINGS[3]["kernel"])
self.assertEqual(
self.kernel,
Expand All @@ -326,7 +329,7 @@ def test_rm_kernel(self):
self.result["changed"], True
)
self.assertEqual(
self.result["actions"][-1], expected_cmd
self.result["actions"][0], expected_cmd
)
self.reset_vars()

Expand All @@ -345,6 +348,7 @@ def test_get_boot_args(self):
self.assertEqual(bootloader_args, "")

def test_rm_boot_args(self):
self.reset_vars()
bootloader_settings.rm_boot_args(
self.mock_module, self.result, INFO, "0"
)
Expand All @@ -357,11 +361,12 @@ def test_rm_boot_args(self):
self.result["changed"], True
)
self.assertEqual(
self.result["actions"][-1], expected_cmd
self.result["actions"][0], expected_cmd
)
self.reset_vars()

def test_mod_boot_args(self):
self.reset_vars()
args = (
"--remove-args='arg_with_str_value_absent=test_value arg_with_int_value_absent=1 arg_without_val_absent' "
+ "--args='arg_with_str_value=test_value arg_with_int_value=1 arg_without_val'"
Expand All @@ -376,7 +381,7 @@ def test_mod_boot_args(self):
self.result["changed"], True
)
self.assertEqual(
self.result["actions"][-1], expected_cmd
self.result["actions"][0], expected_cmd
)
self.reset_vars()

Expand All @@ -389,7 +394,7 @@ def test_mod_boot_args(self):
self.result["changed"], True
)
self.assertEqual(
self.result["actions"][-1], expected_cmd
self.result["actions"][0], expected_cmd
)
self.reset_vars()

Expand All @@ -411,7 +416,7 @@ def test_mod_boot_args(self):
self.result["changed"], True
)
self.assertEqual(
self.result["actions"][-1], expected_cmd
self.result["actions"][0], expected_cmd
)
self.reset_vars()

Expand All @@ -428,7 +433,7 @@ def test_mod_boot_args(self):
self.result["changed"], True
)
self.assertEqual(
self.result["actions"][-1], expected_cmd
self.result["actions"][0], expected_cmd
)
self.reset_vars()

Expand All @@ -445,6 +450,6 @@ def test_mod_boot_args(self):
self.result["changed"], True
)
self.assertEqual(
self.result["actions"][-1], expected_cmd
self.result["actions"][0], expected_cmd
)
self.reset_vars()

0 comments on commit f97bfa2

Please sign in to comment.