File: test_pkg.py

package info (click to toggle)
rpmlint 2.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,308 kB
  • sloc: python: 20,622; ansic: 2,511; xml: 1,272; makefile: 17; sh: 4
file content (46 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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


def test_parse_deps():
    for (arg, exp) in (
        ('a, b < 1.0 c = 5:2.0-3 d',
         [('a', 0, (None, None, None)),
          ('b', rpm.RPMSENSE_LESS, (None, '1.0', None)),
          ('c', rpm.RPMSENSE_EQUAL, (5, '2.0', '3')),
          ('d', 0, (None, None, None))]),
    ):
        assert parse_deps(arg) == exp


def test_range_compare():
    for (req, prov) in (
        (('foo', rpm.RPMSENSE_LESS, (None, '1.0', None)),
         ('foo', rpm.RPMSENSE_EQUAL, (1, '0.5', None))),
    ):
        assert not rangeCompare(req, prov)


@pytest.mark.parametrize('package', ['binary/python311-pytest-xprocess'])
@pytest.mark.skipif(os.getuid() == 0, reason='Root has full permission')
def test_extract_fail(package, tmp_path):
    """
    Check that rpm2cpio fails to extract this package because it has no
    permissions to some files.
    """

    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')
        # check that it was rpm2cpio what failed
        assert exc.match(r'rpm2cpio .*')