本文整理汇总了Python中testing.fixtures.git_dir函数的典型用法代码示例。如果您正苦于以下问题:Python git_dir函数的具体用法?Python git_dir怎么用?Python git_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了git_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: in_conflicting_submodule
def in_conflicting_submodule(tempdir_factory):
git_dir_1 = git_dir(tempdir_factory)
git_dir_2 = git_dir(tempdir_factory)
git_commit(msg=in_conflicting_submodule.__name__, cwd=git_dir_2)
cmd_output('git', 'submodule', 'add', git_dir_2, 'sub', cwd=git_dir_1)
with cwd(os.path.join(git_dir_1, 'sub')):
_make_conflict()
yield
示例2: test_clone_shallow_failure_fallback_to_complete
def test_clone_shallow_failure_fallback_to_complete(
store, tempdir_factory,
log_info_mock,
):
path = git_dir(tempdir_factory)
with cwd(path):
git_commit()
rev = git.head_rev(path)
git_commit()
# Force shallow clone failure
def fake_shallow_clone(self, *args, **kwargs):
raise CalledProcessError(None, None, None)
store._shallow_clone = fake_shallow_clone
ret = store.clone(path, rev)
# Should have printed some stuff
assert log_info_mock.call_args_list[0][0][0].startswith(
'Initializing environment for ',
)
# Should return a directory inside of the store
assert os.path.exists(ret)
assert ret.startswith(store.directory)
# Directory should start with `repo`
_, dirname = os.path.split(ret)
assert dirname.startswith('repo')
# Should be checked out to the rev we specified
assert git.head_rev(ret) == rev
# Assert there's an entry in the sqlite db for this
assert store.select_all_repos() == [(path, rev, ret)]
示例3: test_install_pre_commit
def test_install_pre_commit(tempdir_factory):
path = git_dir(tempdir_factory)
runner = Runner(path, C.CONFIG_FILE)
ret = install(runner)
assert ret == 0
assert os.path.exists(runner.pre_commit_path)
pre_commit_contents = io.open(runner.pre_commit_path).read()
pre_commit_script = resource_filename('hook-tmpl')
expected_contents = io.open(pre_commit_script).read().format(
sys_executable=pipes.quote(sys.executable),
hook_type='pre-commit',
hook_specific='',
config_file=runner.config_file,
skip_on_missing_conf='false',
)
assert pre_commit_contents == expected_contents
assert os.access(runner.pre_commit_path, os.X_OK)
ret = install(runner, hook_type='pre-push')
assert ret == 0
assert os.path.exists(runner.pre_push_path)
pre_push_contents = io.open(runner.pre_push_path).read()
pre_push_tmpl = resource_filename('pre-push-tmpl')
pre_push_template_contents = io.open(pre_push_tmpl).read()
expected_contents = io.open(pre_commit_script).read().format(
sys_executable=pipes.quote(sys.executable),
hook_type='pre-push',
hook_specific=pre_push_template_contents,
config_file=runner.config_file,
skip_on_missing_conf='false',
)
assert pre_push_contents == expected_contents
示例4: 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
示例5: test_pcre_hook_matching
def test_pcre_hook_matching(tempdir_factory, store):
path = git_dir(tempdir_factory)
with cwd(path):
with io.open("herp", "w") as herp:
herp.write("\nherpfoo'bard\n")
with io.open("derp", "w") as derp:
derp.write("[INFO] information yo\n")
_test_hook_repo(
tempdir_factory,
store,
"pcre_hooks_repo",
"regex-with-quotes",
["herp", "derp"],
b"herp:2:herpfoo'bard\n",
expected_return_code=123,
)
_test_hook_repo(
tempdir_factory,
store,
"pcre_hooks_repo",
"other-regex",
["herp", "derp"],
b"derp:1:[INFO] information yo\n",
expected_return_code=123,
)
示例6: test_get_root_deeper
def test_get_root_deeper(tmpdir_factory):
path = git_dir(tmpdir_factory)
foo_path = os.path.join(path, 'foo')
os.mkdir(foo_path)
with local.cwd(foo_path):
assert git.get_root() == path
示例7: img_staged
def img_staged(tmpdir_factory):
path = git_dir(tmpdir_factory)
with local.cwd(path):
img_filename = os.path.join(path, 'img.jpg')
shutil.copy(get_resource_path('img1.jpg'), img_filename)
local['git']('add', 'img.jpg')
yield auto_namedtuple(path=path, img_filename=img_filename)
示例8: img_staged
def img_staged(tempdir_factory):
path = git_dir(tempdir_factory)
with cwd(path):
img_filename = os.path.join(path, 'img.jpg')
shutil.copy(get_resource_path('img1.jpg'), img_filename)
cmd_output('git', 'add', 'img.jpg')
yield auto_namedtuple(path=path, img_filename=img_filename)
示例9: test_get_root_deeper
def test_get_root_deeper(tempdir_factory):
path = git_dir(tempdir_factory)
foo_path = os.path.join(path, "foo")
os.mkdir(foo_path)
with cwd(foo_path):
assert git.get_root() == path
示例10: prepare_commit_msg_repo
def prepare_commit_msg_repo(tempdir_factory):
path = git_dir(tempdir_factory)
script_name = 'add_sign_off.sh'
config = {
'repo': 'local',
'hooks': [{
'id': 'add-signoff',
'name': 'Add "Signed off by:"',
'entry': './{}'.format(script_name),
'language': 'script',
'stages': ['prepare-commit-msg'],
}],
}
write_config(path, config)
with cwd(path):
with io.open(script_name, 'w') as script_file:
script_file.write(
'#!/usr/bin/env bash\n'
'set -eu\n'
'echo "\nSigned off by: " >> "$1"\n',
)
make_executable(script_name)
cmd_output('git', 'add', '.')
git_commit(msg=prepare_commit_msg_repo.__name__)
yield path
示例11: test_install_pre_commit
def test_install_pre_commit(tmpdir_factory):
path = git_dir(tmpdir_factory)
runner = Runner(path)
ret = install(runner)
assert ret == 0
assert os.path.exists(runner.pre_commit_path)
pre_commit_contents = io.open(runner.pre_commit_path).read()
pre_commit_script = resource_filename('hook-tmpl')
expected_contents = io.open(pre_commit_script).read().format(
sys_executable=sys.executable,
hook_type='pre-commit',
pre_push=''
)
assert pre_commit_contents == expected_contents
assert os.access(runner.pre_commit_path, os.X_OK)
ret = install(runner, hook_type='pre-push')
assert ret == 0
assert os.path.exists(runner.pre_push_path)
pre_push_contents = io.open(runner.pre_push_path).read()
pre_push_tmpl = resource_filename('pre-push-tmpl')
pre_push_template_contents = io.open(pre_push_tmpl).read()
expected_contents = io.open(pre_commit_script).read().format(
sys_executable=sys.executable,
hook_type='pre-push',
pre_push=pre_push_template_contents,
)
assert pre_push_contents == expected_contents
示例12: test_get_root_deeper
def test_get_root_deeper(tempdir_factory):
path = git_dir(tempdir_factory)
foo_path = os.path.join(path, 'foo')
os.mkdir(foo_path)
with cwd(foo_path):
assert os.path.normcase(git.get_root()) == os.path.normcase(path)
示例13: test_make_archive
def test_make_archive(tmpdir_factory):
output_dir = tmpdir_factory.get()
git_path = git_dir(tmpdir_factory)
# Add a files to the git directory
with local.cwd(git_path):
local['touch']('foo')
local['git']('add', '.')
local['git']('commit', '-m', 'foo')
# We'll use this sha
head_sha = get_head_sha('.')
# And check that this file doesn't exist
local['touch']('bar')
local['git']('add', '.')
local['git']('commit', '-m', 'bar')
# Do the thing
archive_path = make_archives.make_archive(
'foo', git_path, head_sha, output_dir,
)
assert archive_path == os.path.join(output_dir, 'foo.tar.gz')
assert os.path.exists(archive_path)
extract_dir = tmpdir_factory.get()
# Extract the tar
with tarfile_open(archive_path) as tf:
tf.extractall(extract_dir)
# Verify the contents of the tar
assert os.path.exists(os.path.join(extract_dir, 'foo'))
assert os.path.exists(os.path.join(extract_dir, 'foo', 'foo'))
assert not os.path.exists(os.path.join(extract_dir, 'foo', '.git'))
assert not os.path.exists(os.path.join(extract_dir, 'foo', 'bar'))
示例14: test_clone
def test_clone(store, tmpdir_factory, log_info_mock):
path = git_dir(tmpdir_factory)
with local.cwd(path):
local['git']('commit', '--allow-empty', '-m', 'foo')
sha = get_head_sha(path)
local['git']('commit', '--allow-empty', '-m', 'bar')
ret = store.clone(path, sha)
# Should have printed some stuff
log_info_mock.assert_called_with('This may take a few minutes...')
# Should return a directory inside of the store
assert os.path.exists(ret)
assert ret.startswith(store.directory)
# Directory should start with `repo`
_, dirname = os.path.split(ret)
assert dirname.startswith('repo')
# Should be checked out to the sha we specified
assert get_head_sha(ret) == sha
# Assert that we made a symlink from the sha to the repo
sha_path = os.path.join(store.directory, sha + '_' + hex_md5(path))
assert os.path.exists(sha_path)
assert os.path.islink(sha_path)
assert os.readlink(sha_path) == ret
示例15: test_install_hooks_directory_not_present
def test_install_hooks_directory_not_present(tmpdir_factory):
path = git_dir(tmpdir_factory)
# Simulate some git clients which don't make .git/hooks #234
shutil.rmtree(os.path.join(path, '.git', 'hooks'))
runner = Runner(path)
install(runner)
assert os.path.exists(runner.pre_commit_path)