本文整理汇总了Python中testing.fixtures.add_config_to_repo函数的典型用法代码示例。如果您正苦于以下问题:Python add_config_to_repo函数的具体用法?Python add_config_to_repo怎么用?Python add_config_to_repo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_config_to_repo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_useless_exclude_with_types_filter
def test_useless_exclude_with_types_filter(capsys, in_git_dir):
config = {
'repos': [
{
'repo': 'meta',
'hooks': [
{
'id': 'check-useless-excludes',
'exclude': '.pre-commit-config.yaml',
'types': ['python'],
},
],
},
],
}
add_config_to_repo(in_git_dir.strpath, config)
assert check_useless_excludes.main(()) == 1
out, _ = capsys.readouterr()
out = out.strip()
expected = (
"The exclude pattern '.pre-commit-config.yaml' for "
'check-useless-excludes does not match any files'
)
assert expected == out
示例2: test_local_hooks
def test_local_hooks(tempdir_factory, mock_out_store_directory):
config = OrderedDict((
('repo', 'local'),
(
'hooks', (
OrderedDict((
('id', 'arg-per-line'),
('name', 'Args per line hook'),
('entry', 'bin/hook.sh'),
('language', 'script'),
('files', ''),
('args', ['hello', 'world']),
)), OrderedDict((
('id', 'do_not_commit'),
('name', 'Block if "DO NOT COMMIT" is found'),
('entry', 'DO NOT COMMIT'),
('language', 'pcre'),
('files', '^(.*)$'),
)),
),
),
))
git_path = git_dir(tempdir_factory)
add_config_to_repo(git_path, config)
runner = Runner(git_path, C.CONFIG_FILE)
assert len(runner.repositories) == 1
assert len(runner.repositories[0].hooks) == 2
示例3: test_args_hook_only
def test_args_hook_only(cap_out, store, repo_with_passing_hook):
config = {
'repo': 'local',
'hooks': [
{
'id': 'flake8',
'name': 'flake8',
'entry': "'{}' -m flake8".format(sys.executable),
'language': 'system',
'stages': ['commit'],
},
{
'id': 'do_not_commit',
'name': 'Block if "DO NOT COMMIT" is found',
'entry': 'DO NOT COMMIT',
'language': 'pygrep',
},
],
}
add_config_to_repo(repo_with_passing_hook, config)
stage_a_file()
ret, printed = _do_run(
cap_out,
store,
repo_with_passing_hook,
run_opts(hook='do_not_commit'),
)
assert b'flake8' not in printed
示例4: test_local_hook_fails
def test_local_hook_fails(cap_out, store, repo_with_passing_hook):
config = {
'repo': 'local',
'hooks': [{
'id': 'no-todo',
'name': 'No TODO',
'entry': 'sh -c "! grep -iI todo [email protected]" --',
'language': 'system',
}],
}
add_config_to_repo(repo_with_passing_hook, config)
with io.open('dummy.py', 'w') as staged_file:
staged_file.write('"""TODO: something"""\n')
cmd_output('git', 'add', 'dummy.py')
_test_run(
cap_out,
store,
repo_with_passing_hook,
opts={},
expected_outputs=[b''],
expected_ret=1,
stage=False,
)
示例5: test_local_hook_passes
def test_local_hook_passes(cap_out, store, repo_with_passing_hook):
config = {
'repo': 'local',
'hooks': [
{
'id': 'flake8',
'name': 'flake8',
'entry': "'{}' -m flake8".format(sys.executable),
'language': 'system',
'files': r'\.py$',
},
{
'id': 'do_not_commit',
'name': 'Block if "DO NOT COMMIT" is found',
'entry': 'DO NOT COMMIT',
'language': 'pygrep',
},
],
}
add_config_to_repo(repo_with_passing_hook, config)
with io.open('dummy.py', 'w') as staged_file:
staged_file.write('"""TODO: something"""\n')
cmd_output('git', 'add', 'dummy.py')
_test_run(
cap_out,
store,
repo_with_passing_hook,
opts={},
expected_outputs=[b''],
expected_ret=0,
stage=False,
)
示例6: test_autoupdate_local_hooks
def test_autoupdate_local_hooks(in_git_dir, store):
config = sample_local_config()
add_config_to_repo('.', config)
assert autoupdate(C.CONFIG_FILE, store, tags_only=False) == 0
new_config_writen = read_config('.')
assert len(new_config_writen['repos']) == 1
assert new_config_writen['repos'][0] == config
示例7: test_local_hook_passes
def test_local_hook_passes(repo_with_passing_hook, mock_out_store_directory):
config = OrderedDict((
('repo', 'local'),
('hooks', (OrderedDict((
('id', 'pylint'),
('name', 'PyLint'),
('entry', 'python -m pylint.__main__'),
('language', 'system'),
('files', r'\.py$'),
)), OrderedDict((
('id', 'do_not_commit'),
('name', 'Block if "DO NOT COMMIT" is found'),
('entry', 'DO NOT COMMIT'),
('language', 'pcre'),
('files', '^(.*)$'),
))))
))
add_config_to_repo(repo_with_passing_hook, config)
with io.open('dummy.py', 'w') as staged_file:
staged_file.write('"""TODO: something"""\n')
cmd_output('git', 'add', 'dummy.py')
_test_run(
repo_with_passing_hook,
options={},
expected_outputs=[b''],
expected_ret=0,
stage=False
)
示例8: test_meta_hook_passes
def test_meta_hook_passes(cap_out, store, repo_with_passing_hook):
add_config_to_repo(repo_with_passing_hook, sample_meta_config())
_test_run(
cap_out,
store,
repo_with_passing_hook,
opts={},
expected_outputs=[b'Check for useless excludes'],
expected_ret=0,
stage=False,
)
示例9: test_no_excludes
def test_no_excludes(capsys, in_git_dir):
config = {
'repos': [
{
'repo': 'meta',
'hooks': [{'id': 'check-useless-excludes'}],
},
],
}
add_config_to_repo(in_git_dir.strpath, config)
assert check_useless_excludes.main(()) == 0
out, _ = capsys.readouterr()
assert out == ''
示例10: test_always_run_alt_config
def test_always_run_alt_config(cap_out, store, repo_with_passing_hook):
repo_root = '.'
config = read_config(repo_root)
config['repos'][0]['hooks'][0]['always_run'] = True
alt_config_file = 'alternate_config.yaml'
add_config_to_repo(repo_root, config, config_file=alt_config_file)
_test_run(
cap_out,
store,
repo_with_passing_hook,
{},
(b'Bash hook', b'Passed'),
0,
stage=False,
config_file=alt_config_file,
)
示例11: test_push_hook
def test_push_hook(cap_out, repo_with_passing_hook, mock_out_store_directory):
config = OrderedDict((
('repo', 'local'),
(
'hooks', (
OrderedDict((
('id', 'flake8'),
('name', 'hook 1'),
('entry', "'{}' -m flake8".format(sys.executable)),
('language', 'system'),
('types', ['python']),
('stages', ['commit']),
)),
OrderedDict((
('id', 'do_not_commit'),
('name', 'hook 2'),
('entry', 'DO NOT COMMIT'),
('language', 'pcre'),
('types', ['text']),
('stages', ['push']),
)),
),
),
))
add_config_to_repo(repo_with_passing_hook, config)
open('dummy.py', 'a').close()
cmd_output('git', 'add', 'dummy.py')
_test_run(
cap_out,
repo_with_passing_hook,
{'hook_stage': 'commit'},
expected_outputs=[b'hook 1'],
expected_ret=0,
stage=False,
)
_test_run(
cap_out,
repo_with_passing_hook,
{'hook_stage': 'push'},
expected_outputs=[b'hook 2'],
expected_ret=0,
stage=False,
)
示例12: test_autoupdate_local_hooks
def test_autoupdate_local_hooks(tempdir_factory):
git_path = git_dir(tempdir_factory)
config = config_with_local_hooks()
path = add_config_to_repo(git_path, config)
runner = Runner(path, C.CONFIG_FILE)
assert autoupdate(runner, tags_only=False) == 0
new_config_writen = load_config(runner.config_file_path)
assert len(new_config_writen['repos']) == 1
assert new_config_writen['repos'][0] == config
示例13: test_autoupdate_local_hooks
def test_autoupdate_local_hooks(tmpdir_factory):
git_path = git_dir(tmpdir_factory)
config = config_with_local_hooks()
path = add_config_to_repo(git_path, config)
runner = Runner(path)
assert autoupdate(runner) == 0
new_config_writen = load_config(runner.config_file_path)
assert len(new_config_writen) == 1
assert new_config_writen[0] == config
示例14: test_useless_exclude_global
def test_useless_exclude_global(capsys, in_git_dir):
config = {
'exclude': 'foo',
'repos': [
{
'repo': 'meta',
'hooks': [{'id': 'check-useless-excludes'}],
},
],
}
add_config_to_repo(in_git_dir.strpath, config)
assert check_useless_excludes.main(()) == 1
out, _ = capsys.readouterr()
out = out.strip()
assert "The global exclude pattern 'foo' does not match any files" == out
示例15: test_valid_exceptions
def test_valid_exceptions(capsys, in_git_dir, mock_store_dir):
config = {
'repos': [
{
'repo': 'local',
'hooks': [
# applies to a file
{
'id': 'check-yaml',
'name': 'check yaml',
'entry': './check-yaml',
'language': 'script',
'files': r'\.yaml$',
},
# Should not be reported as an error due to language: fail
{
'id': 'changelogs-rst',
'name': 'changelogs must be rst',
'entry': 'changelog filenames must end in .rst',
'language': 'fail',
'files': r'changelog/.*(?<!\.rst)$',
},
# Should not be reported as an error due to always_run
{
'id': 'i-always-run',
'name': 'make check',
'entry': 'make check',
'language': 'system',
'files': '^$',
'always_run': True,
},
],
},
],
}
add_config_to_repo(in_git_dir.strpath, config)
assert check_hooks_apply.main(()) == 0
out, _ = capsys.readouterr()
assert out == ''