Skip to content

Commit 2edd59c

Browse files
committed
Run only once the validate_filters per call
When the cli tool is called with "-i" option in combination with a list of spec/rpm files it runs the validate_installed_packages and also the validate_files. These methods check the list of packages to lint to just run post check function and validate used filters in rpmlintrc. This patch makes sure to do not call the post check and validation twice, checking if there are also "files" during the validate_installed_packages. That way the is_last will be only true in the latter call inside validate_files. Fix #1368
1 parent 153653e commit 2edd59c

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

rpmlint/lint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def _run(self):
6767
if self.options['explain']:
6868
self.print_explanation(self.options['explain'], self.config)
6969
return retcode
70+
7071
# if there are installed arguments just load them up as extra
7172
# items to the rpmfile option
7273
if self.options['installed']:
@@ -222,8 +223,10 @@ def _print_header(self):
222223
print('')
223224

224225
def validate_installed_packages(self, packages):
226+
# Do not run post checks if there are also plain rpm/spec files to validate
227+
run_post_checks = not bool(self.options['rpmfile'])
225228
for pkg in packages:
226-
self.run_checks(pkg, pkg == packages[-1])
229+
self.run_checks(pkg, run_post_checks and pkg == packages[-1])
227230
self.reset_checks()
228231

229232
def validate_files(self, files):

test/test_cli.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from pathlib import PosixPath
2+
from unittest.mock import Mock
23

34
import pytest
45
from rpmlint.cli import process_lint_args
56
from rpmlint.config import Config
67
from rpmlint.lint import Lint
78

8-
from Testing import HAS_CHECKBASHISMS, HAS_DASH
9+
from Testing import HAS_CHECKBASHISMS, HAS_DASH, HAS_RPMDB
910

1011

1112
@pytest.mark.parametrize('test_arguments', [['-c', 'rpmlint/configs/thisdoesntexist.toml']])
@@ -92,3 +93,18 @@ def test_reset_check():
9293
lint.run()
9394
out = lint.output.print_results(lint.output.results, lint.config)
9495
assert 'more-than-one-%changelog-section' not in out
96+
97+
98+
@pytest.mark.skipif(not HAS_RPMDB, reason='No RPM database present')
99+
@pytest.mark.parametrize('args', [
100+
['test/spec/SpecCheck2.spec', 'test/spec/SpecCheck3.spec'],
101+
['-i', 'rpm', 'glibc'],
102+
['test/spec/SpecCheck2.spec', '-i', 'rpm'],
103+
['test/spec/SpecCheck2.spec', 'test/spec/SpecCheck3.spec', '-i', 'rpm', 'glibc'],
104+
])
105+
def test_validate_filters(args):
106+
options = process_lint_args(args)
107+
lint = Lint(options)
108+
lint.output.validate_filters = Mock(wraps=lint.output.validate_filters)
109+
lint.run()
110+
lint.output.validate_filters.assert_called_once()

0 commit comments

Comments
 (0)