Simplify check_utils into check_dnf
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:
parent
8798c3c7d4
commit
c57888877c
2 changed files with 11 additions and 15 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue