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 10, 2024
1 parent 2afb620 commit b72e24b
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 27 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
4 changes: 3 additions & 1 deletion test/Testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _fake_pkg(self):
self._lazy_name)
return self._lazy_pkg

def clone(self, files=None, header=None, name=None):
def clone(self, files=None, header=None, name=None, extend=False):
"""
Copies this LazyMock modifying some properties
"""
Expand All @@ -91,6 +91,8 @@ def clone(self, files=None, header=None, name=None):
files = self._lazy_files
if header is None:
header = self._lazy_header
elif extend:
header = self._lazy_header | header
if name is None:
name = self._lazy_name

Expand Down
Binary file removed test/binary/foo-devel-0-0.x86_64.rpm
Binary file not shown.
Binary file removed test/binary/fuse-common-3.10.2-5.el8.x86_64.rpm
Binary file not shown.
Binary file removed test/binary/invalid-exception-0-0.x86_64.rpm
Binary file not shown.
Binary file removed test/binary/missingprovides-devel-0-0.x86_64.rpm
Binary file not shown.
Binary file removed test/binary/unexpanded1-0-0.noarch.rpm
Binary file not shown.
Binary file removed test/binary/valid-exception-0-0.x86_64.rpm
Binary file not shown.
145 changes: 145 additions & 0 deletions test/mockdata/mock_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import rpm

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',
},
)


FuseCommonPackage = get_tested_mock_package(
lazyload=True,
name='fuse-common',
files={
'etc/fuse.conf': {
'content': '# mount_max = 1000\nuser_allow_other\n',
'flags': rpm.RPMFILE_NOREPLACE | rpm.RPMFILE_CONFIG,
},
},
header={
'requires': [
'config(fuse-common) = 3.10.2-5.el8',
'rpmlib(CompressedFileNames) <= 3.0.4-1',
'rpmlib(FileDigests) <= 4.6.0-1',
'rpmlib(PayloadFilesHavePrefix) <= 4.0-1',
'rpmlib(PayloadIsXz) <= 5.2-1',
],
'provides': [
'config(fuse-common) = 3.10.2-5.el8',
'fuse-common = 3.10.2-5.el8',
'fuse-common = 3.2.1',
'fuse-common = 3.3.0',
'fuse-common(x86-64) = 3.10.2-5.el8',
],
'arch': 'x86_64',
'name': 'fuse-common',
'version': '3.10.2',
'release': '5.el8',
},
)


FooDevelPackage = get_tested_mock_package(
lazyload=True,
name='foo-devel',
header={
'requires': [],
'provides': [],
'arch': 'x86_64',
'name': 'foo-devel',
'version': '0',
'release': '0',
'group': 'Games',
'license': 'GPL-2.0+',
'url': 'http://www.opensuse.org/',
'buildhost': 'marxinbox.suse.cz',
'summary': 'Lorem ipsum',
'description': """Lorem ipsum dolor sit amet, consectetur adipisici elit, sed
eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquid ex ea commodi consequat. Quis aute iure reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
""",
'changelogname': ['[email protected]'],
'changelogtime': [1303128000],
'changelogtext': ['dummy'],
},
)


MissingProvidesPackage = get_tested_mock_package(
lazyload=True,
name='missingprovides-devel',
files=['/usr/lib64/pkgconfig/libparted.pc'],
header={
'requires': [],
'provides': [],
'arch': 'x86_64',
'name': 'missingprovides-devel',
'version': '0',
'release': '0',
},
)


InvalidExceptionPackage = MissingProvidesPackage.clone(
extend=True,
name='invalid-exception',
header={
'name': 'invalid-exception',
'license': 'GPL-2.0+ WITH sparta',
},
)


ValidExceptionPackage = InvalidExceptionPackage.clone(
extend=True,
name='valid-exception',
header={
'name': 'valid-exception',
'license': 'GPL-2.0+ WITH 389-exception',
},
)
51 changes: 30 additions & 21 deletions test/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
from mockdata.mock_tags import (
FooDevelPackage,
FuseCommonPackage,
InvalidExceptionPackage,
MissingProvidesPackage,
SelfPackage,
UnexpandedMacroPackage,
ValidExceptionPackage,
)
import pytest
from rpmlint.checks.TagsCheck import TagsCheck
from rpmlint.filter import Filter
Expand Down Expand Up @@ -28,10 +37,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,53 +50,53 @@ 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


@pytest.mark.parametrize('package', ['binary/fuse-common'])
def test_useless_provides_only_versions(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [FuseCommonPackage])
def test_useless_provides_only_versions(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' not in out
assert 'E: useless-provides fuse-common' not in out


@pytest.mark.parametrize('package', ['binary/foo-devel'])
def test_development_package(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [FooDevelPackage])
def test_development_package(package, tagscheck):
output, test = tagscheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'W: devel-package-with-non-devel-group Games' in out


@pytest.mark.parametrize('package', ['binary/missingprovides'])
def test_missing_provides(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [MissingProvidesPackage])
def test_missing_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: no-pkg-config-provides' in out


@pytest.mark.parametrize('package', ['binary/invalid-exception'])
def test_invalid_license_exception(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [InvalidExceptionPackage])
def test_invalid_license_exception(package, tagscheck):
output, test = tagscheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'W: invalid-license-exception sparta' in out


@pytest.mark.parametrize('package', ['binary/valid-exception'])
@pytest.mark.parametrize('package', [ValidExceptionPackage])
def test_valid_license_exception(tmp_path, package, tagscheck):
CONFIG.info = True
CONFIG.configuration['ValidLicenseExceptions'] = ['389-exception']
output = Filter(CONFIG)
test = TagsCheck(CONFIG, output)
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'W: invalid-license-exception' not in out

Expand Down

0 comments on commit b72e24b

Please sign in to comment.