Example #1
0
def test_rev_options_to_display() -> None:
    """
    Test RevOptions.to_display().
    """
    # The choice of VersionControl class doesn't matter here since
    # the implementation is the same for all of them.
    rev_options = RevOptions(Git)
    assert rev_options.to_display() == ""

    rev_options = RevOptions(Git, "master")
    assert rev_options.to_display() == " (to revision master)"
Example #2
0
def test_rev_options_to_args(
    vc_class: Type[VersionControl],
    expected1: List[str],
    expected2: List[str],
    kwargs: Dict[str, Any],
) -> None:
    """
    Test RevOptions.to_args().
    """
    assert RevOptions(vc_class, **kwargs).to_args() == expected1
    assert RevOptions(vc_class, "123", **kwargs).to_args() == expected2
Example #3
0
 def test_fetch_new_revision(self):
     rev_options = RevOptions(Subversion, '123')
     self.svn.fetch_new(self.dest, self.url, rev_options)
     self.assert_call_args([
         'svn', 'checkout', '-q', '--non-interactive', '-r', '123',
         'svn+http://username:[email protected]/', '/tmp/test'
     ])
Example #4
0
    def _install_gist(self, fullname, gist_hash):
        repo_path = os.path.join(self.clone_path, gist_hash)

        #if not self._is_installed(fullname):
        url = "https://gist.github.com/%s.git" % (gist_hash, )

        self._ensure_clone_path_present()

        repo_path = os.path.join(self.clone_path, gist_hash)
        git = vcs.get_backend_for_scheme("git+https")
        if not os.path.exists(repo_path):
            logger.debug("Cloning %s to %s", url, repo_path)
            git.fetch_new(repo_path, url, RevOptions(git, "master"))
        else:
            logger.debug("Updating %s from %s", repo_path, url)
            git.update(repo_path, url, RevOptions(git, "master"))

        return repo_path
Example #5
0
    def setUp(self):
        patcher = patch('pip._internal.vcs.versioncontrol.call_subprocess')
        self.addCleanup(patcher.stop)
        self.call_subprocess_mock = patcher.start()

        # Test Data.
        self.url = 'svn+http://username:[email protected]/'
        # use_interactive is set to False to test that remote call options are
        # properly added.
        self.svn = Subversion(use_interactive=False)
        self.rev_options = RevOptions(Subversion)
        self.dest = '/tmp/test'
Example #6
0
def test_rev_options_make_new() -> None:
    """
    Test RevOptions.make_new().
    """
    # The choice of VersionControl class doesn't matter here since
    # the implementation is the same for all of them.
    rev_options = RevOptions(Git, "master", extra_args=["foo", "bar"])
    new_options = rev_options.make_new("develop")

    assert new_options is not rev_options
    assert new_options.extra_args == ["foo", "bar"]
    assert new_options.rev == "develop"
    assert new_options.vc_class is Git
Example #7
0
def test_rev_options_make_new():
    """
    Test RevOptions.make_new().
    """
    # The choice of VersionControl class doesn't matter here since
    # the implementation is the same for all of them.
    rev_options = RevOptions(Git, 'master', extra_args=['foo', 'bar'])
    new_options = rev_options.make_new('develop')

    assert new_options is not rev_options
    assert new_options.extra_args == ['foo', 'bar']
    assert new_options.rev == 'develop'
    assert new_options.vc_class is Git
Example #8
0
    def _install_module(self, modulename):
        self._ensure_clone_path_present()

        modulename = modulename.replace("_minus_", "-")
        module_path = modulename.replace(".", "/")

        # TODO: might use hash of url instead of ns, because ns could be registered dynamically
        repo_path = os.path.join(self.clone_path, self.ns, module_path)
        Path(repo_path).mkdir(parents=True, exist_ok=True)

        url = self.url % (modulename, )

        git = vcs.get_backend_for_scheme("git+https")
        if not os.path.exists(os.path.join(repo_path, ".git")):
            logger.debug("Cloning %s to %s", url, repo_path)
            git.fetch_new(repo_path, url, RevOptions(git, "master"))
        else:
            # TODO: should throttle here
            logger.debug("Updating %s from %s", repo_path, url)
            git.update(repo_path, url, RevOptions(git, "master"))

        return repo_path
Example #9
0
 def test_fetch_new_revision(self) -> None:
     rev_options = RevOptions(Subversion, "123")
     self.svn.fetch_new(self.dest, hide_url(self.url), rev_options)
     self.assert_call_args(
         [
             "svn",
             "checkout",
             "-q",
             "--non-interactive",
             "-r",
             "123",
             hide_url("svn+http://username:[email protected]/"),
             "/tmp/test",
         ]
     )
Example #10
0
def test_rev_options_repr() -> None:
    rev_options = RevOptions(Git, "develop")
    assert repr(rev_options) == "<RevOptions git: rev='develop'>"
Example #11
0
def test_rev_options_to_args(vc_class, expected1, expected2, kwargs):
    """
    Test RevOptions.to_args().
    """
    assert RevOptions(vc_class, **kwargs).to_args() == expected1
    assert RevOptions(vc_class, '123', **kwargs).to_args() == expected2
Example #12
0
def test_rev_options_repr():
    rev_options = RevOptions(Git, 'develop')
    assert repr(rev_options) == "<RevOptions git: rev='develop'>"