mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
No need for OrderedDict
This commit is contained in:
parent
9d48766c02
commit
21c2c9df33
2 changed files with 109 additions and 115 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from pre_commit.meta_hooks import check_hooks_apply
|
from pre_commit.meta_hooks import check_hooks_apply
|
||||||
from testing.fixtures import add_config_to_repo
|
from testing.fixtures import add_config_to_repo
|
||||||
from testing.fixtures import git_dir
|
from testing.fixtures import git_dir
|
||||||
|
|
@ -7,17 +5,19 @@ from testing.util import cwd
|
||||||
|
|
||||||
|
|
||||||
def test_hook_excludes_everything(capsys, tempdir_factory, mock_store_dir):
|
def test_hook_excludes_everything(capsys, tempdir_factory, mock_store_dir):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('repo', 'meta'),
|
'repos': [
|
||||||
(
|
{
|
||||||
'hooks', (
|
'repo': 'meta',
|
||||||
OrderedDict((
|
'hooks': [
|
||||||
('id', 'check-useless-excludes'),
|
{
|
||||||
('exclude', '.pre-commit-config.yaml'),
|
'id': 'check-useless-excludes',
|
||||||
)),
|
'exclude': '.pre-commit-config.yaml',
|
||||||
),
|
},
|
||||||
),
|
],
|
||||||
))
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
@ -30,17 +30,19 @@ def test_hook_excludes_everything(capsys, tempdir_factory, mock_store_dir):
|
||||||
|
|
||||||
|
|
||||||
def test_hook_includes_nothing(capsys, tempdir_factory, mock_store_dir):
|
def test_hook_includes_nothing(capsys, tempdir_factory, mock_store_dir):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('repo', 'meta'),
|
'repos': [
|
||||||
(
|
{
|
||||||
'hooks', (
|
'repo': 'meta',
|
||||||
OrderedDict((
|
'hooks': [
|
||||||
('id', 'check-useless-excludes'),
|
{
|
||||||
('files', 'foo'),
|
'id': 'check-useless-excludes',
|
||||||
)),
|
'files': 'foo',
|
||||||
),
|
},
|
||||||
),
|
],
|
||||||
))
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
@ -53,17 +55,19 @@ def test_hook_includes_nothing(capsys, tempdir_factory, mock_store_dir):
|
||||||
|
|
||||||
|
|
||||||
def test_hook_types_not_matched(capsys, tempdir_factory, mock_store_dir):
|
def test_hook_types_not_matched(capsys, tempdir_factory, mock_store_dir):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('repo', 'meta'),
|
'repos': [
|
||||||
(
|
{
|
||||||
'hooks', (
|
'repo': 'meta',
|
||||||
OrderedDict((
|
'hooks': [
|
||||||
('id', 'check-useless-excludes'),
|
{
|
||||||
('types', ['python']),
|
'id': 'check-useless-excludes',
|
||||||
)),
|
'types': ['python'],
|
||||||
),
|
},
|
||||||
),
|
],
|
||||||
))
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
@ -78,17 +82,19 @@ def test_hook_types_not_matched(capsys, tempdir_factory, mock_store_dir):
|
||||||
def test_hook_types_excludes_everything(
|
def test_hook_types_excludes_everything(
|
||||||
capsys, tempdir_factory, mock_store_dir,
|
capsys, tempdir_factory, mock_store_dir,
|
||||||
):
|
):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('repo', 'meta'),
|
'repos': [
|
||||||
(
|
{
|
||||||
'hooks', (
|
'repo': 'meta',
|
||||||
OrderedDict((
|
'hooks': [
|
||||||
('id', 'check-useless-excludes'),
|
{
|
||||||
('exclude_types', ['yaml']),
|
'id': 'check-useless-excludes',
|
||||||
)),
|
'exclude_types': ['yaml'],
|
||||||
),
|
},
|
||||||
),
|
],
|
||||||
))
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
@ -101,22 +107,21 @@ def test_hook_types_excludes_everything(
|
||||||
|
|
||||||
|
|
||||||
def test_valid_includes(capsys, tempdir_factory, mock_store_dir):
|
def test_valid_includes(capsys, tempdir_factory, mock_store_dir):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('repo', 'meta'),
|
'repos': [
|
||||||
(
|
{
|
||||||
'hooks', (
|
'repo': 'meta',
|
||||||
OrderedDict((
|
'hooks': [
|
||||||
('id', 'check-useless-excludes'),
|
# Should not be reported as an error due to always_run
|
||||||
)),
|
{
|
||||||
# Should not be reported as an error due to always_run
|
'id': 'check-useless-excludes',
|
||||||
OrderedDict((
|
'files': '^$',
|
||||||
('id', 'check-useless-excludes'),
|
'always_run': True,
|
||||||
('files', '^$'),
|
},
|
||||||
('always_run', True),
|
],
|
||||||
)),
|
},
|
||||||
),
|
],
|
||||||
),
|
}
|
||||||
))
|
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from pre_commit.meta_hooks import check_useless_excludes
|
from pre_commit.meta_hooks import check_useless_excludes
|
||||||
from testing.fixtures import add_config_to_repo
|
from testing.fixtures import add_config_to_repo
|
||||||
from testing.fixtures import git_dir
|
from testing.fixtures import git_dir
|
||||||
|
|
@ -7,23 +5,15 @@ from testing.util import cwd
|
||||||
|
|
||||||
|
|
||||||
def test_useless_exclude_global(capsys, tempdir_factory):
|
def test_useless_exclude_global(capsys, tempdir_factory):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('exclude', 'foo'),
|
'exclude': 'foo',
|
||||||
(
|
'repos': [
|
||||||
'repos', [
|
{
|
||||||
OrderedDict((
|
'repo': 'meta',
|
||||||
('repo', 'meta'),
|
'hooks': [{'id': 'check-useless-excludes'}],
|
||||||
(
|
},
|
||||||
'hooks', (
|
],
|
||||||
OrderedDict((
|
}
|
||||||
('id', 'check-useless-excludes'),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
))
|
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
@ -32,21 +22,19 @@ def test_useless_exclude_global(capsys, tempdir_factory):
|
||||||
assert check_useless_excludes.main(()) == 1
|
assert check_useless_excludes.main(()) == 1
|
||||||
|
|
||||||
out, _ = capsys.readouterr()
|
out, _ = capsys.readouterr()
|
||||||
assert "The global exclude pattern 'foo' does not match any files" in out
|
out = out.strip()
|
||||||
|
assert "The global exclude pattern 'foo' does not match any files" == out
|
||||||
|
|
||||||
|
|
||||||
def test_useless_exclude_for_hook(capsys, tempdir_factory):
|
def test_useless_exclude_for_hook(capsys, tempdir_factory):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('repo', 'meta'),
|
'repos': [
|
||||||
(
|
{
|
||||||
'hooks', (
|
'repo': 'meta',
|
||||||
OrderedDict((
|
'hooks': [{'id': 'check-useless-excludes', 'exclude': 'foo'}],
|
||||||
('id', 'check-useless-excludes'),
|
},
|
||||||
('exclude', 'foo'),
|
],
|
||||||
)),
|
}
|
||||||
),
|
|
||||||
),
|
|
||||||
))
|
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
@ -55,24 +43,23 @@ def test_useless_exclude_for_hook(capsys, tempdir_factory):
|
||||||
assert check_useless_excludes.main(()) == 1
|
assert check_useless_excludes.main(()) == 1
|
||||||
|
|
||||||
out, _ = capsys.readouterr()
|
out, _ = capsys.readouterr()
|
||||||
|
out = out.strip()
|
||||||
expected = (
|
expected = (
|
||||||
"The exclude pattern 'foo' for check-useless-excludes "
|
"The exclude pattern 'foo' for check-useless-excludes "
|
||||||
"does not match any files"
|
"does not match any files"
|
||||||
)
|
)
|
||||||
assert expected in out
|
assert expected == out
|
||||||
|
|
||||||
|
|
||||||
def test_no_excludes(capsys, tempdir_factory):
|
def test_no_excludes(capsys, tempdir_factory):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('repo', 'meta'),
|
'repos': [
|
||||||
(
|
{
|
||||||
'hooks', (
|
'repo': 'meta',
|
||||||
OrderedDict((
|
'hooks': [{'id': 'check-useless-excludes'}],
|
||||||
('id', 'check-useless-excludes'),
|
},
|
||||||
)),
|
],
|
||||||
),
|
}
|
||||||
),
|
|
||||||
))
|
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
@ -85,17 +72,19 @@ def test_no_excludes(capsys, tempdir_factory):
|
||||||
|
|
||||||
|
|
||||||
def test_valid_exclude(capsys, tempdir_factory):
|
def test_valid_exclude(capsys, tempdir_factory):
|
||||||
config = OrderedDict((
|
config = {
|
||||||
('repo', 'meta'),
|
'repos': [
|
||||||
(
|
{
|
||||||
'hooks', (
|
'repo': 'meta',
|
||||||
OrderedDict((
|
'hooks': [
|
||||||
('id', 'check-useless-excludes'),
|
{
|
||||||
('exclude', '.pre-commit-config.yaml'),
|
'id': 'check-useless-excludes',
|
||||||
)),
|
'exclude': '.pre-commit-config.yaml',
|
||||||
),
|
},
|
||||||
),
|
],
|
||||||
))
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
repo = git_dir(tempdir_factory)
|
repo = git_dir(tempdir_factory)
|
||||||
add_config_to_repo(repo, config)
|
add_config_to_repo(repo, config)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue