Beispiel #1
0
def test_private_ssh_format(pip_url_kwargs):
    pip_url_kwargs.update(
        **{'pip_url': 'git+ssh://github.com:' + '/tmp/omg/private_ssh_repo'})

    with pytest.raises(exc.LibVCSException) as excinfo:
        create_repo_from_pip_url(**pip_url_kwargs)
    excinfo.match(r'is malformatted')
Beispiel #2
0
def test_private_ssh_format(pip_url_kwargs):
    pip_url_kwargs.update(
        **{'pip_url': 'git+ssh://github.com:' + '/tmp/omg/private_ssh_repo'}
    )

    with pytest.raises(exc.LibVCSException) as excinfo:
        create_repo_from_pip_url(**pip_url_kwargs)
    excinfo.match(r'is malformatted')
Beispiel #3
0
def test_create_repo_from_pip_url(repo_dict, repo_class, raises_exception, tmpdir):
    # add parent_dir via fixture
    repo_dict['repo_dir'] = str(tmpdir.join('repo_name'))

    if raises_exception:
        with pytest.raises(raises_exception):
            create_repo_from_pip_url(**repo_dict)
    else:
        repo = create_repo_from_pip_url(**repo_dict)
        assert isinstance(repo, repo_class)
Beispiel #4
0
def update_repo(repo_dict):
    repo_dict['pip_url'] = repo_dict.pop('url')
    repo_dict['progress_callback'] = progress_cb

    r = create_repo_from_pip_url(**repo_dict)

    r.update_repo()
Beispiel #5
0
def test_remotes(pip_url_kwargs):
    remote_name = 'myrepo'
    pip_url_kwargs.update(
        **{'remotes': [{'remote_name': remote_name, 'url': 'file:///'}]}
    )

    git_repo = create_repo_from_pip_url(**pip_url_kwargs)
    git_repo.obtain()
    assert remote_name in git_repo.remotes_get
Beispiel #6
0
def test_remotes_preserves_git_ssh(pip_url_kwargs):
    # Regression test for #14
    remote_url = 'git+ssh://[email protected]/tony/AlgoXY.git'

    pip_url_kwargs.update(**{'remotes': [{'remote_name': 'myrepo', 'url': remote_url}]})

    git_repo = create_repo_from_pip_url(**pip_url_kwargs)
    git_repo.obtain()

    assert (remote_url, remote_url) in git_repo.remotes_get.values()
Beispiel #7
0
def test_remotes(pip_url_kwargs):
    remote_name = 'myrepo'
    pip_url_kwargs.update(
        **{'remotes': [{
            'remote_name': remote_name,
            'url': 'file:///'
        }]})

    git_repo = create_repo_from_pip_url(**pip_url_kwargs)
    git_repo.obtain()
    assert remote_name in git_repo.remotes_get
Beispiel #8
0
def test_remotes_vcs_prefix(pip_url_kwargs):
    remote_url = 'https://localhost/my/git/repo.git'
    remote_vcs_url = 'git+' + remote_url

    pip_url_kwargs.update(
        **{'remotes': [{'remote_name': 'myrepo', 'url': remote_vcs_url}]}
    )

    git_repo = create_repo_from_pip_url(**pip_url_kwargs)
    git_repo.obtain()

    assert (remote_url, remote_url) in git_repo.remotes_get.values()
Beispiel #9
0
def test_repo_git_obtain_full(tmpdir, git_remote):
    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+file://' + git_remote,
            'repo_dir': str(tmpdir.join('myrepo')),
        })

    git_repo.obtain()

    test_repo_revision = run(['git', 'rev-parse', 'HEAD'], cwd=git_remote)

    assert git_repo.get_revision() == test_repo_revision
    assert os.path.exists(str(tmpdir.join('myrepo')))
