Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test framework #1126

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,22 @@ def _gather_dep_info(self):
return (_requires, _prereq, _provides, _conflicts, _obsoletes, _recommends,
_suggests, _enhances, _supplements)

def scriptprog(self, which):
"""
Get the specified script interpreter as a string.
Depending on rpm-python version, the string may or may not include
interpreter arguments, if any.
"""
if which is None:
return ''
prog = self[which]
if prog is None:
prog = ''
elif isinstance(prog, (list, tuple)):
# http://rpm.org/ticket/847#comment:2
prog = ''.join(prog)
return prog

def __enter__(self):
return self

Expand Down Expand Up @@ -704,22 +720,6 @@ def check_versioned_dep(self, name, version):
return True
return False

def scriptprog(self, which):
"""
Get the specified script interpreter as a string.
Depending on rpm-python version, the string may or may not include
interpreter arguments, if any.
"""
if which is None:
return ''
prog = self[which]
if prog is None:
prog = ''
elif isinstance(prog, (list, tuple)):
# http://rpm.org/ticket/847#comment:2
prog = ''.join(prog)
return prog


def get_installed_pkgs(name):
"""Get list of installed package objects by name."""
Expand Down Expand Up @@ -796,6 +796,7 @@ def __init__(self, name, is_source=False):
self.header[getattr(rpm, f'RPMTAG_{tagname}NAME')] = []
self.header[getattr(rpm, f'RPMTAG_{tagname}FLAGS')] = []
self.header[getattr(rpm, f'RPMTAG_{tagname}VERSION')] = []
self.header[rpm.RPMTAG_FILENAMES] = []

def add_file(self, path, name):
pkgfile = PkgFile(name)
Expand All @@ -816,7 +817,11 @@ def _mock_file(self, path, attrs):
elif 'content' in attrs:
content = attrs['content']

self.add_file_with_content(path, content, metadata=metadata)
if 'linkto' in attrs:
self.add_symlink_to(path, attrs['linkto'])
else:
self.add_file_with_content(path, content, metadata=metadata)
self.header[rpm.RPMTAG_FILENAMES].append(path)

if 'content-path' in attrs:
content.close()
Expand Down Expand Up @@ -852,6 +857,8 @@ def add_file_with_content(self, name, content, metadata=None, **flags):
pkg_file = PkgFile(name)
pkg_file.path = path
pkg_file.mode = stat.S_IFREG | 0o0644
pkg_file.user = 'root'
pkg_file.group = 'root'
self.files[name] = pkg_file

# create files in filesystem
Expand Down Expand Up @@ -915,6 +922,8 @@ def add_symlink_to(self, name, target):
pkg_file = PkgFile(name)
pkg_file.mode = stat.S_IFLNK
pkg_file.linkto = target
pkg_file.user = 'root'
pkg_file.group = 'root'
self.files[name] = pkg_file

def readlink(self, pkgfile):
Expand All @@ -937,3 +946,7 @@ def md5_checksum(self, file_name):
def cleanup(self):
if self.dirname:
self.__tmpdir.cleanup()

# access the tags like an array
def __getitem__(self, key):
return self.header.get(key, None)