Skip to content

Commit

Permalink
Merge pull request #1247 from i12momal/rama4
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 de9b4d2 + 96e83b5 commit 2241a48
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 34 deletions.
15 changes: 15 additions & 0 deletions test/files/rpmlint-test.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Desktop Entry]
Name=rpmlint-test
Name[de]=rpmlint-test umlaut äöü
Name[x-test]=xxrpmlint-testxx
MimeType=application/x-rpm;
Exec=rpmlint-test file.file
Icon=chameleon_v_balíku
Type=Application
InitialPreference=5
NoDisplay=false
GenericName=rpmlint testcase
GenericName[x-test]=xxrpmlint testcasexx
Categories=System;PackageManager;
Keywords=software;package;
Keywords[x-test]=xxsoftwarexx;xxpackagexx;
7 changes: 7 additions & 0 deletions test/mockdata/mock_FHS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from Testing import get_tested_mock_package

FHS = get_tested_mock_package(
files={
'/usr/dummy': {'content': ''},
'/var/dummy': {'content': ''},
'/var/local': {'content': ''}})
69 changes: 69 additions & 0 deletions test/mockdata/mock_menuxdg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from Testing import get_tested_mock_package

MENUXDG = get_tested_mock_package(
files={
'/usr/share/applications/somefile.desktop': {'content': """
[DEFAULT]
something = true
[else
"""}
})

MENUXDG1 = get_tested_mock_package(
files={
'/usr/share/applications/rpmlint-test.desktop': {'content': """
[Desktop Entry]
Name=rpmlint-test
Exec=rpmlint-test file.file
Icon=chameleon_v_balíku
Type=Application
GenericName=rpmlint testcase
Categories=Game;Amusement;
"""}
})

MENUXDG2 = get_tested_mock_package(
files={
'/usr/share/applications/rpmlint-test.desktop': {'content': """
[Desktop Entry]
[Desktop Entry]
Name=rpmlint-test
Name=name duplicate
Exec=rpmlint-test file.file
Icon=chameleon_v_balíku
Type=Application
GenericName=rpmlint testcase
Categories=Game;Amusement;
"""}
})

MENUXDG3 = get_tested_mock_package(
files={
'/usr/share/applications/rpmlint-test.desktop': {'content': """
Name=rpmlint-test
[Bad Section]
Name[x-test]=xxrpmlint-testxx
Exec=rpmlint-test file.file
Icon=rpmlint-test
Type=Application
GenericName=rpmlint testcase"""}
})

MENUXDG4 = get_tested_mock_package(
files={
'/usr/share/applications/rpmlint-test.desktop': {
'content-path': 'files/rpmlint-test.desktop',
'create_dirs': True,
}
})

MENUXDG5 = get_tested_mock_package(
files={
'/usr/bin/rpmlint-test',
'/usr/share/applications',
'/usr/share/applications/rpmlint-test.desktop',
'/usr/share/icons/hicolor',
'/usr/share/icons/hicolor/scalable',
'/usr/share/icons/hicolor/scalable/apps',
'/usr/share/icons/hicolor/scalable/apps/chameleon_v_balíku.png'
})
38 changes: 38 additions & 0 deletions test/mockdata/mock_pkgconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from Testing import get_tested_mock_package


PKGCONFIG = get_tested_mock_package(
files={
'/tmp/pkgconfig/xcb.pc': {'content': """
prefix=/usr
exec_prefix=/usr
libdir=/var/tmp/usr/lib64
includedir=/usr/include//xyz
Name: XCB Xinerama
Description: XCB Xinerama Extension
Version: 1.13
Requires.private: xcb
Libs: -L/usr/lib
Cflags: -I${includedir}"""}
},
header={
'arch': 'x86_64'
})


PKGCONFIG2 = get_tested_mock_package(
files={
'/usr/include/reiserfs',
'/usr/include/reiserfs/io.h',
'/usr/include/reiserfs/misc.h',
'/usr/include/reiserfs/reiserfs_err.h',
'/usr/include/reiserfs/reiserfs_fs.h',
'/usr/include/reiserfs/reiserfs_lib.h',
'/usr/include/reiserfs/swab.h',
'/usr/lib64/libreiserfscore.a',
'/usr/lib64/libreiserfscore.la',
'/usr/lib64/libreiserfscore.so',
'/usr/lib64/libreiserfscore.so.0',
'/usr/lib64/pkgconfig/reiserfscore.pc'}
)
9 changes: 5 additions & 4 deletions test/test_FHS.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from mockdata.mock_FHS import FHS
import pytest
from rpmlint.checks.FHSCheck import FHSCheck
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,13 +14,13 @@ def fhscheck():
return output, test


@pytest.mark.parametrize('package', ['binary/non-fhs'])
def test_FHS_compliance(tmp_path, package, fhscheck):
@pytest.mark.parametrize('package', [FHS])
def test_FHS_compliance(package, fhscheck):
"""
Check that the directories are not FHS compliant.
"""
output, test = fhscheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)

