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

Implement a proper testing framework (GSoC23) #1079

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7db587d
Tried to mock a test: test_binary.py
afrid18 Jun 1, 2023
f3b18d8
As suggested, I have made changes to to get_tested_mock_package to us…
afrid18 Jun 2, 2023
f61411d
changes as suggested
afrid18 Jun 2, 2023
c58c7f5
Update main.yml for GitHub Actions on branch GSoC23
afrid18 Jun 7, 2023
535b834
No need to import FakePkg
afrid18 Jun 7, 2023
7556cd8
Merge branch 'GSoC23' of https://github.com/afrid18/rpmlint into GSoC23
afrid18 Jun 7, 2023
ec6486c
Flake8 suggestion
afrid18 Jun 7, 2023
9bc5a00
flake8: fixed flake8 warnings
afrid18 Jun 8, 2023
8c55e5f
Merge branch 'rpm-software-management:main' into GSoC23
afrid18 Jun 8, 2023
b0912c4
test: mocked test_python_doc_in_package
afrid18 Jun 14, 2023
4e215e3
test: modified test_python_doc_module_in_package with mocking
afrid18 Jun 15, 2023
a0c5579
test: Remove binary RPM packages with Python docs and docs modules
afrid18 Jun 15, 2023
db63a42
tests: Refactored Python package tests using mocking for docs, src, a…
afrid18 Jun 19, 2023
6f3996e
test: distutil test for python packages is mocked
afrid18 Jun 25, 2023
94e71ab
modified if condition in add_file_with_content function
afrid18 Jun 26, 2023
53afa1c
Merge branch 'rpm-software-management:main' into GSoC23
afrid18 Jun 29, 2023
3031842
test: mocked test for python dependencies from metadata
afrid18 Jul 1, 2023
0f65484
test: mocked test for python dependencies from requires.txt
afrid18 Jul 1, 2023
a4fff79
test: mocked complex dependencies from metadata
afrid18 Jul 3, 2023
1187239
test: mocked test for metadata check in python package
afrid18 Jul 3, 2023
d3d5f18
test: mocked another metadata test that supports complex dependency s…
afrid18 Jul 3, 2023
7588dd2
test: removed binaries used for testing python package dependencies f…
afrid18 Jul 10, 2023
bf38b06
test: mocked test_python_dependencies_missing; also removed its two r…
afrid18 Jul 10, 2023
751d8aa
copied _gather_deps_info and _gather_aux functions to FakePkg class
afrid18 Jul 3, 2023
afc08c3
test: mocked python dependencies leftovers; and removed 2 binaries
afrid18 Jul 10, 2023
ee0d6a5
CI: removed GSoC23 branch for CI workflow
afrid18 Jul 13, 2023
04be19a
moved _gather_dep_info and _gather_aux to AbstractPkg
afrid18 Jul 13, 2023
2494367
Refactored FakePkg with a new helper method for cleaner code in get_t…
afrid18 Jul 13, 2023
ee2fe52
test: mocked test_duplicates tests
afrid18 Aug 3, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [main, opensuse]
branches: [main, opensuse, GSoC23]
danigm marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
branches: [main, opensuse]

Expand Down
77 changes: 66 additions & 11 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@


# Class to provide an API to a 'fake' package, eg. for specfile-only checks
class FakePkg(AbstractPkg):
class FakePkg(Pkg):
Fixed Show fixed Hide fixed
def __init__(self, name, is_source=False):
self.name = str(name)
self.arch = None
Expand All @@ -759,26 +759,81 @@
self.files = {}
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: '',
}

def add_file(self, path, name):
pkgfile = PkgFile(name)
pkgfile.path = path
self.files[name] = pkgfile
return pkgfile

def add_file_with_content(self, name, content, **flags):
def add_dir(self, path):
pkgdir = PkgFile(path)
pkgdir.magic = 'directory'
pkgdir.path = path
self.files[path] = pkgdir
return pkgdir

def add_file_with_content(self, name, content, real_files=False, **flags):
"""
Add file to the FakePkg and fill the file with provided
string content.
"""
basename = name.replace(os.path.sep, '_')
path = os.path.join(self.dir_name(), basename)
with open(path, 'w') as out:
out.write(content)
pkg_file = PkgFile(name)
pkg_file.path = path
for key, value in flags.items():
setattr(pkg_file, key, value)
self.files[name] = pkg_file
path = os.path.join(self.dir_name(), name.lstrip('/'))
pkg_file = PkgFile(name)
pkg_file.path = path
for key, value in flags.items():
setattr(pkg_file, key, value)
self.files[name] = pkg_file

if real_files:
os.makedirs(Path(path).parent, exist_ok=True)
with open(Path(path), 'w') as out:
out.write(content)

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')
continue

key = getattr(rpm, f'RPMTAG_{k}'.upper())
self.header[key] = v

(self.requires, self.prereq, self.provides, self.conflicts,
self.obsoletes, self.recommends, self.suggests, self.enhances,
self.supplements) = self._gather_dep_info()

self.req_names = [x[0] for x in self.requires + self.prereq]

def add_symlink_to(self, name, target):
"""
Expand Down
15 changes: 14 additions & 1 deletion test/Testing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import glob
import os
from pathlib import Path
from pathlib import Path, PurePath
import platform
import re
import shutil
Expand Down Expand Up @@ -60,3 +60,16 @@ def get_tested_spec_package(name):
candidates = list(get_tested_path(name).parent.glob(filename))
assert len(candidates) == 1
return FakePkg(candidates[0])


def get_tested_mock_package(files=None, real_files=None, header=None):
mockPkg = FakePkg('mockPkg')
if files is not None:
for path, file in files.items():
if file.get('create_dirs'):
for i in PurePath(path).parents[:file.get('include_dirs', -1)]:
mockPkg.add_dir(str(i))
mockPkg.add_file_with_content(path, file.get('content'), real_files=real_files)
danigm marked this conversation as resolved.
Show resolved Hide resolved
if header is not None:
mockPkg.add_header(header)
return mockPkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 10 additions & 9 deletions test/test_binaries.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pytest
from rpmlint.checks.BinariesCheck import BinariesCheck
from rpmlint.filter import Filter
from rpmlint.pkg import FakePkg

from Testing import CONFIG, Config, get_tested_package, IS_X86_64, TEST_CONFIG
from Testing import CONFIG, Config, get_tested_mock_package, get_tested_package, IS_X86_64, TEST_CONFIG


@pytest.fixture(scope='function', autouse=True)
Expand Down Expand Up @@ -280,11 +279,13 @@ def test_patchable_function_entry_archive(tmp_path, package, binariescheck):
assert 'E: patchable-function-entry-in-archive /usr/lib64/libhello.a' in out


def test_systemd_unit_file(binariescheck):
@pytest.mark.parametrize('package', [
get_tested_mock_package(files={
'/usr/lib/systemd/system/yast-timesync.service': {'content': ''}
})
])
def test_systemd_unit_file(package, binariescheck):
output, test = binariescheck
with FakePkg('fake') as pkg:
pkg.add_file_with_content('/usr/lib/systemd/system/yast-timesync.service', '')
output, test = binariescheck
test.check(pkg)
out = output.print_results(output.results)
assert 'only-non-binary-in-usr-lib' not in out
test.check(package)
out = output.print_results(output.results)
assert 'only-non-binary-in-usr-lib' not in out
Loading
Loading