Beispiel #10
0
def test_vcs_url_scheme_to_object(tmpdir):
    """Test that ``url`` return a GitRepo/MercurialRepo/SubversionRepo.

    :class:`GitRepo`, :class:`MercurialRepo` or :class:`SubversionRepo`
    object based on the pip-style URL scheme.

    """
    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+git://git.myproject.org/MyProject.git@da39a3ee5e6b4b',
            'repo_dir': str(tmpdir.join('myproject1')),
        }
    )

    # TODO cwd and name if duplicated should give an error

    assert isinstance(git_repo, GitRepo)
    assert isinstance(git_repo, BaseRepo)

    hg_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'hg+https://hg.myproject.org/MyProject#egg=MyProject',
            'repo_dir': str(tmpdir.join('myproject2')),
        }
    )

    assert isinstance(hg_repo, MercurialRepo)
    assert isinstance(hg_repo, BaseRepo)

    svn_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'svn+svn://svn.myproject.org/svn/MyProject#egg=MyProject',
            'repo_dir': str(tmpdir.join('myproject3')),
        }
    )

    assert isinstance(svn_repo, SubversionRepo)
    assert isinstance(svn_repo, BaseRepo)
Beispiel #11
0
def test_vcs_url_scheme_to_object(tmpdir):
    """Test that ``url`` return a GitRepo/MercurialRepo/SubversionRepo.

    :class:`GitRepo`, :class:`MercurialRepo` or :class:`SubversionRepo`
    object based on the pip-style URL scheme.

    """
    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+git://git.myproject.org/MyProject.git@da39a3ee5e6b4b',
            'repo_dir': str(tmpdir.join('myproject1')),
        }
    )

    # TODO cwd and name if duplicated should give an error

    assert isinstance(git_repo, GitRepo)
    assert isinstance(git_repo, BaseRepo)

    hg_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'hg+https://hg.myproject.org/MyProject#egg=MyProject',
            'repo_dir': str(tmpdir.join('myproject2')),
        }
    )

    assert isinstance(hg_repo, MercurialRepo)
    assert isinstance(hg_repo, BaseRepo)

    svn_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'svn+svn://svn.myproject.org/svn/MyProject#egg=MyProject',
            'repo_dir': str(tmpdir.join('myproject3')),
        }
    )

    assert isinstance(svn_repo, SubversionRepo)
    assert isinstance(svn_repo, BaseRepo)
Beispiel #12
0
def test_repo_svn(tmpdir, svn_dummy_repo_dir):
    repo_name = 'my_svn_project'

    svn_repo = create_repo_from_pip_url(**{
        'pip_url': 'svn+file://' + svn_dummy_repo_dir,
        'repo_dir': str(tmpdir.join(repo_name)),
    })

    svn_repo.obtain()
    svn_repo.update_repo()

    assert svn_repo.get_revision() == 0

    assert os.path.exists(str(tmpdir.join(repo_name)))
Beispiel #13
0
def test_remotes_vcs_prefix(pip_url_kwargs):
    remote_url = 'https://localhost/my/git/repo.git'
    remote_vcs_url = 'git+' + remote_url

    pip_url_kwargs.update(
        **{'remotes': [{
            'remote_name': 'myrepo',
            'url': remote_vcs_url
        }]})

    git_repo = create_repo_from_pip_url(**pip_url_kwargs)
    git_repo.obtain()

    assert (remote_url, remote_url) in git_repo.remotes_get.values()
Beispiel #14
0
def test_repo_git_obtain_full(tmpdir, git_remote):
    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+file://' + git_remote,
            'repo_dir': str(tmpdir.join('myrepo')),
        }
    )

    git_repo.obtain()

    test_repo_revision = run(['git', 'rev-parse', 'HEAD'], cwd=git_remote)

    assert git_repo.get_revision() == test_repo_revision
    assert os.path.exists(str(tmpdir.join('myrepo')))
Beispiel #15
0
def test_remotes_preserves_git_ssh(pip_url_kwargs):
    # Regression test for #14
    remote_url = 'git+ssh://[email protected]/tony/AlgoXY.git'

    pip_url_kwargs.update(
        **{'remotes': [{
            'remote_name': 'myrepo',
            'url': remote_url
        }]})

    git_repo = create_repo_from_pip_url(**pip_url_kwargs)
    git_repo.obtain()

    assert (remote_url, remote_url) in git_repo.remotes_get.values()
