Ejemplo n.º 1
0
    def test_equality_different_secret(self):
        """
        Test equality with an object having a different secret.
        """
        hidden1 = HiddenText('secret-1', redacted='****')
        hidden2 = HiddenText('secret-2', redacted='****')

        assert hidden1 != hidden2
        # Also test __eq__.
        assert not hidden1 == hidden2
Ejemplo n.º 2
0
    def test_equality_different_secret(self) -> None:
        """
        Test equality with an object having a different secret.
        """
        hidden1 = HiddenText("secret-1", redacted="****")
        hidden2 = HiddenText("secret-2", redacted="****")

        assert hidden1 != hidden2
        # Also test __eq__.
        assert not hidden1 == hidden2
Ejemplo n.º 3
0
    def test_equality_same_secret(self):
        """
        Test equality with an object having the same secret.
        """
        # Choose different redactions for the two objects.
        hidden1 = HiddenText('secret', redacted='****')
        hidden2 = HiddenText('secret', redacted='####')

        assert hidden1 == hidden2
        # Also test __ne__.
        assert not hidden1 != hidden2
Ejemplo n.º 4
0
    def test_equality_same_secret(self) -> None:
        """
        Test equality with an object having the same secret.
        """
        # Choose different redactions for the two objects.
        hidden1 = HiddenText("secret", redacted="****")
        hidden2 = HiddenText("secret", redacted="####")

        assert hidden1 == hidden2
        # Also test __ne__.
        assert not hidden1 != hidden2
Ejemplo n.º 5
0
def test_git_resolve_revision_rev_not_found(get_sha_mock: mock.Mock) -> None:
    get_sha_mock.return_value = (None, False)
    url = HiddenText("git+https://git.example.com", redacted="*")
    rev_options = Git.make_rev_options("develop")

    new_options = Git.resolve_revision(".", url, rev_options)
    assert new_options.rev == "develop"
Ejemplo n.º 6
0
def test_clone_without_partial_clone_support(script: PipTestEnvironment,
                                             tmp_path: pathlib.Path) -> None:
    """Older git clients don't support partial clone. Test the fallback path"""
    repo_path = tmp_path / "repo"
    repo_file = _initialize_clonetest_server(repo_path,
                                             script,
                                             enable_partial_clone=True)
    clone_path = repo_path / "clone1"

    # Check that we can clone w/ old version of git w/o --filter
    with patch("pip._internal.vcs.git.Git.get_git_version",
               return_value=(2, 16)):
        Git().fetch_new(
            str(clone_path),
            HiddenText(repo_path.as_uri(), redacted="*"),
            Git.make_rev_options(),
            verbosity=0,
        )

    repo_file.write_text("...")
    script.run("git", "commit", "-am", "third commit", cwd=str(repo_path))

    # Should work fine w/o attempting to use `--filter` args
    assert ("warning: filtering not recognized by server, ignoring"
            not in script.run("git", "pull", cwd=clone_path).stderr)
Ejemplo n.º 7
0
def test_resolve_commit_not_on_branch(script: PipTestEnvironment,
                                      tmp_path: pathlib.Path) -> None:
    repo_path = tmp_path / "repo"
    repo_file = repo_path / "file.txt"
    clone_path = repo_path / "clone"
    repo_path.mkdir()
    script.run("git", "init", cwd=str(repo_path))

    repo_file.write_text(".")
    script.run("git", "add", "file.txt", cwd=str(repo_path))
    script.run("git", "commit", "-m", "initial commit", cwd=str(repo_path))
    script.run("git", "checkout", "-b", "abranch", cwd=str(repo_path))

    # create a commit
    repo_file.write_text("..")
    script.run("git", "commit", "-a", "-m", "commit 1", cwd=str(repo_path))
    commit = script.run("git", "rev-parse", "HEAD",
                        cwd=str(repo_path)).stdout.strip()

    # make sure our commit is not on a branch
    script.run("git", "checkout", "master", cwd=str(repo_path))
    script.run("git", "branch", "-D", "abranch", cwd=str(repo_path))

    # create a ref that points to our commit
    (repo_path / ".git" / "refs" / "myrefs").mkdir(parents=True)
    (repo_path / ".git" / "refs" / "myrefs" / "myref").write_text(commit)

    # check we can fetch our commit
    rev_options = Git.make_rev_options(commit)
    Git().fetch_new(
        str(clone_path),
        HiddenText(repo_path.as_uri(), redacted="*"),
        rev_options,
        verbosity=0,
    )
