Skip to content

Commit

Permalink
Merge pull request #1285 from rpm-software-management/clean-test-suite
Browse files Browse the repository at this point in the history
Clean test suite
  • Loading branch information
danigm authored Oct 30, 2024
2 parents fd7ba4e + b72e24b commit 25c5792
Show file tree
Hide file tree
Showing 91 changed files with 4,196 additions and 981 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
- run: pytest
- run: flake8
- run: /github/home/.local/bin/ruff check .
- run: find . -name '*.py' | xargs /github/home/.local/bin/pyupgrade --py38-plus
- run: find . -not -path "./test/files/*" -name '*.py' | xargs /github/home/.local/bin/pyupgrade --py38-plus
- run: python3 -m cProfile -o profile.stats lint.py -V test/source/* test/binary/* > /dev/null
- run: python3 test/dump_stats.py profile.stats
- name: Collect the coveralls report
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ rpmlint = ["configdefaults.toml"]
"rpmlint.descriptions" = ["*.toml"]

[tool.ruff]
exclude = ["test/files"]

lint.ignore = ["E501"]
13 changes: 4 additions & 9 deletions rpmlint/checks/DocCheck.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from pathlib import Path
import stat

import rpm
from rpmlint.checks.AbstractCheck import AbstractCheck
from rpmlint.helpers import byte_to_string


class DocCheck(AbstractCheck):
Expand Down Expand Up @@ -60,15 +58,12 @@ def _check_doc_file_dependencies(self, pkg):
core_reqs = {} # dependencies of non-doc files
doc_reqs = {} # dependencies of doc files

for dep in rpm.ds(pkg.header, 'requires'):
# skip deps which were found by find-requires
if dep.Flags() & rpm.RPMSENSE_FIND_REQUIRES != 0:
continue
core_reqs[dep.N()] = []
for dep in pkg.get_core_reqs():
core_reqs[dep] = []

# register things which are provided by the package
for i in pkg.header[rpm.RPMTAG_PROVIDES]:
core_reqs[byte_to_string(i)] = []
for i in pkg.provides:
core_reqs[i] = []
for i in files:
core_reqs[i] = []

Expand Down
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
40 changes: 30 additions & 10 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,15 @@ def read_with_mmap(self, filename):
except Exception:
return ''

def grep(self, regex, filename):
"""Grep regex from a file, return first matching line number (starting with 1)."""
data = self.read_with_mmap(filename)
match = regex.search(data)
if match:
return data.count('\n', 0, match.start()) + 1
else:
return None


class Pkg(AbstractPkg):
_magic_from_compressed_re = re.compile(r'\([^)]+\s+compressed\s+data\b')
Expand Down Expand Up @@ -640,15 +649,6 @@ def cleanup(self):
if self.extracted and self.dirname:
self.__tmpdir.cleanup()

def grep(self, regex, filename):
"""Grep regex from a file, return first matching line number (starting with 1)."""
data = self.read_with_mmap(filename)
match = regex.search(data)
if match:
return data.count('\n', 0, match.start()) + 1
else:
return None

def langtag(self, tag, lang):
"""Get value of tag in the given language."""
# LANGUAGE trumps other env vars per GNU gettext docs, see also #166
Expand Down Expand Up @@ -726,6 +726,21 @@ def readlink(self, pkgfile):
result = self.files.get(linkpath)
return result

def get_core_reqs(self):
"""
Return the list of dependencies that are not found by find-requires
withouth the flag RPM
"""
core_reqs = []

for dep in rpm.ds(self.header, 'requires'):
# skip deps which were found by find-requires
if dep.Flags() & rpm.RPMSENSE_FIND_REQUIRES != 0:
continue
core_reqs.append(dep.N())

return core_reqs


def get_installed_pkgs(name):
"""Get list of installed package objects by name."""
Expand Down Expand Up @@ -883,6 +898,7 @@ def add_dir(self, path, metadata=None):

path = os.path.join(self.dir_name(), path.lstrip('/'))
os.makedirs(Path(path), exist_ok=True)
pkgdir.inode = os.stat(Path(path)).st_ino

pkgdir.path = path
self.files[name] = pkgdir
Expand Down Expand Up @@ -946,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 Expand Up @@ -998,6 +1014,10 @@ def cleanup(self):
if self.dirname:
self.__tmpdir.cleanup()

def get_core_reqs(self):
core_reqs = []
return core_reqs

# access the tags like an array
def __getitem__(self, key):
return self.header.get(key, None)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ test=pytest
ignore = E122,E501,W504
import-order-style = google
application-import-names = Testing

exclude = test/files/*
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/doc-file-dependency-1.0.0-0.noarch.rpm
Binary file not shown.
Binary file removed test/binary/fPing-4.2~dev-1.2~.3.x86_64.rpm
Binary file not shown.
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/install-file-in-docs-1.0-0.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 not shown.
Binary file removed test/binary/logrotate-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/mydoc-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.
14 changes: 14 additions & 0 deletions test/files/logrotate/logrotate.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/var/log/myapp/*.log {
su appuser appuser
weekly
rotate 4
compress

delaycompress
missingok
create 644 appuser appuser
}

/var/log/myapp/*.log {
su appuser2 appuser2
}
12 changes: 12 additions & 0 deletions test/files/logrotate/logrotate2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/var/log/myapp/*.log {
su appuser2 appuser2
}

/tmp/foo/my.log {
# comment
su appuser2 appuser2
}

/tmp/foo2/my.log {
su appuser2 appuser2
}
Binary file added test/files/python3-power/__init__.cpython-33.pyc
Binary file not shown.
Binary file added test/files/python3-power/__init__.cpython-33.pyo
Binary file not shown.
39 changes: 39 additions & 0 deletions test/files/python3-power/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# coding=utf-8
"""
Provides crossplatform checking of current power source, battery warning level and battery time remaining estimate.
Allows you to add observer for power notifications if platform supports it.
Usage:
from power import PowerManagement, PowerManagementObserver # Automatically imports platform-specific implementation
class Observer(PowerManagementObserver):
def on_power_sources_change(self, power_management):
print "Power sources did change."
def on_time_remaining_change(self, power_management):
print "Time remaining did change."
# class Observer(object):
# ...
# PowerManagementObserver.register(Observer)
"""
__author__ = '[email protected]'
__version__ = '1.1'

from sys import platform
from power.common import *


try:
if platform.startswith('darwin'):
from power.darwin import PowerManagement
elif platform.startswith('win32'):
from power.win32 import PowerManagement
elif platform.startswith('linux'):
from power.linux import PowerManagement
else:
raise RuntimeError("{platform} is not supported.".format(platform=platform))
except RuntimeError as e:
import warnings
warnings.warn("Unable to load PowerManagement for {platform}. No-op PowerManagement class is used: {error}".format(error=str(e), platform=platform))
from power.common import PowerManagementNoop as PowerManagement
Binary file added test/files/python3-power/common.cpython-33.pyc
Binary file not shown.
Binary file added test/files/python3-power/common.cpython-33.pyo
Binary file not shown.
Loading

0 comments on commit 25c5792

Please sign in to comment.