def test_descriptions_from_config(capsys, packages): """ Test that rpmlint updates 'parametrized' descriptions from configuration. We test that "parametrized" errors (non-standard-dir-in-usr and non-standard-dir-in-var) were overridden by values from 'descriptions.config' file. """ additional_options = { 'config': [testpath() / 'configs/descriptions.config'], 'rpmfile': [packages] } options_preset['verbose'] = True options = {**options_preset, **additional_options} linter = Lint(options) linter.run() out, err = capsys.readouterr() assert 'A new text for non-standard-dir-in-usr error.' in out assert 'A new text for non-standard-dir-in-var error.' in out assert 'Your package is creating a non-standard subdirectory in /usr' \ not in out assert 'Your package is creating a non-standard subdirectory in /var' \ not in out assert not err
def test_distribution_tags(): oldpkg = os.path.join(testpath(), 'binary/mc-4.8.15-10.3.1.x86_64.rpm') newpkg = os.path.join(testpath(), 'binary/mc-4.8.21-2.1.x86_64.rpm') ignore = list() diff = Rpmdiff(oldpkg, newpkg, ignore) textdiff = diff.textdiff() # the count always reports one less assert textdiff.count('\n') + 1 == 231 ignore.append('T') ignore.append('5') ignore.append('S') diff = Rpmdiff(oldpkg, newpkg, ignore) textdiff = diff.textdiff() assert textdiff.count('\n') + 1 == 36 assert 'added /usr/share/mc/syntax/yaml.syntax' in textdiff
def test_distribution_tags(): oldpkg = testpath() / 'binary/mc-4.8.15-10.3.1.x86_64.rpm' newpkg = testpath() / 'binary/mc-4.8.21-2.1.x86_64.rpm' ignore = [] diff = Rpmdiff(oldpkg, newpkg, ignore) textdiff = diff.textdiff() # the count always reports one less assert 231 <= len(textdiff.splitlines()) <= 233 ignore.append('T') ignore.append('5') ignore.append('S') diff = Rpmdiff(oldpkg, newpkg, ignore) textdiff = diff.textdiff() assert 36 <= len(textdiff.splitlines()) <= 38 assert 'added /usr/share/mc/syntax/yaml.syntax' in textdiff
def test_exclude(): oldpkg = testpath() / 'binary/mc-4.8.15-10.3.1.x86_64.rpm' newpkg = testpath() / 'binary/mc-4.8.21-2.1.x86_64.rpm' ignore = list('T5S') # print(Rpmdiff(oldpkg, newpkg, ignore=ignore).textdiff()) for exclude in [], ['/usr/share/mc/ski'], ['/share/mc/skins'], ['skins']: diff = Rpmdiff(oldpkg, newpkg, ignore, exclude) textdiff = diff.textdiff() assert '/usr/share/mc/skins/yadt256.ini' in textdiff for exclude in (['/usr/share/mc/skins'], ['/usr/share/*/skins'], ['/*/*/*/skins']): diff = Rpmdiff(oldpkg, newpkg, ignore, exclude) textdiff = diff.textdiff() assert '/usr/share/mc/skins/yadt256.ini' not in textdiff assert '/usr/share/mc/syntax/cuda.syntax' in textdiff for exclude in ['*.syntax'], ['syntax/cuda.syntax']: diff = Rpmdiff(oldpkg, newpkg, ignore, exclude) textdiff = diff.textdiff() assert '/usr/share/mc/skins/yadt256.ini' in textdiff assert '/usr/share/mc/syntax/cuda.syntax' not in textdiff
def test_explain_non_standard_dir_from_cfg(capsys): """ Test that 'explain' option can read updated description from configuration. Test 'non-standard-dir-in-usr' error that is special because the original description is not defined in FHSCheck.toml but in FHSCheck.py. Then it's supposed to be overridden to the custom values defined in 'descriptions.config' file. """ additional_options = { 'config': [testpath() / 'configs/descriptions.config'], 'explain': ['non-standard-dir-in-usr'] } options = {**options_preset, **additional_options} linter = Lint(options) linter.run() out, err = capsys.readouterr() assert 'A new text for non-standard-dir-in-usr error.' in out assert 'Your package is creating a non-standard subdirectory in /usr' not in out assert not err
def test_explain_no_binary_from_cfg(capsys): """ Test that 'explain' option can read updated description from configuration. Test 'no-binary' error that is defined in CheckBinaries.toml file by default and then it's overridden to the custom values defined in 'descriptions.config' file. """ additional_options = { 'config': [testpath() / 'configs/descriptions.config'], 'explain': ['no-binary'] } options = {**options_preset, **additional_options} linter = Lint(options) linter.run() out, err = capsys.readouterr() # the new string is present and the old one is not assert 'A new text for no-binary error.' in out assert 'The package should be of the noarch architecture' not in out assert not err
from pathlib import Path import pytest from rpmlint.config import Config from Testing import TEST_CONFIG, testpath TEST_CONFIG_2 = [testpath() / 'configs/test2.config'] TEST_CONFIG_FILTERS = [testpath() / 'configs/testfilters.config'] TEST_LIST1 = [testpath() / 'configs/testlists1.config'] TEST_LIST2 = [testpath() / 'configs/testlists2.config'] TEST_OVERRIDE = [testpath() / 'configs/test.override.config'] TEST_RPMLINTRC = testpath() / 'configs/testing-rpmlintrc' TEST_BROKEN = [testpath() / 'configs/broken.config'] def test_printing(capsys): cfg = Config() cfg.print_config() out, err = capsys.readouterr() assert not err assert out def test_custom_config(capsys): cfg = Config() # bullshit config cfg.find_configs([Path('BULLSHIT')]) out, err = capsys.readouterr() assert Path('BULLSHIT') not in cfg.conf_files assert 'BULLSHIT' in err
from pathlib import Path from rpmlint.config import Config from Testing import TEST_CONFIG, testpath TEST_CONFIG_2 = testpath() / 'configs/test2.config' TEST_CONFIG_FILTERS = testpath() / 'configs/testfilters.config' TEST_LIST1 = testpath() / 'configs/testlists1.config' TEST_LIST2 = testpath() / 'configs/testlists2.config' TEST_RPMLINTRC = testpath() / 'configs/testing-rpmlintrc' TEST_BROKEN = testpath() / 'configs/broken.config' def test_printing(capsys): cfg = Config() cfg.print_config() out, err = capsys.readouterr() assert not err assert out def test_custom_config(capsys): cfg = Config() # bullshit config cfg.find_configs(Path('BULLSHIT')) out, err = capsys.readouterr() assert Path('BULLSHIT') not in cfg.conf_files assert 'BULLSHIT' in err # existing config cfg.find_configs(TEST_CONFIG)
import os from rpmlint.Config import Config from Testing import TEST_CONFIG, testpath TEST_CONFIG_2 = os.path.join(testpath(), 'configs/test2.config') TEST_CONFIG_FILTERS = os.path.join(testpath(), 'configs/testfilters.config') TEST_LIST1 = os.path.join(testpath(), 'configs/testlists1.config') TEST_LIST2 = os.path.join(testpath(), 'configs/testlists2.config') TEST_RPMLINTRC = os.path.join(testpath(), 'configs/testing-rpmlintrc') def test_printing(capsys): cfg = Config() cfg.print_config() out, err = capsys.readouterr() assert not err assert out def test_custom_config(capsys): cfg = Config() # bullshit config cfg.find_configs('BULLSHIT') out, err = capsys.readouterr() assert 'BULLSHIT' not in cfg.conf_files assert 'BULLSHIT' in err # existing config cfg.find_configs(TEST_CONFIG) out, err = capsys.readouterr()
import os from typing.re import Pattern from rpmlint.Config import Config from rpmlint.Filter import Filter from Testing import get_tested_package, testpath TEST_CONFIG_FILTERS = os.path.join(testpath(), 'configs/testfilters.config') TEST_RPMLINTRC = os.path.join(testpath(), 'configs/testing-rpmlintrc') TEST_PACKAGE = os.path.join('binary', 'ngircd') TEST_PACKAGE2 = os.path.join('binary', 'dovecot') def test_filters_regexp(): """ Load some filters and make sure we generate nice regexp """ cfg = Config(TEST_CONFIG_FILTERS) result = Filter(cfg) assert len(cfg.configuration['Filters']) == 9 assert cfg.configuration['Filters'][0] == '.*invalid-buildhost.*' assert isinstance(result.filters_re, Pattern) def test_data_storing(tmpdir): """ Load some filters and make sure we generate nice regexp """ cfg = Config(TEST_CONFIG_FILTERS) cfg.load_rpmlintrc(TEST_RPMLINTRC)
from pathlib import Path import pytest from rpmlint.lint import Lint from rpmlint.spellcheck import ENCHANT from Testing import (HAS_CHECKBASHISMS, HAS_DASH, HAS_ENGLISH_DICTIONARY, HAS_RPMDB, TEST_CONFIG, testpath) TEST_RPMLINTRC = testpath() / 'configs/testing2-rpmlintrc' options_preset = { 'config': TEST_CONFIG, 'verbose': False, 'strict': False, 'permissive': False, 'print_config': False, 'explain': '', 'rpmfile': '', 'rpmlintrc': False, 'installed': '', 'time_report': False, 'profile': False, 'ignore_unused_rpmlintrc': False, 'checks': None } basic_tests = [ 'AlternativesCheck', 'AppDataCheck', 'BinariesCheck',
import os from typing.re import Pattern from rpmlint.config import Config from rpmlint.filter import Filter from Testing import get_tested_package, testpath TEST_CONFIG_FILTERS = testpath() / 'configs/testfilters.config' TEST_RPMLINTRC = testpath() / 'configs/testing-rpmlintrc' TEST_PACKAGE = os.path.join('binary', 'ngircd') TEST_PACKAGE2 = os.path.join('binary', 'dovecot') def test_filters_regexp(): """ Load some filters and make sure we generate nice regexp """ cfg = Config(TEST_CONFIG_FILTERS) result = Filter(cfg) assert len(cfg.configuration['Filters']) == 9 assert cfg.configuration['Filters'][0] == '.*invalid-buildhost.*' assert isinstance(result.filters_re, Pattern) def test_data_storing(tmpdir): """ Load some filters and make sure we generate nice regexp """ cfg = Config(TEST_CONFIG_FILTERS) cfg.load_rpmlintrc(TEST_RPMLINTRC)
from pathlib import Path from rpmlint.config import Config from rpmlint.filter import Filter from Testing import get_tested_package, testpath TEST_CONFIG_FILTERS = [testpath() / 'configs/testfilters.config'] TEST_RPMLINTRC = testpath() / 'configs/testing-rpmlintrc' TEST3_RPMLINTRC = testpath() / 'configs/testing3-rpmlintrc' TEST_PACKAGE = Path('binary', 'ngircd') TEST_PACKAGE2 = Path('binary', 'tempfiled') TEST_DESCRIPTIONS = [testpath() / 'configs/descriptions.config'] def test_filters_regexp(): """ Load some filters and make sure we generate nice regexp """ cfg = Config(TEST_CONFIG_FILTERS) assert len(cfg.configuration['Filters']) == 12 assert cfg.configuration['Filters'][0] == '.*invalid-buildhost.*' def test_data_storing(tmpdir): """ Load some filters and make sure we generate nice regexp """ cfg = Config(TEST_CONFIG_FILTERS) cfg.load_rpmlintrc(TEST_RPMLINTRC) result = Filter(cfg)