Ejemplo n.º 8
0
 def test_basic(self):
     """
     Test str(), repr(), and attribute access.
     """
     hidden = HiddenText('my-secret', redacted='######')
     assert repr(hidden) == "<HiddenText '######'>"
     assert str(hidden) == '######'
     assert hidden.redacted == '######'
     assert hidden.secret == 'my-secret'
Ejemplo n.º 9
0
 def test_basic(self) -> None:
     """
     Test str(), repr(), and attribute access.
     """
     hidden = HiddenText("my-secret", redacted="######")
     assert repr(hidden) == "<HiddenText '######'>"
     assert str(hidden) == "######"
     assert hidden.redacted == "######"
     assert hidden.secret == "my-secret"
Ejemplo n.º 10
0
    def test_equality_with_str(self):
        """
        Test equality (and inequality) with str objects.
        """
        hidden = HiddenText('secret', redacted='****')

        # Test that the object doesn't compare equal to either its original
        # or redacted forms.
        assert hidden != hidden.secret
        assert hidden.secret != hidden

        assert hidden != hidden.redacted
        assert hidden.redacted != hidden
Ejemplo n.º 11
0
def test_partial_clone_without_server_support(
    script: PipTestEnvironment, tmp_path: pathlib.Path
) -> None:
    """Test partial clone w/ a git-server that does not support it"""
    repo_path = tmp_path / "repo"
    repo_file = _initialize_clonetest_server(
        repo_path, script, enable_partial_clone=False
    )
    clone_path1 = repo_path / "clone1"
    clone_path2 = repo_path / "clone2"

    commit = script.run("git", "rev-parse", "HEAD", cwd=str(repo_path)).stdout.strip()

    # Check that we can clone at HEAD
    Git().fetch_new(
        str(clone_path1),
        HiddenText(repo_path.as_uri(), redacted="*"),
        Git.make_rev_options(),
    )
    # Check that we can clone to commit
    Git().fetch_new(
        str(clone_path2),
        HiddenText(repo_path.as_uri(), redacted="*"),
        Git.make_rev_options(commit),
    )

    # Write some additional stuff to git pull
    repo_file.write_text(u"..")
    script.run("git", "commit", "-am", "second commit", cwd=str(repo_path))

    # Make sure git pull works - even though server doesn't support filtering
    assert (
        "warning: filtering not recognized by server, ignoring"
        in script.run("git", "pull", cwd=clone_path1).stderr
    )
    assert (
        "warning: filtering not recognized by server, ignoring"
        in script.run("git", "pull", cwd=clone_path2).stderr
    )
Ejemplo n.º 12
0
def test_git_resolve_revision_not_found_warning(
        get_sha_mock: mock.Mock, caplog: pytest.LogCaptureFixture) -> None:
    get_sha_mock.return_value = (None, False)
    url = HiddenText("git+https://git.example.com", redacted="*")
    sha = 40 * "a"
    rev_options = Git.make_rev_options(sha)

    # resolve_revision with a full sha would fail here because
    # it attempts a git fetch. This case is now covered by
    # test_resolve_commit_not_on_branch.

    rev_options = Git.make_rev_options(sha[:6])
    new_options = Git.resolve_revision(".", url, rev_options)
    assert new_options.rev == "aaaaaa"

    # Check that a warning got logged only for the abbreviated hash.
    messages = [r.getMessage() for r in caplog.records]
    messages = [msg for msg in messages if msg.startswith("Did not find ")]
    assert messages == [
        "Did not find branch or tag 'aaaaaa', assuming revision or ref."
    ]