Beispiel #1
0
def test_auto_detect_exclude(monkeypatch):
    """Verify that exclude option can be used to narrow down detection."""
    options = cli.get_config(['--exclude', 'foo'])

    def mockreturn(options):
        return ['foo/playbook.yml', 'bar/playbook.yml']

    monkeypatch.setattr(utils, 'get_yaml_files', mockreturn)
    result = utils.get_lintables(options)
    assert result == [Lintable('bar/playbook.yml', kind='playbook')]
Beispiel #2
0
def test_auto_detect_exclude(monkeypatch: MonkeyPatch) -> None:
    """Verify that exclude option can be used to narrow down detection."""
    options = cli.get_config(['--exclude', 'foo'])

    def mockreturn(options: Namespace) -> List[str]:
        return ['foo/playbook.yml', 'bar/playbook.yml']

    monkeypatch.setattr(utils, 'discover_lintables', mockreturn)
    result = utils.get_lintables(options)
    assert result == [Lintable('bar/playbook.yml', kind='playbook')]
Beispiel #3
0
def test_auto_detect(monkeypatch, path: str, kind: FileType) -> None:
    """Verify auto-detection logic."""
    options = cli.get_config([])

    def mockreturn(options):
        return [path]

    monkeypatch.setattr(utils, 'get_yaml_files', mockreturn)
    result = utils.get_lintables(options)
    assert result == [Lintable(path, kind=kind)]
Beispiel #4
0
def _get_matches(rules: RulesCollection, options: "Namespace") -> LintResult:

    lintables = get_lintables(options=options, args=options.lintables)

    matches = list()
    checked_files: Set[str] = set()
    for lintable in lintables:
        runner = Runner(rules, lintable, options.tags,
                        options.skip_list, options.exclude_paths,
                        options.verbosity, checked_files)
        matches.extend(runner.run())

    # Assure we do not print duplicates and the order is consistent
    matches = sorted(set(matches))

    return LintResult(matches=matches, files=checked_files)
Beispiel #5
0
def test_auto_detect(monkeypatch, path: str, kind: FileType) -> None:
    """Verify auto-detection logic."""
    options = cli.get_config([])

    def mockreturn(options):
        return [path]

    # assert Lintable is able to determine file type
    lintable_detected = Lintable(path)
    lintable_expected = Lintable(path, kind=kind)
    assert lintable_detected == lintable_expected

    monkeypatch.setattr(utils, 'get_yaml_files', mockreturn)
    result = utils.get_lintables(options)
    # get_lintable could return additional files and we only care to see
    # that the given file is among the returned list.
    assert lintable_expected in result