Skip to content

Commit

Permalink
test: Mocking TagsCheck binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Oct 3, 2024
1 parent 2afb620 commit 1328572
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
6 changes: 2 additions & 4 deletions rpmlint/checks/TagsCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ def check_description(self, pkg, lang, ignored_words):
description = byte_to_string(description)
self._unexpanded_macros(pkg, '%%description -l %s' % lang, description)
if self.spellcheck:
pkgname = byte_to_string(pkg.header[rpm.RPMTAG_NAME])
typos = self.spellchecker.spell_check(description, '%description -l {}', lang, pkgname, ignored_words)
typos = self.spellchecker.spell_check(description, '%description -l {}', lang, pkg.name, ignored_words)
for typo in typos.items():
self.output.add_info('E', pkg, 'spelling-error', typo)
for i in description.splitlines():
Expand All @@ -172,8 +171,7 @@ def check_summary(self, pkg, lang, ignored_words):
summary = byte_to_string(summary)
self._unexpanded_macros(pkg, 'Summary(%s)' % lang, summary)
if self.spellcheck:
pkgname = byte_to_string(pkg.header[rpm.RPMTAG_NAME])
typos = self.spellchecker.spell_check(summary, 'Summary({})', lang, pkgname, ignored_words)
typos = self.spellchecker.spell_check(summary, 'Summary({})', lang, pkg.name, ignored_words)
for typo in typos.items():
self.output.add_info('E', pkg, 'spelling-error', typo)
if any(nl in summary for nl in ('\n', '\r')):
Expand Down
2 changes: 1 addition & 1 deletion rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ def add_header(self, header):
tagname = k[:-1].upper()
for i in v:
name, flags, version = parse_deps(i)[0]
version = f'{version[0]}:{version[1]}-{version[2]}'
version = versionToString(version)
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
Binary file removed test/binary/unexpanded1-0-0.noarch.rpm
Binary file not shown.
46 changes: 46 additions & 0 deletions test/mockdata/mock_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from Testing import get_tested_mock_package


UnexpandedMacroPackage = get_tested_mock_package(
lazyload=True,
name='unexpanded1',
header={
'requires': [],
'provides': ['/%notreally', 'unexpanded1 = 0-0'],
'suggests': ['/%asdf'],
'conflicts': ['something:%unexpanded_conflicts'],
'enhances': ['/%else'],
'obsoletes': ['something:%unexpanded'],
'recommends': ['/%unxpanded_recommends'],
'supplements': ['/%something'],
'arch': 'noarch',
'name': 'unexpanded1',
'version': '0',
'release': '0',
},
)


SelfPackage = get_tested_mock_package(
lazyload=True,
name='self',
header={
'requires': [
'insserv',
'rpmlib(CompressedFileNames) <= 3.0.4-1',
'rpmlib(FileDigests) <= 4.6.0-1',
'rpmlib(PayloadFilesHavePrefix) <= 4.0-1',
'rpmlib(PayloadIsXz) <= 5.2-1',
'xinetd',
],
'provides': [
'self',
'self = 0-0',
'self(x86-64) = 0-0',
],
'arch': 'x86_64',
'name': 'self',
'version': '0',
'release': '0',
},
)
16 changes: 10 additions & 6 deletions test/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from mockdata.mock_tags import (
SelfPackage,
UnexpandedMacroPackage,
)
import pytest
from rpmlint.checks.TagsCheck import TagsCheck
from rpmlint.filter import Filter
Expand Down Expand Up @@ -28,10 +32,10 @@ def test(tagscheck):
yield test


@pytest.mark.parametrize('package', ['binary/unexpanded1'])
def test_unexpanded_macros(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [UnexpandedMacroPackage])
def test_unexpanded_macros(package, tagscheck):
output, test = tagscheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'unexpanded-macro Recommends' in out
assert 'unexpanded-macro Provides' in out
Expand All @@ -41,10 +45,10 @@ def test_unexpanded_macros(tmp_path, package, tagscheck):
assert 'unexpanded-macro Enhances' in out


@pytest.mark.parametrize('package', ['binary/self'])
def test_self_provides(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [SelfPackage])
def test_self_provides(package, tagscheck):
output, test = tagscheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: useless-provides self' in out

Expand Down

0 comments on commit 1328572

Please sign in to comment.