Beispiel #16
0
def test_repo_svn(tmpdir, svn_remote):
    repo_name = 'my_svn_project'

    svn_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'svn+file://' + svn_remote,
            'repo_dir': str(tmpdir.join(repo_name)),
        })

    svn_repo.obtain()
    svn_repo.update_repo()

    assert svn_repo.get_revision() == 0
    assert svn_repo.get_revision_file('./') == 0

    assert os.path.exists(str(tmpdir.join(repo_name)))
Beispiel #17
0
def update_repo(repo_dict):
    repo_dict = deepcopy(repo_dict)
    if 'pip_url' not in repo_dict:
        repo_dict['pip_url'] = repo_dict.pop('url')
    repo_dict['progress_callback'] = progress_cb

    r = create_repo_from_pip_url(**repo_dict)  # Creates the repo object

    remote_settings = repo_dict.get('remotes', {})
    if remote_settings.get('origin', {}) == {}:
        from libvcs.git import GitRemote

        remote_settings['origin'] = GitRemote(
            name='origin',
            push_url=repo_dict['pip_url'],
            fetch_url=repo_dict['pip_url'],
        )

    remotes_updated = False
    r.update_repo()  # Creates repo if not exists and fetches

    for remote_name, remote_setting in remote_settings.items():
        config_remote_name = remote_name  # From config file
        try:
            current_remote = r.remote(config_remote_name)
        except FileNotFoundError:  # git repo doesn't exist yet, so cna't be outdated
            break

        current_fetch_url = (current_remote.fetch_url
                             if current_remote is not None else None)

        if current_remote is None or current_fetch_url != remote_setting.fetch_url:
            print(
                'Updating remote {name} ({current_url}) with {new_url}'.format(
                    name=config_remote_name,
                    current_url=current_fetch_url,
                    new_url=remote_setting.fetch_url,
                ))
            r.set_remote(name=config_remote_name,
                         url=remote_setting.fetch_url,
                         overwrite=True)
            remotes_updated = True

    if remotes_updated:  # Fetch again since we added / changed remotes
        r.update_repo()
    return r
Beispiel #18
0
def test_makes_recursive(tmpdir, git_dummy_repo_dir):
    """Ensure that directories in pull are made recursively."""

    YAML_CONFIG = """
    {tmpdir}/study/myrepo:
        my_url: git+file://{repo_dir}
    """

    YAML_CONFIG = YAML_CONFIG.format(tmpdir=str(tmpdir), repo_dir=git_dummy_repo_dir)

    conf = kaptan.Kaptan(handler='yaml')
    conf.import_config(YAML_CONFIG)
    conf = conf.export('dict')
    repos = extract_repos(conf)

    for r in filter_repos(repos):
        repo = create_repo_from_pip_url(**r)
        repo.obtain()
Beispiel #19
0
def test_makes_recursive(tmpdir, git_dummy_repo_dir):
    """Ensure that directories in pull are made recursively."""

    YAML_CONFIG = """
    {TMP_DIR}/study/myrepo:
        my_url: git+file://{REPO_DIR}
    """

    YAML_CONFIG = YAML_CONFIG.format(TMP_DIR=str(tmpdir), REPO_DIR=git_dummy_repo_dir)

    conf = kaptan.Kaptan(handler='yaml')
    conf.import_config(YAML_CONFIG)
    conf = conf.export('dict')
    repos = extract_repos(conf)

    for r in filter_repos(repos):
        repo = create_repo_from_pip_url(**r)
        repo.obtain()
Beispiel #20
0
def test_repo_mercurial(tmpdir, parentdir, hg_remote):
    repo_name = 'my_mercurial_project'

    mercurial_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'hg+file://' + hg_remote,
            'repo_dir': str(parentdir.join(repo_name)),
        })

    run(['hg', 'init', mercurial_repo.name], cwd=str(tmpdir))

    mercurial_repo.update_repo()

    test_repo_revision = run(
        ['hg', 'parents', '--template={rev}'],
        cwd=str(parentdir.join(repo_name)),
    )

    assert mercurial_repo.get_revision() == test_repo_revision
    assert os.path.exists(str(tmpdir.join(repo_name)))
Beispiel #21
0
def test_progress_callback(tmpdir, git_remote, mocker):
    def progress_callback_spy(output, timestamp):
        assert isinstance(output, string_types)
        assert isinstance(timestamp, datetime.datetime)

    progress_callback = mocker.Mock(name='progress_callback_stub',
                                    side_effect=progress_callback_spy)

    run(['git', 'rev-parse', 'HEAD'], cwd=git_remote)

    # create a new repo with the repo as a remote
    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+file://' + git_remote,
            'repo_dir': str(tmpdir.join('myrepo')),
            'progress_callback': progress_callback,
        })
    git_repo.obtain()

    assert progress_callback.called
Beispiel #22
0
def test_repo_update_handle_cases(tmpdir, git_remote, mocker):
    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+file://' + git_remote,
            'repo_dir': str(tmpdir.join('myrepo')),
        })

    git_repo.obtain()  # clone initial repo
    mocka = mocker.spy(git_repo, 'run')
    git_repo.update_repo()

    mocka.assert_any_call(['symbolic-ref', '--short', 'HEAD'])

    mocka.reset_mock()

    # will only look up symbolic-ref if no rev specified for object
    git_repo.rev = 'HEAD'
    git_repo.update_repo()
    assert mocker.call(['symbolic-ref', '--short',
                        'HEAD']) not in mocka.mock_calls
Beispiel #23
0
def test_repo_git_obtain_initial_commit_repo(tmpdir):
    """initial commit repos return 'initial'.

    note: this behaviors differently from git(1)'s use of the word "bare".
    running `git rev-parse --is-bare-repository` would return false.
    """
    repo_name = 'my_git_project'

    run(['git', 'init', repo_name], cwd=str(tmpdir))

    bare_repo_dir = tmpdir.join(repo_name)

    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+file://' + str(bare_repo_dir),
            'repo_dir': str(tmpdir.join('obtaining a bare repo')),
        })

    git_repo.obtain()
    assert git_repo.get_revision() == 'initial'
Beispiel #24
0
def test_repo_update_handle_cases(tmpdir, git_remote, mocker):
    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+file://' + git_remote,
            'repo_dir': str(tmpdir.join('myrepo')),
        }
    )

    git_repo.obtain()  # clone initial repo
    mocka = mocker.spy(git_repo, 'run')
    git_repo.update_repo()

    mocka.assert_any_call(['symbolic-ref', '--short', 'HEAD'])

    mocka.reset_mock()

    # will only look up symbolic-ref if no rev specified for object
    git_repo.rev = 'HEAD'
    git_repo.update_repo()
    assert mocker.call(['symbolic-ref', '--short', 'HEAD']) not in mocka.mock_calls
Beispiel #25
0
def test_repo_mercurial(tmpdir, parentdir, hg_remote):
    repo_name = 'my_mercurial_project'

    mercurial_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'hg+file://' + hg_remote,
            'repo_dir': str(parentdir.join(repo_name)),
        }
    )

    run(['hg', 'init', mercurial_repo.name], cwd=str(tmpdir))

    mercurial_repo.update_repo()

    test_repo_revision = run(
        ['hg', 'parents', '--template={rev}'], cwd=str(parentdir.join(repo_name))
    )

    assert mercurial_repo.get_revision() == test_repo_revision
    assert os.path.exists(str(tmpdir.join(repo_name)))
