当前位置: 首页>>代码示例>>Python>>正文


Python util.cwd函数代码示例

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


在下文中一共展示了cwd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: f1_is_a_conflict_file

def f1_is_a_conflict_file(in_tmpdir):
    # Make a merge conflict
    cmd_output('git', 'init', 'repo1')
    with cwd('repo1'):
        io.open('f1', 'w').close()
        cmd_output('git', 'add', 'f1')
        cmd_output('git', 'commit', '-m' 'commit1')

    cmd_output('git', 'clone', 'repo1', 'repo2')

    # Commit in master
    with cwd('repo1'):
        write_file('f1', 'parent\n')
        cmd_output('git', 'commit', '-am', 'master commit2')

    # Commit in clone and pull
    with cwd('repo2'):
        write_file('f1', 'child\n')
        cmd_output('git', 'commit', '-am', 'clone commit2')
        cmd_output('git', 'pull', retcode=None)
        # We should end up in a merge conflict!
        assert io.open('f1').read().startswith(
            '<<<<<<< HEAD\n'
            'child\n'
            '=======\n'
            'parent\n'
            '>>>>>>>'
        )
        assert os.path.exists(os.path.join('.git', 'MERGE_MSG'))
        yield
开发者ID:LeoCavaille,项目名称:pre-commit-hooks,代码行数:30,代码来源:check_merge_conflict_test.py

示例2: repository_is_pending_merge

def repository_is_pending_merge(in_tmpdir):
    # Make a (non-conflicting) merge
    cmd_output('git', 'init', 'repo1')
    with cwd('repo1'):
        io.open('f1', 'w').close()
        cmd_output('git', 'add', 'f1')
        cmd_output('git', 'commit', '-m' 'commit1')

    cmd_output('git', 'clone', 'repo1', 'repo2')

    # Commit in master
    with cwd('repo1'):
        write_file('f1', 'parent\n')
        cmd_output('git', 'commit', '-am', 'master commit2')

    # Commit in clone and pull without committing
    with cwd('repo2'):
        write_file('f2', 'child\n')
        cmd_output('git', 'add', 'f2')
        cmd_output('git', 'commit', '-m', 'clone commit2')
        cmd_output('git', 'pull', '--no-commit')
        # We should end up in a pending merge
        assert io.open('f1').read().startswith('parent\n')
        assert io.open('f2').read().startswith('child\n')
        assert os.path.exists(os.path.join('.git', 'MERGE_HEAD'))
        yield
开发者ID:LeoCavaille,项目名称:pre-commit-hooks,代码行数:26,代码来源:check_merge_conflict_test.py

示例3: test_files_running_subdir

def test_files_running_subdir(repo_with_passing_hook, tempdir_factory):
    with cwd(repo_with_passing_hook):
        os.mkdir('subdir')
        open('subdir/foo.py', 'w').close()
        cmd_output('git', 'add', 'subdir/foo.py')

        with cwd('subdir'):
            # Use subprocess to demonstrate behaviour in main
            _, stdout, _ = cmd_output_mocked_pre_commit_home(
                sys.executable, '-m', 'pre_commit.main', 'run', '-v',
                # Files relative to where we are (#339)
                '--files', 'foo.py',
                tempdir_factory=tempdir_factory,
            )
        assert 'subdir/foo.py'.replace('/', os.sep) in stdout
开发者ID:pre-commit,项目名称:pre-commit,代码行数:15,代码来源:run_test.py

示例4: test_adding_something

def test_adding_something(temp_git_dir):
    with cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        cmd_output('git', 'add', 'f.py')

        # Should fail with max size of 0
        assert find_large_added_files(['f.py'], 0) == 1
开发者ID:bchess,项目名称:pre-commit-hooks,代码行数:7,代码来源:check_added_large_files_test.py

示例5: test_hook_that_modifies_but_returns_zero

def test_hook_that_modifies_but_returns_zero(cap_out, store, tempdir_factory):
    git_path = make_consuming_repo(
        tempdir_factory, 'modified_file_returns_zero_repo',
    )
    with cwd(git_path):
        stage_a_file('bar.py')
        _test_run(
            cap_out,
            store,
            git_path,
            {},
            (
                # The first should fail
                b'Failed',
                # With a modified file (default message + the hook's output)
                b'Files were modified by this hook. Additional output:\n\n'
                b'Modified: foo.py',
                # The next hook should pass despite the first modifying
                b'Passed',
                # The next hook should fail
                b'Failed',
                # bar.py was modified, but provides no additional output
                b'Files were modified by this hook.\n',
            ),
            1,
            True,
        )
开发者ID:pre-commit,项目名称:pre-commit,代码行数:27,代码来源:run_test.py

示例6: test_added_file_not_in_pre_commits_list

def test_added_file_not_in_pre_commits_list(temp_git_dir):
    with cwd(temp_git_dir):
        write_file('f.py', "print('hello world')")
        cmd_output('git', 'add', 'f.py')

        # Should pass even with a size of 0
        assert find_large_added_files(['g.py'], 0) == 0
开发者ID:bchess,项目名称:pre-commit-hooks,代码行数:7,代码来源:check_added_large_files_test.py

示例7: _test_sub_state

