• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python fixtures.git_dir函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中testing.fixtures.git_dir函数的典型用法代码示例。如果您正苦于以下问题:Python git_dir函数的具体用法?Python git_dir怎么用?Python git_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了git_dir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:pre-commit,项目名称:pre-commit,代码行数:8,代码来源:conftest.py


示例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)]
开发者ID:pre-commit,项目名称:pre-commit,代码行数:33,代码来源:store_test.py


示例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
开发者ID:Lucas-C,项目名称:pre-commit,代码行数:32,代码来源:install_uninstall_test.py


示例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
开发者ID:Lucas-C,项目名称:pre-commit,代码行数:27,代码来源:runner_test.py


示例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,
        )
开发者ID:hitul007,项目名称:pre-commit,代码行数:28,代码来源:repository_test.py


示例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
开发者ID:bukzor,项目名称:pre-commit,代码行数:7,代码来源:git_test.py


示例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)
开发者ID:bukzor,项目名称:pre-commit,代码行数:7,代码来源:staged_files_only_test.py


示例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)
开发者ID:brettmcintosh,项目名称:pre-commit,代码行数:7,代码来源:staged_files_only_test.py


示例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
开发者ID:imbstack,项目名称:pre-commit,代码行数:7,代码来源:git_test.py


示例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
开发者ID:pre-commit,项目名称:pre-commit,代码行数:25,代码来源:conftest.py


示例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
开发者ID:rolka,项目名称:pre-commit,代码行数:28,代码来源:install_uninstall_test.py


示例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)
开发者ID:akramhussein,项目名称:pre-commit,代码行数:7,代码来源:git_test.py


示例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'))
开发者ID:bukzor,项目名称:pre-commit,代码行数:34,代码来源:make_archives_test.py


示例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
开发者ID:bukzor,项目名称:pre-commit,代码行数:25,代码来源:store_test.py


示例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)
开发者ID:rolka,项目名称:pre-commit,代码行数:7,代码来源:install_uninstall_test.py


示例16: foo_staged

def foo_staged(tempdir_factory):
    path = git_dir(tempdir_factory)
    with cwd(path):
        with io.open('foo', 'w') as foo_file:
            foo_file.write(FOO_CONTENTS)
        cmd_output('git', 'add', 'foo')
        foo_filename = os.path.join(path, 'foo')
        yield auto_namedtuple(path=path, foo_filename=foo_filename)
开发者ID:brettmcintosh,项目名称:pre-commit,代码行数:8,代码来源:staged_files_only_test.py


示例17: submodule_with_commits

def submodule_with_commits(tempdir_factory):
    path = git_dir(tempdir_factory)
    with cwd(path):
        cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
        sha1 = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
        cmd_output('git', 'commit', '--allow-empty', '-m', 'bar')
        sha2 = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
        yield auto_namedtuple(path=path, sha1=sha1, sha2=sha2)
开发者ID:brettmcintosh,项目名称:pre-commit,代码行数:8,代码来源:staged_files_only_test.py


示例18: submodule_with_commits

def submodule_with_commits(tmpdir_factory):
    path = git_dir(tmpdir_factory)
    with local.cwd(path):
        local['git']('commit', '--allow-empty', '-m', 'foo')
        sha1 = local['git']('rev-parse', 'HEAD').strip()
        local['git']('commit', '--allow-empty', '-m', 'bar')
        sha2 = local['git']('rev-parse', 'HEAD').strip()
        yield auto_namedtuple(path=path, sha1=sha1, sha2=sha2)
开发者ID:bukzor,项目名称:pre-commit,代码行数:8,代码来源:staged_files_only_test.py


示例19: submodule_with_commits

def submodule_with_commits(tempdir_factory):
    path = git_dir(tempdir_factory)
    with cwd(path):
        git_commit()
        rev1 = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
        git_commit()
        rev2 = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
        yield auto_namedtuple(path=path, rev1=rev1, rev2=rev2)
开发者ID:pre-commit,项目名称:pre-commit,代码行数:8,代码来源:staged_files_only_test.py


示例20: test_cwd_of_hook

def test_cwd_of_hook(tmpdir_factory, store):
    # Note: this doubles as a test for `system` hooks
    path = git_dir(tmpdir_factory)
    with cwd(path):
        _test_hook_repo(
            tmpdir_factory, store, 'prints_cwd_repo',
            'prints_cwd', ['-L'], _norm_pwd(path) + '\n',
        )
开发者ID:caffodian,项目名称:pre-commit,代码行数:8,代码来源:repository_test.py



注:本文中的testing.fixtures.git_dir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python fixtures.make_config_from_repo函数代码示例发布时间:2022-05-27
下一篇:
Python fixtures.add_config_to_repo函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap