Ejemplo n.º 1
0
def add_doctest_fixtures(
    doctest_namespace: dict[str, Any],
    tmp_path: pathlib.Path,
    home_default: pathlib.Path,
    gitconfig: pathlib.Path,
    create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
    create_svn_remote_repo: CreateProjectCallbackFixtureProtocol,
    create_hg_remote_repo: CreateProjectCallbackFixtureProtocol,
    git_repo: pathlib.Path,
) -> None:
    doctest_namespace["tmp_path"] = tmp_path
    if which("git"):
        doctest_namespace["gitconfig"] = gitconfig
        doctest_namespace["create_git_remote_repo"] = functools.partial(
            create_git_remote_repo,
            remote_repo_post_init=git_remote_repo_single_commit_post_init,
        )
        doctest_namespace[
            "create_git_remote_repo_bare"] = create_git_remote_repo
        doctest_namespace["git_local_clone"] = git_repo
    if which("svn"):
        doctest_namespace["create_svn_remote_repo"] = create_svn_remote_repo
    if which("hg"):
        doctest_namespace["create_hg_remote_repo_bare"] = create_hg_remote_repo
        doctest_namespace["create_hg_remote_repo"] = functools.partial(
            create_hg_remote_repo,
            remote_repo_post_init=hg_remote_repo_single_commit_post_init,
        )
Ejemplo n.º 2
0
def pytest_ignore_collect(path: LocalPath, config: pytest.Config) -> bool:
    if not which("svn") and any(needle in path
                                for needle in ["svn", "subversion"]):
        return True
    if not which("git") and "git" in path:
        return True
    if not which("hg") and any(needle in path
                               for needle in ["hg", "mercurial"]):
        return True

    return False
Ejemplo n.º 3
0
import pathlib
import shutil
import textwrap
from typing import Any, Optional, Protocol

import pytest
from py._path.local import LocalPath

from faker import Faker

from libvcs._internal.run import run, which
from libvcs.projects.git import GitProject, GitRemote
from libvcs.projects.hg import MercurialProject
from libvcs.projects.svn import SubversionProject

skip_if_git_missing = pytest.mark.skipif(not which("git"),
                                         reason="git is not available")
skip_if_svn_missing = pytest.mark.skipif(not which("svn"),
                                         reason="svn is not available")
skip_if_hg_missing = pytest.mark.skipif(not which("hg"),
                                        reason="hg is not available")


def pytest_ignore_collect(path: LocalPath, config: pytest.Config) -> bool:
    if not which("svn") and any(needle in path
                                for needle in ["svn", "subversion"]):
        return True
    if not which("git") and "git" in path:
        return True
    if not which("hg") and any(needle in path
                               for needle in ["hg", "mercurial"]):
Ejemplo n.º 4
0
import pytest

from pytest_mock import MockerFixture

from libvcs import exc
from libvcs._internal.run import run, which
from libvcs._internal.shortcuts import create_project
from libvcs.conftest import CreateProjectCallbackFixtureProtocol
from libvcs.projects.git import (
    GitProject,
    GitRemote,
    GitStatus,
    convert_pip_url as git_convert_pip_url,
)

if not which("git"):
    pytestmark = pytest.mark.skip(reason="git is not available")

ProjectTestFactory = Callable[..., GitProject]
ProjectTestFactoryLazyKwargs = Callable[..., dict]
ProjectTestFactoryRemoteLazyExpected = Callable[..., Dict[str, GitRemote]]


@pytest.mark.parametrize(
    # Postpone evaluation of options so fixture variables can interpolate
    "constructor,lazy_constructor_options",
    [
        [
            GitProject,
            lambda bare_dir, tmp_path, **kwargs: {
                "url": f"file://{bare_dir}",
Ejemplo n.º 5
0
def test_which_no_hg_found(monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setenv("PATH", "/")
    which("hg")
    which("hg", "/")
Ejemplo n.º 6
0
"""Tests for libvcs hg repos."""
import pathlib

import pytest

from libvcs._internal.run import run, which
from libvcs._internal.shortcuts import create_project

if not which("hg"):
    pytestmark = pytest.mark.skip(reason="hg is not available")


def test_repo_mercurial(
    tmp_path: pathlib.Path,
    projects_path: pathlib.Path,
    hg_remote_repo: pathlib.Path,
) -> None:
    repo_name = "my_mercurial_project"

    mercurial_repo = create_project(
        url=f"file://{hg_remote_repo}",
        dir=projects_path / repo_name,
        vcs="hg",
    )

    run(["hg", "init", mercurial_repo.repo_name], cwd=tmp_path)

    mercurial_repo.update_repo()

    test_repo_revision = run(
        ["hg", "parents", "--template={rev}"], cwd=projects_path / repo_name
Ejemplo n.º 7
0
"""tests for libvcs svn repos."""
import os
import pathlib

import pytest

from libvcs._internal.run import which
from libvcs.conftest import CreateProjectCallbackFixtureProtocol
from libvcs.projects.svn import SubversionProject

if not which("svn"):
    pytestmark = pytest.mark.skip(reason="svn is not available")


def test_repo_svn(tmp_path: pathlib.Path,
                  svn_remote_repo: pathlib.Path) -> None:
    repo_name = "my_svn_project"

    svn_repo = SubversionProject(
        url=f"file://{svn_remote_repo}",
        dir=str(tmp_path / 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(tmp_path / repo_name)