Simplify check_utils into check_dnf
All checks were successful
CI via Tox / tox (pull_request) Successful in 1m28s
AI Code Review / ai-review (pull_request_target) Successful in 23s

We're only checking for one thing, now. Long may this last.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
Adam Williamson 2026-04-20 12:10:48 -07:00
commit c57888877c
2 changed files with 11 additions and 15 deletions

View file

@ -335,22 +335,18 @@ def parse_args() -> argparse.Namespace:
return args
def check_utils() -> None:
"""Check required utilities are installed."""
missing = []
for prog in (("dnf", "--version"),):
try:
subprocess.run(prog, stdout=subprocess.DEVNULL, check=True)
except FileNotFoundError:
missing.append(prog[0])
if missing:
sys.exit("Please install missing required utilities: " + " ".join(missing))
def check_dnf() -> None:
"""Check DNF is installed."""
try:
subprocess.run(("dnf", "--version"), stdout=subprocess.DEVNULL, check=True)
except FileNotFoundError:
sys.exit("Please install missing required utilities: dnf")
def main() -> None:
"""Main loop."""
try:
check_utils()
check_dnf()
exitcode = 0
args = parse_args()
if f"--forcearch={args.arch}" not in DNFARGS:

View file

@ -180,15 +180,15 @@ def test_check_arch(_):
@mock.patch("subprocess.run", autospec=True)
def test_check_utils(mock_run):
rmdepcheck.check_utils()
def test_check_dnf(mock_run):
rmdepcheck.check_dnf()
mock_run.side_effect = FileNotFoundError
with pytest.raises(SystemExit) as excinfo:
rmdepcheck.check_utils()
rmdepcheck.check_dnf()
assert excinfo.value.code == "Please install missing required utilities: dnf"
@mock.patch("rmdepcheck.check_utils", side_effect=KeyboardInterrupt)
@mock.patch("rmdepcheck.check_dnf", side_effect=KeyboardInterrupt)
def test_ctrl_c(_, capsys):
with pytest.raises(SystemExit) as excinfo:
rmdepcheck.main()