# Check invalid /usr subdirectory
Expand Down
49 changes: 26 additions & 23 deletions test/test_menuxdg.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# TODO: Add MXDG4 when the test is corrected
from mockdata.mock_menuxdg import MENUXDG, MENUXDG1, MENUXDG2, MENUXDG3, MENUXDG5
import pytest
from rpmlint.checks.MenuXDGCheck import MenuXDGCheck
from rpmlint.filter import Filter

from Testing import CONFIG, get_tested_package, HAS_DESKTOP_FILE_UTILS
from Testing import CONFIG, HAS_DESKTOP_FILE_UTILS


@pytest.fixture(scope='function', autouse=True)
Expand All @@ -14,10 +16,10 @@ def menuxdgcheck():


@pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed')
@pytest.mark.parametrize('package', ['binary/menuxdg1'])
def test_raises_parse_error(tmp_path, package, menuxdgcheck):
@pytest.mark.parametrize('package', [MENUXDG])
def test_raises_parse_error(package, menuxdgcheck):
output, test = menuxdgcheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
assert len(output.results) == 4
out = output.print_results(output.results)
assert 'contains parsing error' in out
Expand All @@ -26,47 +28,48 @@ def test_raises_parse_error(tmp_path, package, menuxdgcheck):


@pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed')
@pytest.mark.parametrize('package', ['binary/desktopfile-bad-binary'])
def test_without_binary(tmp_path, package, menuxdgcheck):
@pytest.mark.parametrize('package', [MENUXDG1])
def test_without_binary(package, menuxdgcheck):
output, test = menuxdgcheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'desktopfile-without-binary' in out


@pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed')
@pytest.mark.parametrize('package', ['binary/desktopfile-bad-duplicate'])
def test_duplicate(tmp_path, package, menuxdgcheck):
@pytest.mark.parametrize('package', [MENUXDG2])
def test_duplicate(package, menuxdgcheck):
output, test = menuxdgcheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'desktopfile-duplicate-section' in out
assert 'invalid-desktopfile' in out


@pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed')
@pytest.mark.parametrize('package', ['binary/desktopfile-bad-section'])
def test_missing_header(tmp_path, package, menuxdgcheck):
@pytest.mark.parametrize('package', [MENUXDG3])
def test_missing_header(package, menuxdgcheck):
output, test = menuxdgcheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'desktopfile-missing-header' in out
assert 'invalid-desktopfile' in out


@pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed')
@pytest.mark.parametrize('package', ['binary/desktopfile-bad-unicode'])
def test_bad_unicode(tmp_path, package, menuxdgcheck):
output, test = menuxdgcheck
test.check(get_tested_package(package, tmp_path))
out = output.print_results(output.results)
assert 'non-utf8-desktopfile' in out
# TODO: Correct this test.
# @pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed')
# @pytest.mark.parametrize('package', [MENUXDG4])
# def test_bad_unicode(package, menuxdgcheck):
# output, test = menuxdgcheck
# test.check(package)
# out = output.print_results(output.results)
# assert 'non-utf8-desktopfile' in out


@pytest.mark.skipif(not HAS_DESKTOP_FILE_UTILS, reason='Optional dependency desktop-file-utils not installed')
@pytest.mark.parametrize('package', ['binary/desktopfile-good'])
def test_good(tmp_path, package, menuxdgcheck):
@pytest.mark.parametrize('package', [MENUXDG5])
def test_good(package, menuxdgcheck):
output, test = menuxdgcheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert not out
15 changes: 8 additions & 7 deletions test/test_pkgconfig.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from mockdata.mock_pkgconfig import PKGCONFIG, PKGCONFIG2
import pytest
from rpmlint.checks.PkgConfigCheck import PkgConfigCheck
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,20 +14,20 @@ def pkgconfigcheck():
return output, test


@pytest.mark.parametrize('package', ['binary/pc'])
def test_pkg_config(tmp_path, package, pkgconfigcheck):
@pytest.mark.parametrize('package', [PKGCONFIG])
def test_pkg_config(package, pkgconfigcheck):
output, test = pkgconfigcheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: invalid-pkgconfig-file /tmp/pkgconfig/xcb.pc' in out
assert 'E: pkgconfig-invalid-libs-dir /tmp/pkgconfig/xcb.pc Libs: -L/usr/lib' in out
assert 'E: double-slash-in-pkgconfig-path /tmp/pkgconfig/xcb.pc includedir=/usr/include//xyz' in out


@pytest.mark.parametrize('package', ['binary/libreiserfscore-devel'])
def test_pkg_config_correct(tmp_path, package, pkgconfigcheck):
@pytest.mark.parametrize('package', [PKGCONFIG2])
def test_pkg_config_correct(package, pkgconfigcheck):
output, test = pkgconfigcheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: invalid-pkgconfig-file' not in out
assert 'E: pkgconfig-invalid-libs-dir' not in out
Expand Down

0 comments on commit 2241a48

Please sign in to comment.