From c6a63e2bf4cc901a33357cca985e3b1dc2d04a47 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Wed, 14 Aug 2024 15:45:41 +0200 Subject: [PATCH] Rewrite test_extract to *_fail variant that tests an expected failure in rpm2cpio --- test/test_pkg.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/test_pkg.py b/test/test_pkg.py index 805eb42b6..694e51cce 100644 --- a/test/test_pkg.py +++ b/test/test_pkg.py @@ -1,5 +1,8 @@ import pytest import rpm +import shutil +import subprocess +import unittest.mock as mock from rpmlint.pkg import parse_deps, rangeCompare from Testing import get_tested_package @@ -24,6 +27,16 @@ def test_range_compare(): assert not rangeCompare(req, prov) +def mock_which_rpm2archive(cmd, *args, **kwargs): + # pretend that there's no rpm2archive because we're testing a rpm2cpio failure + if cmd == "rpm2archive": + return None + return shutil.which(cmd, *args, **kwargs) + + +@mock.patch('shutil.which', new=mock_which_rpm2archive) @pytest.mark.parametrize('package', ['binary/python311-pytest-xprocess']) -def test_extract(package, tmp_path): - get_tested_package(package, tmp_path) +def test_extract_fail(package, tmp_path): + # the package cannot be extracted using rpm2cpio because it contains a directory without 'x' permission + with pytest.raises(subprocess.CalledProcessError) as exc: + get_tested_package(package, tmp_path)