Example #1
0
def test_include_exclude_base_case(some_filenames):
    ret = _filter_by_include_exclude(some_filenames, '', '^$')
    assert ret == {
        '.pre-commit-hooks.yaml',
        'pre_commit/main.py',
        'pre_commit/git.py',
    }
Example #2
0
def test_include_exclude_base_case(some_filenames):
    ret = _filter_by_include_exclude(some_filenames, '', '^$')
    assert ret == {
        '.pre-commit-hooks.yaml',
        'pre_commit/main.py',
        'pre_commit/git.py',
    }
Example #3
0
def check_all_hooks_match_files(config_file):
    files = git.get_all_files()
    retv = 0

    for hook in all_hooks(load_config(config_file), Store()):
        if hook.always_run or hook.language == 'fail':
            continue
        include, exclude = hook.files, hook.exclude
        filtered = _filter_by_include_exclude(files, include, exclude)
        types, exclude_types = hook.types, hook.exclude_types
        filtered = _filter_by_types(filtered, types, exclude_types)
        if not filtered:
            print('{} does not apply to this repository'.format(hook.id))
            retv = 1

    return retv
Example #4
0
def check_all_hooks_match_files(config_file):
    files = git.get_all_files()
    retv = 0

    for repo in repositories(load_config(config_file), Store()):
        for hook_id, hook in repo.hooks:
            if hook['always_run'] or hook['language'] == 'fail':
                continue
            include, exclude = hook['files'], hook['exclude']
            filtered = _filter_by_include_exclude(files, include, exclude)
            types, exclude_types = hook['types'], hook['exclude_types']
            filtered = _filter_by_types(filtered, types, exclude_types)
            if not filtered:
                print('{} does not apply to this repository'.format(hook_id))
                retv = 1

    return retv
def check_all_hooks_match_files(config_file):
    runner = Runner.create(config_file)
    files = git.get_all_files()
    retv = 0

    for repo in runner.repositories:
        for hook_id, hook in repo.hooks:
            if hook['always_run']:
                continue
            include, exclude = hook['files'], hook['exclude']
            filtered = _filter_by_include_exclude(files, include, exclude)
            types, exclude_types = hook['types'], hook['exclude_types']
            filtered = _filter_by_types(filtered, types, exclude_types)
            if not filtered:
                print('{} does not apply to this repository'.format(hook_id))
                retv = 1

    return retv
Example #6
0
def test_include_exclude_exclude_removes_files(some_filenames):
    ret = _filter_by_include_exclude(some_filenames, '', r'\.py$')
    assert ret == {'.pre-commit-hooks.yaml'}
Example #7
0
def test_include_exclude_does_search_instead_of_match(some_filenames):
    ret = _filter_by_include_exclude(some_filenames, r'\.yaml$', '^$')
    assert ret == {'.pre-commit-hooks.yaml'}
Example #8
0
def test_include_exclude_total_match(some_filenames):
    ret = _filter_by_include_exclude(some_filenames, r'^.*\.py$', '^$')
    assert ret == {'pre_commit/main.py', 'pre_commit/git.py'}
Example #9
0
def test_matches_broken_symlink(tmpdir):  # pramga: no cover (non-windows)
    with tmpdir.as_cwd():
        os.symlink('does-not-exist', 'link')
        ret = _filter_by_include_exclude({'link'}, '', '^$')
        assert ret == {'link'}
Example #10
0
def test_include_exclude_exclude_removes_files(some_filenames):
    ret = _filter_by_include_exclude(some_filenames, '', r'\.py$')
    assert ret == {'.pre-commit-hooks.yaml'}
Example #11
0
def test_include_exclude_does_search_instead_of_match(some_filenames):
    ret = _filter_by_include_exclude(some_filenames, r'\.yaml$', '^$')
    assert ret == {'.pre-commit-hooks.yaml'}
Example #12
0
def test_include_exclude_total_match(some_filenames):
    ret = _filter_by_include_exclude(some_filenames, r'^.*\.py$', '^$')
    assert ret == {'pre_commit/main.py', 'pre_commit/git.py'}
Example #13
0
def test_matches_broken_symlink(tmpdir):  # pramga: no cover (non-windows)
    with tmpdir.as_cwd():
        os.symlink('does-not-exist', 'link')
        ret = _filter_by_include_exclude({'link'}, '', '^$')
        assert ret == {'link'}