Skip to content

Commit

Permalink
Merge pull request #936 from danigm/main
Browse files Browse the repository at this point in the history
Add python-setup-test check to SpecCheck
  • Loading branch information
marxin authored Sep 29, 2022
2 parents bb301e0 + c8b87d6 commit 9efe21c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rpmlint/checks/SpecCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def re_tag_compile(tag):
pkgname_regex = re.compile(r'\s+(?:-n\s+)?(\S+)')
tarball_regex = re.compile(r'\.(?:t(?:ar|[glx]z|bz2?)|zip)\b', re.IGNORECASE)

python_setup_test_regex = re.compile(r'^[^#]*(setup.py test)')

UNICODE_NBSP = u'\xa0'


Expand Down Expand Up @@ -490,6 +492,10 @@ def check_spec(self, pkg):
if len(res.group(0)) % 2:
self.output.add_info('W', pkg, 'macro-in-comment', match)

# Test if the "python setup.py test" deprecated subcommand is used
if current_section == 'check' and python_setup_test_regex.search(line):
self.output.add_info('W', pkg, 'python-setup-test', line[:-1])

# Last line read is not useful after this point
pkg.current_linenum = None

Expand Down
4 changes: 4 additions & 0 deletions rpmlint/descriptions/SpecCheck.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,7 @@ the sign that someone didn't check if a patch is still needed and do not want
to rediff it. It is usually better to rediff the patch and try to send it
upstream.
"""
python-setup-test="""
The python setup.py test subcommand is deprecated and should be replaced with a
modern testing tool like %pytest or %pyunittest discover -v.
"""
34 changes: 34 additions & 0 deletions test/spec/python-setup-test.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Name: python-setup-test
Version: 1.0
Release: 0
Summary: python-setup-test warning
License: MIT
URL: https://www.example.com
Source: Source.tar.gz
BuildRequires: gcc
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

%description
A test specfile with python setup.py test that is deprecated.

%prep
%setup -q

%build
%configure
%make_build

%install
%make_install

%check
%python_exec setup.py test

%post
%postun

%files
%license COPYING
%doc ChangeLog README

%changelog
10 changes: 10 additions & 0 deletions test/test_speccheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,13 @@ def test_check_invalid_url_not_applied(package, speccheck):
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'W: invalid-url' not in out


@pytest.mark.parametrize('package', ['spec/python-setup-test'])
def test_python_setup_test(package, speccheck):
"""Test if specfile has deprecated use of 'setup.py test'."""
output, test = speccheck
pkg = get_tested_spec_package(package)
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'W: python-setup-test' in out

0 comments on commit 9efe21c

Please sign in to comment.