Skip to content

Commit

Permalink
test: Fix test_extract_fail when running as root
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Sep 4, 2024
1 parent cd5f890 commit ce08677
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def test_header_information(capsys):
@pytest.mark.no_cover
def test_run_full_rpm(capsys, packages, configs):
# the package cannot be extracted using rpm2cpio because it contains a directory without 'x' permission
packages.remove(Path("test/binary/python311-pytest-xprocess-0.23.0-2.4.noarch.rpm"))
packages.remove(Path('test/binary/python311-pytest-xprocess-0.23.0-2.4.noarch.rpm'))

number_of_pkgs = len(packages)
additional_options = {
Expand Down
21 changes: 16 additions & 5 deletions test/test_pkg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
import rpm
import os
import subprocess
import unittest.mock as mock

import pytest
import rpm
from rpmlint.pkg import parse_deps, rangeCompare

from Testing import get_tested_package
Expand All @@ -28,11 +30,20 @@ def test_range_compare():

@pytest.mark.parametrize('package', ['binary/python311-pytest-xprocess'])
def test_extract_fail(package, tmp_path):
with mock.patch("shutil.which") as mock_which:
"""
Check that rpm2cpio fails to extract this package because it has no
permissions to some files.
"""

# Root can extract the package, so nothing to check
if os.getuid() == 0:
return

with mock.patch('shutil.which') as mock_which:
mock_which.return_value = None
# 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)
mock_which.assert_called_once_with("rpm2archive")
mock_which.assert_called_once_with('rpm2archive')
# check that it was rpm2cpio what failed
assert exc.match(r"rpm2cpio .*")
assert exc.match(r'rpm2cpio .*')

0 comments on commit ce08677

Please sign in to comment.