def _test_sub_state(path, rev='rev1', status='A'):
    assert os.path.exists(path.sub_path)
    with cwd(path.sub_path):
        actual_rev = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
    assert actual_rev == getattr(path.submodule, rev)
    actual_status = get_short_git_status()['sub']
    assert actual_status == status
开发者ID:pre-commit,项目名称:pre-commit,代码行数:7,代码来源:staged_files_only_test.py

示例8: test_environment_not_sourced

def test_environment_not_sourced(tempdir_factory, store):
    path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
    with cwd(path):
        # Patch the executable to simulate rming virtualenv
        with mock.patch.object(sys, 'executable', '/does-not-exist'):
            assert install(C.CONFIG_FILE, store) == 0

        # Use a specific homedir to ignore --user installs
        homedir = tempdir_factory.get()
        ret, stdout, stderr = git_commit(
            env={
                'HOME': homedir,
                'PATH': _path_without_us(),
                # Git needs this to make a commit
                'GIT_AUTHOR_NAME': os.environ['GIT_AUTHOR_NAME'],
                'GIT_COMMITTER_NAME': os.environ['GIT_COMMITTER_NAME'],
                'GIT_AUTHOR_EMAIL': os.environ['GIT_AUTHOR_EMAIL'],
                'GIT_COMMITTER_EMAIL': os.environ['GIT_COMMITTER_EMAIL'],
            },
            retcode=None,
        )
        assert ret == 1
        assert stdout == ''
        assert stderr.replace('\r\n', '\n') == (
            '`pre-commit` not found.  '
            'Did you forget to activate your virtualenv?\n'
        )
开发者ID:pre-commit,项目名称:pre-commit,代码行数:27,代码来源:install_uninstall_test.py

示例9: 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

示例10: 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

示例11: test_pre_push_legacy

def test_pre_push_legacy(tempdir_factory, store):
    upstream = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
    path = tempdir_factory.get()
    cmd_output('git', 'clone', upstream, path)
    with cwd(path):
        mkdirp(os.path.join(path, '.git/hooks'))
        with io.open(os.path.join(path, '.git/hooks/pre-push'), 'w') as f:
            f.write(
                '#!/usr/bin/env bash\n'
                'set -eu\n'
                'read lr ls rr rs\n'
                'test -n "$lr" -a -n "$ls" -a -n "$rr" -a -n "$rs"\n'
                'echo legacy\n',
            )
        make_executable(f.name)

        install(C.CONFIG_FILE, store, hook_type='pre-push')
        assert _get_commit_output(tempdir_factory)[0] == 0

        retc, output = _get_push_output(tempdir_factory)
        assert retc == 0
        first_line, _, third_line = output.splitlines()[:3]
        assert first_line == 'legacy'
        assert third_line.startswith('Bash hook')
        assert third_line.endswith('Passed')
开发者ID:pre-commit,项目名称:pre-commit,代码行数:25,代码来源:install_uninstall_test.py

示例12: test_installed_from_venv

def test_installed_from_venv(tempdir_factory, store):
    path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
    with cwd(path):
        install(C.CONFIG_FILE, store)
        # No environment so pre-commit is not on the path when running!
        # Should still pick up the python from when we installed
        ret, output = _get_commit_output(
            tempdir_factory,
            env={
                'HOME': os.path.expanduser('~'),
                'PATH': _path_without_us(),
                'TERM': os.environ.get('TERM', ''),
                # Windows needs this to import `random`
                'SYSTEMROOT': os.environ.get('SYSTEMROOT', ''),
                # Windows needs this to resolve executables
                'PATHEXT': os.environ.get('PATHEXT', ''),
                # Git needs this to make a commit
                'GIT_AUTHOR_NAME': os.environ['GIT_AUTHOR_NAME'],
                'GIT_COMMITTER_NAME': os.environ['GIT_COMMITTER_NAME'],
                'GIT_AUTHOR_EMAIL': os.environ['GIT_AUTHOR_EMAIL'],
                'GIT_COMMITTER_EMAIL': os.environ['GIT_COMMITTER_EMAIL'],
            },
        )
        assert ret == 0
        assert NORMAL_PRE_COMMIT_RUN.match(output)
开发者ID:pre-commit,项目名称:pre-commit,代码行数:25,代码来源:install_uninstall_test.py

示例13: test_legacy_overwriting_legacy_hook

def test_legacy_overwriting_legacy_hook(tempdir_factory, store):
    path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
    with cwd(path):
        _write_legacy_hook(path)
        assert install(C.CONFIG_FILE, store) == 0
        _write_legacy_hook(path)
        # this previously crashed on windows.  See #1010
        assert install(C.CONFIG_FILE, store) == 0
开发者ID:pre-commit,项目名称:pre-commit,代码行数:8,代码来源:install_uninstall_test.py

示例14: test_failing_hooks_returns_nonzero

def test_failing_hooks_returns_nonzero(tempdir_factory, store):
    path = make_consuming_repo(tempdir_factory, 'failing_hook_repo')
    with cwd(path):
        assert install(C.CONFIG_FILE, store) == 0

        ret, output = _get_commit_output(tempdir_factory)
        assert ret == 1
        assert FAILING_PRE_COMMIT_RUN.match(output)
开发者ID:pre-commit,项目名称:pre-commit,代码行数:8,代码来源:install_uninstall_test.py

示例15: 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


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