Skip to content

Commit

Permalink
Merge pull request #1248 from i12momal/rama5
Browse files Browse the repository at this point in the history
Replace bin in easy tests
  • Loading branch information
danigm authored Aug 7, 2024
2 parents f6ad983 + bb03c10 commit de9b4d2
Show file tree
Hide file tree
Showing 10 changed files with 1,358 additions and 23 deletions.
16 changes: 8 additions & 8 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,14 @@ def __enter__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
self.cleanup()

def read_with_mmap(self, filename):
"""Mmap a file, return it's content decoded."""
try:
with open(Path(self.dir_name() or '/', filename.lstrip('/'))) as in_file:
return mmap.mmap(in_file.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ).read().decode()
except Exception:
return ''


class Pkg(AbstractPkg):
_magic_from_compressed_re = re.compile(r'\([^)]+\s+compressed\s+data\b')
Expand Down Expand Up @@ -630,14 +638,6 @@ def grep(self, regex, filename):
else:
return None

def read_with_mmap(self, filename):
"""Mmap a file, return it's content decoded."""
try:
with open(Path(self.dir_name() or '/', filename.lstrip('/'))) as in_file:
return mmap.mmap(in_file.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ).read().decode()
except Exception:
return ''

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
426 changes: 426 additions & 0 deletions test/files/broken-xml.metainfo.xml

Large diffs are not rendered by default.

426 changes: 426 additions & 0 deletions test/files/broken.appdata.xml

Large diffs are not rendered by default.

427 changes: 427 additions & 0 deletions test/files/terminator.appdata.xml

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions test/mockdata/mock_appdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from Testing import get_tested_mock_package

APPDATA = get_tested_mock_package(
files={
'/usr/share/appdata/broken.appdata.xml': {
'content-path': 'files/broken.appdata.xml',
'create_dirs': True},
'/usr/share/appdata/broken-xml.metainfo.xml': {
'content-path': 'files/broken-xml.metainfo.xml',
'create_dirs': True}
})

APPDATA2 = get_tested_mock_package(
files={
'/usr/share/appdata/broken-xml.metainfo.xml': {
'content-path': 'files/broken-xml.metainfo.xml',
'create_dirs': True}
})
6 changes: 6 additions & 0 deletions test/mockdata/mock_build_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from Testing import get_tested_mock_package

BUILDROOT = get_tested_mock_package(
files={
'/bin/trace': {'content': '/home/marxin/rpmbuild/BUILDROOT/buildroot-0-0.x86_64'}
})
29 changes: 29 additions & 0 deletions test/mockdata/mock_dbus_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from Testing import get_tested_mock_package

DBUSPOLICY = get_tested_mock_package(
files={
'/etc/dbus-1/system.d/noxml.conf': {
'content': '',
},
'/etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf': {
'content': """
<busconfig>
<policy user="root">
<allow send_interface="org.freedesktop.NetworkManager.PPP"/>
<allow receive_sender="foo"/>
</policy>
<policy>
<deny send_interface="org.freedesktop.NetworkManager.Settings" send_member="ReloadConnections"/>
</policy>
</busconfig>
""",
},
'/etc/dbus-1/system.d/org.freedesktop.NetworkManager2.conf': {
'content': """
<busconfig>
<policy user="root">
<!-- No allow policies -->
</policy>
</busconfig>
""",
}})
15 changes: 8 additions & 7 deletions test/test_appdata.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from unittest.mock import patch

from mockdata.mock_appdata import APPDATA, APPDATA2
import pytest
from rpmlint.checks.AppDataCheck import AppDataCheck
from rpmlint.filter import Filter

from Testing import CONFIG, get_tested_package, HAS_APPSTREAM_GLIB
from Testing import CONFIG, HAS_APPSTREAM_GLIB


@pytest.fixture(scope='function', autouse=True)
Expand All @@ -16,21 +17,21 @@ def appdatacheck():


@pytest.mark.skipif(not HAS_APPSTREAM_GLIB, reason='Optional dependency appstream-glib not installed')
@pytest.mark.parametrize('package', ['binary/appdata'])
def test_appdata_fail(tmp_path, package, appdatacheck):
@pytest.mark.parametrize('package', [APPDATA])
def test_appdata_fail(package, appdatacheck):
output, test = appdatacheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
# there are two borked packages
assert len(output.results) == 2
assert 'invalid-appdata-file' in out


@pytest.mark.parametrize('package', ['binary/appdata'])
@pytest.mark.parametrize('package', [APPDATA2])
@patch('rpmlint.checks.AppDataCheck.AppDataCheck.cmd', 'command-really-not-found')
def test_appdata_fail_no_checker(tmp_path, package, appdatacheck):
def test_appdata_fail_no_checker(package, appdatacheck):
output, test = appdatacheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
# there is just one borked file as the other is invalid content
# but valid xml
Expand Down
9 changes: 5 additions & 4 deletions test/test_build_root.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from mockdata.mock_build_root import BUILDROOT
import pytest
from rpmlint.checks.BuildRootAndDateCheck import BuildRootAndDateCheck
from rpmlint.filter import Filter

from Testing import CONFIG, get_tested_package
from Testing import CONFIG


@pytest.fixture(scope='function', autouse=True)
Expand All @@ -13,10 +14,10 @@ def buildrootcheck():
return output, test


@pytest.mark.parametrize('package', ['binary/buildroot'])
def test_build_root(tmp_path, package, buildrootcheck):
@pytest.mark.parametrize('package', [BUILDROOT])
def test_build_root(package, buildrootcheck):
output, test = buildrootcheck
test.prepare_regex('/home/marxin/rpmbuild/BUILDROOT/%{NAME}-%{VERSION}-%{RELEASE}.x86_64')
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: file-contains-buildroot /bin/trace' in out
9 changes: 5 additions & 4 deletions test/test_dbus_policy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from mockdata.mock_dbus_policy import DBUSPOLICY
import pytest
from rpmlint.checks.DBusPolicyCheck import DBusPolicyCheck
from rpmlint.filter import Filter

from Testing import CONFIG, get_tested_package
from Testing import CONFIG


@pytest.fixture(scope='function', autouse=True)
Expand All @@ -13,10 +14,10 @@ def dbuspolicycheck():
return output, test


@pytest.mark.parametrize('package', ['binary/dbusrule'])
def test_dbus_policy(tmp_path, package, dbuspolicycheck):
@pytest.mark.parametrize('package', [DBUSPOLICY])
def test_dbus_policy(package, dbuspolicycheck):
output, test = dbuspolicycheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: dbus-parsing-exception raised an exception: no element found: line 1, column 0 /etc/dbus-1/system.d/noxml.conf' in out
assert 'E: dbus-policy-allow-without-destination <allow send_interface="org.freedesktop.NetworkManager.PPP"/>' in out
Expand Down

0 comments on commit de9b4d2

Please sign in to comment.