Пример #1
0
def test_run_full_rpm(capsys, packages, configs):
    number_of_pkgs = len(packages)
    additional_options = {
        'rpmfile': packages,
    }
    options_preset['config'] = configs
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert f'{number_of_pkgs} packages and 0 specfiles checked' in out
    # we convert the err as we don't care about errors from missing
    # spellchecking dictionaries -> we have to ignore it
    err_reduced = [
        a for a in err.split('\n') if not a.startswith(
            '(none): W: unable to load spellchecking dictionary for')
        and a != ''
    ]
    # also we can find out signatures are wrong because of the other distros
    # could've signed it
    err_reduced = [
        a for a in err_reduced
        if not a.startswith('Error checking signature of')
    ]
    assert not err_reduced
Пример #2
0
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
Пример #3
0
def lint():
    """
    Main wrapper for lint command processing
    """
    options = process_lint_args(sys.argv[1:])
    lint = Lint(options)
    sys.exit(lint.run())
Пример #4
0
def test_installed_package(capsys):
    additional_options = {'installed': ['bzip2'], 'permissive': True}
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    retcode = linter.run()
    out, err = capsys.readouterr()
    assert '1 packages and 0 specfiles checked' in out
    assert retcode == 0
Пример #5
0
def test_run_rpmlintrc_multiple(capsys, packages):
    additional_options = {
        'rpmfile': [packages],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert 'rpmlintrc:' not in out
    assert 'There are multiple items to be loaded for rpmlintrc' in err
Пример #6
0
def test_run_rpmlintrc_single_file(capsys, packages):
    additional_options = {
        'rpmfile': [packages],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert not err
    assert 'rpmlintrc:' in out
Пример #7
0
def test_run_single(capsys, packages):
    additional_options = {
        'rpmfile': [packages],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert 'E: no-signature' in out
    assert '1 packages and 0 specfiles checked' in out
    assert not err
Пример #8
0
def test_run_full_specs(capsys, packages):
    number_of_pkgs = len(packages)
    additional_options = {
        'rpmfile': packages,
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert f'0 packages and {number_of_pkgs} specfiles checked' in out
    assert not err
Пример #9
0
def test_explain_unknown(capsys):
    message = ['bullcrap']
    additional_options = {
        'explain': message,
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert 'bullcrap:\nUnknown message' in out
    assert not err
Пример #10
0
def test_run_single(capsys, packages):
    additional_options = {
        'rpmfile': [packages],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.checks = _remove_except_zip(linter.checks)
    linter.run()
    out, err = capsys.readouterr()
    assert '1 packages and 0 specfiles checked' in out
    assert not err
Пример #11
0
def test_run_rpmlintrc_single_file(capsys, packages):
    additional_options = {'rpmfile': [packages], 'rpmlintrc': TEST_RPMLINTRC}
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert not err
    assert 'rpmlintrc:' in out
    assert 'E: unused-rpmlintrc-filter "I am not used"' in out
    assert 'E: unused-rpmlintrc-filter "She is not used"' not in out
    assert 'no-%build-section' not in out
Пример #12
0
def test_header_information(capsys):
    additional_options = {
        'rpmfile': [],
        'installed': ['python3-rpm'],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.checks = _remove_except_zip(linter.checks)
    linter.run()
    out, err = capsys.readouterr()
    assert 'packages: 1' in out
Пример #13
0
def test_configoutput(capsys):
    additional_options = {
        'print_config': True,
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert out
    assert 'Vendor = "Fedora Project"' in out
    assert not err
Пример #14
0
def test_explain_known(capsys):
    message = ['infopage-not-compressed']
    additional_options = {
        'explain': message,
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert 'This info page is not compressed' in out
    assert 'Unknown message' not in out
    assert not err
Пример #15
0
def test_run_installed_and_no_files(capsys):
    additional_options = {
        'rpmfile': [],
        'installed': ['python3-rpm'],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.checks = _remove_except_zip(linter.checks)
    linter.run()
    out, err = capsys.readouterr()
    assert '1 packages and 0 specfiles checked' in out
    assert not err
Пример #16
0
def test_run_installed_not_present(capsys):
    additional_options = {
        'rpmfile': [],
        'installed': ['non-existing-package'],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.checks = _remove_except_zip(linter.checks)
    linter.run()
    out, err = capsys.readouterr()
    assert '0 packages and 0 specfiles checked' in out
    assert 'there is no installed rpm' in err
    assert 'There are no files to process' in err
Пример #17
0
def test_run_installed(capsys, packages):
    # load up 1 normal path file and 2 installed packages
    additional_options = {
        'rpmfile': [packages],
        'installed': ['python3-rpm', 'rpm'],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.checks = _remove_except_zip(linter.checks)
    linter.run()
    out, err = capsys.readouterr()
    assert '3 packages and 0 specfiles checked' in out
    assert not err
Пример #18
0
def test_parsing_fedora_conf(test_arguments):
    parsed = process_lint_args(test_arguments)

    assert len(parsed['config']) == 5
    assert PosixPath('configs/Fedora/fedora.toml') in parsed['config']
    assert PosixPath('configs/Fedora/licenses.toml') in parsed['config']
    assert PosixPath('configs/Fedora/users-groups.toml') in parsed['config']

    defaultcfg = Config()
    lint = Lint(parsed)
    default_checks = defaultcfg.configuration['Checks']
    checks = lint.config.configuration['Checks']
    # Verify that all original Checks are enabled and some new are added
    for check in default_checks:
        assert check in checks
    assert len(checks) > len(default_checks)

    # Verify that all scoring keys are a known checks
    checks = set(lint.output.error_details.keys())
    checks |= set(defaultcfg.configuration['Descriptions'].keys())

    score_keys = lint.config.configuration['Scoring'].keys()
    for score_key in score_keys:
        if score_key.startswith('percent-in-'):
            continue
        assert score_key in checks
Пример #19
0
def test_run_strict(capsys, packages):
    """
    Test if we convert warning to error
    """
    additional_options = {
        'rpmfile': [packages],
        'strict': True,
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.checks = _remove_except_zip(linter.checks)
    linter.run()
    out, err = capsys.readouterr()
    assert 'W: unable-to-read-zip' not in out
    assert 'E: unable-to-read-zip' in out
    assert not err
Пример #20
0
def test_run_full_directory(capsys, packages):
    assert packages.is_dir()
    file_list = []
    for item in packages.iterdir():
        if item.is_file():
            file_list.append(item)
    number_of_pkgs = len(file_list)
    additional_options = {
        'rpmfile': [packages],
    }
    options = {**options_preset, **additional_options}
    linter = Lint(options)
    linter.run()
    out, err = capsys.readouterr()
    assert f'0 packages and {number_of_pkgs} specfiles checked' in out
    assert not err
Пример #21
0
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
Пример #22
0
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
Пример #23
0
def test_run_empty(capsys):
    linter = Lint(options_preset)
    linter.run()
    out, err = capsys.readouterr()
    assert err
    assert '0 packages and 0 specfiles checked; 0 errors, 0 warnings' in out
Пример #24
0
def test_cases_loading():
    linter = Lint(options_preset)
    assert list(linter.checks.keys()) == basic_tests