Skip to content

Commit

Permalink
Merge branch 'main' into opensuse
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Oct 9, 2023
2 parents 4b34bab + 401cf4e commit 2f8a35d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 37 deletions.
2 changes: 1 addition & 1 deletion rpmlint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, options):
self.options = options
self.packages_checked = 0
self.specfiles_checked = 0
self.check_duration = defaultdict(lambda: 0)
self.check_duration = defaultdict(int)
if options['config']:
self.config = Config(options['config'])
else:
Expand Down
58 changes: 27 additions & 31 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,17 @@ def check_signature(self):

# Class to provide an API to a 'fake' package, eg. for specfile-only checks
class FakePkg(AbstractPkg):
_autoheaders = [
'requires',
'conflicts',
'provides',
'obsoletes',
'recommends',
'suggests',
'enhances',
'supplements',
]

def __init__(self, name, is_source=False):
self.name = str(name)
self.arch = None
Expand All @@ -779,32 +790,13 @@ def __init__(self, name, is_source=False):
self.ghost_files = {}

# header is a dictionary to mock rpm metadata
self.header = {
rpm.RPMTAG_REQUIRENAME: [],
rpm.RPMTAG_REQUIREFLAGS: [],
rpm.RPMTAG_REQUIREVERSION: [],
rpm.RPMTAG_CONFLICTNAME: '',
rpm.RPMTAG_CONFLICTFLAGS: '',
rpm.RPMTAG_CONFLICTVERSION: '',
rpm.RPMTAG_PROVIDENAME: '',
rpm.RPMTAG_PROVIDEFLAGS: '',
rpm.RPMTAG_PROVIDEVERSION: '',
rpm.RPMTAG_OBSOLETENAME: '',
rpm.RPMTAG_OBSOLETEFLAGS: '',
rpm.RPMTAG_OBSOLETEVERSION: '',
rpm.RPMTAG_RECOMMENDNAME: '',
rpm.RPMTAG_RECOMMENDFLAGS: '',
rpm.RPMTAG_RECOMMENDVERSION: '',
rpm.RPMTAG_SUGGESTNAME: '',
rpm.RPMTAG_SUGGESTFLAGS: '',
rpm.RPMTAG_SUGGESTVERSION: '',
rpm.RPMTAG_ENHANCENAME: '',
rpm.RPMTAG_ENHANCEFLAGS: '',
rpm.RPMTAG_ENHANCEVERSION: '',
rpm.RPMTAG_SUPPLEMENTNAME: '',
rpm.RPMTAG_SUPPLEMENTFLAGS: '',
rpm.RPMTAG_SUPPLEMENTVERSION: '',
}
self.header = {}
for i in self._autoheaders:
# the header name wihtout the ending 's'
tagname = i[:-1].upper()
self.header[getattr(rpm, f'RPMTAG_{tagname}NAME')] = []
self.header[getattr(rpm, f'RPMTAG_{tagname}FLAGS')] = []
self.header[getattr(rpm, f'RPMTAG_{tagname}VERSION')] = []

def add_file(self, path, name):
pkgfile = PkgFile(name)
Expand Down Expand Up @@ -895,11 +887,15 @@ def initiate_files_base_data(self):

def add_header(self, header):
for k, v in header.items():
if k == 'requires':
for req in v:
self.header[rpm.RPMTAG_REQUIRENAME].append(req)
self.header[rpm.RPMTAG_REQUIREFLAGS].append(0)
self.header[rpm.RPMTAG_REQUIREVERSION].append('1.0')
if k in self._autoheaders:
# the header name wihtout the ending 's'
tagname = k[:-1].upper()
for i in v:
name, flags, version = parse_deps(i)[0]
version = f'{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)
continue

key = getattr(rpm, f'RPMTAG_{k}'.upper())
Expand Down
Binary file removed test/binary/packageand-0-0.x86_64.rpm
Binary file not shown.
62 changes: 57 additions & 5 deletions test/test_zypp_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rpmlint.checks.ZyppSyntaxCheck import ZyppSyntaxCheck
from rpmlint.filter import Filter

from Testing import CONFIG, get_tested_package
from Testing import CONFIG, get_tested_mock_package


@pytest.fixture(scope='function', autouse=True)
Expand All @@ -13,13 +13,65 @@ def zyppsyntaxcheck():
return output, test


@pytest.mark.parametrize('package', ['binary/packageand'])
def test_packageand(tmp_path, package, zyppsyntaxcheck):
output, test = zyppsyntaxcheck
test.check(get_tested_package(package, tmp_path))
@pytest.fixture
def output(zyppsyntaxcheck):
output, _test = zyppsyntaxcheck
yield output


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


@pytest.mark.parametrize('package', [get_tested_mock_package(
header={
'requires': [
'rpmlib(CompressedFileNames) <= 3.0.4-1',
'rpmlib(FileDigests) <= 4.6.0-1',
'rpmlib(PayloadFilesHavePrefix) <= 4.0-1',
'rpmlib(PayloadIsXz) <= 5.2-1',
'rpmlib(RichDependencies) <= 4.12.0-1',
],
'supplements': ['packageand(c:d)'],
'recommends': ['packageand(a:b)'],
'suggests': ['(a and b)'],
'conflicts': [
'bee',
'otherproviders(yast2_theme)',
],
},
)])
def test_packageand(package, test, output):
test.check(package)
out = output.print_results(output.results)
assert 'suse-zypp-packageand packageand(c:d)' in out
assert 'suse-zypp-packageand packageand(a:b)' in out
assert '(a and b)' not in out
assert 'bee' not in out
assert 'suse-zypp-otherproviders otherproviders(yast2_theme)' in out


@pytest.mark.parametrize('package', [get_tested_mock_package(
header={
'requires': [
'rpmlib(CompressedFileNames) <= 3.0.4-1',
'rpmlib(FileDigests) <= 4.6.0-1',
'rpmlib(PayloadFilesHavePrefix) <= 4.0-1',
'rpmlib(PayloadIsXz) <= 5.2-1',
'rpmlib(RichDependencies) <= 4.12.0-1',
],
'supplements': ['(c and d)'],
'recommends': ['b'],
'suggests': ['(a and b)'],
'conflicts': [
'bee',
],
},
)])
def test_packageand_ok(package, test, output):
test.check(package)
out = output.print_results(output.results)
assert 'suse-zypp-packageand' not in out
assert 'suse-zypp-otherproviders' not in out

0 comments on commit 2f8a35d

Please sign in to comment.