Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 21, 2023
1 parent 9786657 commit 8b5a07f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
6 changes: 2 additions & 4 deletions scripts/preconversion_assessment_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def install_convert2rhel(pkgs_to_cleanup):
"""Install the convert2rhel tool to the system."""
print("Installing & updating Convert2RHEL package.")

c2r_pkg_name = 'convert2rhel'
c2r_pkg_name = "convert2rhel"
c2r_installed = _check_if_package_installed(c2r_pkg_name)

if not c2r_installed:
Expand All @@ -259,9 +259,7 @@ def install_convert2rhel(pkgs_to_cleanup):
)
pkgs_to_cleanup.append(pkgs_to_cleanup)

output, returncode = run_subprocess(
["/usr/bin/yum", "update", c2r_pkg_name, "-y"]
)
output, returncode = run_subprocess(["/usr/bin/yum", "update", c2r_pkg_name, "-y"])
if returncode:
raise ProcessError(
message="Failed to update convert2rhel RPM.",
Expand Down
29 changes: 22 additions & 7 deletions tests/preconversion_assessment/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@pytest.mark.parametrize(
("subprocess_mock", "pkg_installed_mock", "pkg_removal_len"),
(
([(b"output", 0), (b"output", 0)], False , 1),
([(b"output", 0)], True , 0), # just update with no removed packages
([(b"output", 0), (b"output", 0)], False, 1),
([(b"output", 0)], True, 0), # just update with no removed packages
),
)
def test_install_convert2rhel(subprocess_mock, pkg_installed_mock, pkg_removal_len):
Expand All @@ -33,13 +33,21 @@ def test_install_convert2rhel(subprocess_mock, pkg_installed_mock, pkg_removal_l
["/usr/bin/yum", "update", "convert2rhel", "-y"],
]
if pkg_removal_len > 0:
expected_calls = [["/usr/bin/yum", "install", "convert2rhel", "-y"]] + expected_calls
expected_calls = [
["/usr/bin/yum", "install", "convert2rhel", "-y"]
] + expected_calls

assert mock_run_subprocess.call_args_list == [call(args) for args in expected_calls]


@patch("scripts.preconversion_assessment_script._check_if_package_installed", return_value=False)
@patch("scripts.preconversion_assessment_script.run_subprocess", return_value=(b"failed", 1))
@patch(
"scripts.preconversion_assessment_script._check_if_package_installed",
return_value=False,
)
@patch(
"scripts.preconversion_assessment_script.run_subprocess",
return_value=(b"failed", 1),
)
def test_install_convert2rhel_raise_exception(mock_run_subprocess, mock_pkg_check):
with pytest.raises(
ProcessError,
Expand All @@ -52,8 +60,15 @@ def test_install_convert2rhel_raise_exception(mock_run_subprocess, mock_pkg_chec
mock_pkg_check.assert_called_once()
assert mock_run_subprocess.call_args_list == [call(args) for args in expected_calls]

@patch("scripts.preconversion_assessment_script._check_if_package_installed", return_value=False)
@patch("scripts.preconversion_assessment_script.run_subprocess", side_effect=[(b"output", 0), (b"failed", 1)])

@patch(
"scripts.preconversion_assessment_script._check_if_package_installed",
return_value=False,
)
@patch(
"scripts.preconversion_assessment_script.run_subprocess",
side_effect=[(b"output", 0), (b"failed", 1)],
)
def test_update_convert2rhel_raise_exception(mock_run_subprocess, mock_pkg_check):
with pytest.raises(
ProcessError,
Expand Down

0 comments on commit 8b5a07f

Please sign in to comment.