Skip to content

Commit

Permalink
Merge pull request #1153 from rpm-software-management/missing-depende…
Browse files Browse the repository at this point in the history
…ncy-on-with-epoch

test: Extend tag tests to check 'W: missing-dependency-on'
  • Loading branch information
danigm authored Dec 14, 2023
2 parents cb507aa + 663c98a commit a79af73
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
28 changes: 26 additions & 2 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,29 @@ def check_signature(self):
return (0, 'fake: pgp md5 OK')


class FakeHeader(dict):
def sprintf(self, expr):
"""
Replaces expressions like %{} with actual package
"""

tagre = re.compile(r'%{([^}]*)}')
for tag in tagre.findall(expr):
expr = expr.replace(f'%{tag}', self[f'RPMTAG_{tag}'])
return expr

def __missing__(self, key):
try:
key = getattr(rpm, key)
except (TypeError, KeyError):
raise KeyError

if key not in self:
raise KeyError

return self[key]


# Class to provide an API to a 'fake' package, eg. for specfile-only checks
class FakePkg(AbstractPkg):
_autoheaders = [
Expand All @@ -779,6 +802,7 @@ class FakePkg(AbstractPkg):

def __init__(self, name, is_source=False):
self.name = str(name)
self.filename = f'{name}.rpm'
self.arch = None
self.current_linenum = None
self.dirname = None
Expand All @@ -789,7 +813,7 @@ def __init__(self, name, is_source=False):
self.ghost_files = {}

# header is a dictionary to mock rpm metadata
self.header = {}
self.header = FakeHeader()
for i in self._autoheaders:
# the header name wihtout the ending 's'
tagname = i[:-1].upper()
Expand Down Expand Up @@ -898,7 +922,7 @@ def add_header(self, header):
tagname = k[:-1].upper()
for i in v:
name, flags, version = parse_deps(i)[0]
version = f'{version[1]}-{version[2]}'
version = f'{version[0]}:{version[1]}-{version[2]}'
self.header[getattr(rpm, f'RPMTAG_{tagname}NAME')].append(name)
self.header[getattr(rpm, f'RPMTAG_{tagname}FLAGS')].append(flags)
self.header[getattr(rpm, f'RPMTAG_{tagname}VERSION')].append(version)
Expand Down
4 changes: 2 additions & 2 deletions test/Testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def get_tested_spec_package(name):
return FakePkg(candidates[0])


def get_tested_mock_package(files=None, header=None):
mockPkg = FakePkg('mockPkg')
def get_tested_mock_package(files=None, header=None, name='mockPkg'):
mockPkg = FakePkg(name)
if files is not None:
if isinstance(files, dict):
# full path for test files
Expand Down
40 changes: 39 additions & 1 deletion test/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import rpmlint.spellcheck

from Testing import CONFIG, get_tested_package
from Testing import get_tested_mock_package
from Testing import HAS_ENGLISH_DICTIONARY, HAS_FRENCH_DICTIONARY


Expand All @@ -12,7 +13,19 @@ def tagscheck():
CONFIG.info = True
output = Filter(CONFIG)
test = TagsCheck(CONFIG, output)
return output, test
yield output, test


@pytest.fixture
def output(tagscheck):
output, _test = tagscheck
yield output


@pytest.fixture
def test(tagscheck):
_output, test = tagscheck
yield test


@pytest.mark.parametrize('package', ['binary/unexpanded1'])
Expand Down Expand Up @@ -439,3 +452,28 @@ def test_description_spelling_error(tmp_path, package, tagscheck):
test.check(get_tested_package(package, tmp_path))
out = output.print_results(output.results)
assert 'E: spelling-error' in out


@pytest.mark.parametrize('package', [
get_tested_package('binary/xrootd-devel', '/tmp/'),
get_tested_mock_package(
name='xrootd-devel',
files=[
'/usr/lib64/libXrdXml.so',
],
header={
'requires': [
'xrootd-libs(x86-64) = 1:5.6.3-2.fc39',
],
'ARCH': 'noarch',
'NAME': 'xrootd-devel',
'VERSION': '5.6.3',
'RELEASE': '2.fc39',
'EPOCH': 1,
},
),
])
def test_missing_dependency_on_with_epoch(package, output, test):
test.check(package)
out = output.print_results(output.results)
assert 'W: missing-dependency-on' not in out

0 comments on commit a79af73

Please sign in to comment.