Beispiel #26
0
def test_repo_git_obtain_initial_commit_repo(tmpdir):
    """initial commit repos return 'initial'.

    note: this behaviors differently from git(1)'s use of the word "bare".
    running `git rev-parse --is-bare-repository` would return false.
    """
    repo_name = 'my_git_project'

    run(['git', 'init', repo_name], cwd=str(tmpdir))

    bare_repo_dir = tmpdir.join(repo_name)

    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+file://' + str(bare_repo_dir),
            'repo_dir': str(tmpdir.join('obtaining a bare repo')),
        }
    )

    git_repo.obtain()
    assert git_repo.get_revision() == 'initial'
Beispiel #27
0
def test_to_repo_objects(tmpdir):
    """:py:obj:`dict` objects into Repo objects."""
    repo_list = filter_repos(fixtures.config_dict_expanded)
    for repo_dict in repo_list:
        r = create_repo_from_pip_url(**repo_dict)

        assert isinstance(r, BaseRepo)
        assert 'name' in r
        assert r['name'] == repo_dict['name']
        assert 'parent_dir' in r
        assert r['parent_dir'] == repo_dict['parent_dir']
        assert 'url' in r
        assert r['url'] == repo_dict['url']

        assert r['path'] == os.path.join(r['parent_dir'], r['name'])

        if 'remotes' in repo_dict:
            assert isinstance(r['remotes'], list)
            for remote_name, remote_dict in r['remotes'].items():
                assert isinstance(remote_dict, dict)
                assert 'fetch_url' in remote_dict
                assert 'push_url' in remote_dict
Beispiel #28
0
def test_progress_callback(tmpdir, git_remote, mocker):
    def progress_callback_spy(output, timestamp):
        assert isinstance(output, string_types)
        assert isinstance(timestamp, datetime.datetime)

    progress_callback = mocker.Mock(
        name='progress_callback_stub', side_effect=progress_callback_spy
    )

    run(['git', 'rev-parse', 'HEAD'], cwd=git_remote)

    # create a new repo with the repo as a remote
    git_repo = create_repo_from_pip_url(
        **{
            'pip_url': 'git+file://' + git_remote,
            'repo_dir': str(tmpdir.join('myrepo')),
            'progress_callback': progress_callback,
        }
    )
    git_repo.obtain()

    assert progress_callback.called
Beispiel #29
0
def test_to_repo_objects(tmpdir):
    """:py:obj:`dict` objects into Repo objects."""
    repo_list = filter_repos(fixtures.config_dict_expanded)
    for repo_dict in repo_list:
        r = create_repo_from_pip_url(**repo_dict)

        assert isinstance(r, BaseRepo)
        assert 'name' in r
        assert r['name'] == repo_dict['name']
        assert 'parent_dir' in r
        assert r['parent_dir'] == repo_dict['parent_dir']
        assert 'url' in r
        assert r['url'] == repo_dict['url']

        assert r['path'] == os.path.join(r['parent_dir'], r['name'])

        if 'remotes' in repo_dict:
            assert isinstance(r['remotes'], list)
            for remote in r['remotes']:
                assert isinstance(remote, dict)
                assert 'remote_name' in remote
                assert 'url' in remote
Beispiel #30
0
def update_templates(template_url, dump_dir):
    repo = create_repo_from_pip_url(pip_url=template_url, repo_dir=dump_dir)
    repo.update_repo()
Beispiel #31
0
def git_repo(pip_url_kwargs):
    """Create an git repository for tests. Return repo."""
    git_repo = create_repo_from_pip_url(**pip_url_kwargs)
    git_repo.obtain()
    return git_repo
Beispiel #32
0
def git_repo(git_repo_kwargs):
    """Create an git repository for tests. Return repo."""
    git_repo = create_repo_from_pip_url(**git_repo_kwargs)
    git_repo.obtain(quiet=True)
    return git_repo
Beispiel #33
0
def git_repo(git_repo_kwargs):
    """Create an git repository for tests. Return repo."""
    git_repo = create_repo_from_pip_url(**git_repo_kwargs)
    git_repo.obtain(quiet=True)
    return git_repo