Esempio n. 1
0
 def to_bp(self) -> pfs_proto.Commit:
     """Converts itself into a Betterproto ``Commit``."""
     return pfs_proto.Commit(
         id=self.id,
         branch=pfs_proto.Branch(
             repo=pfs_proto.Repo(name=self.repo, type=self.repo_type),
             name=self.branch,
         ),
     )
Esempio n. 2
0
def test_drop_commit():
    client, repo_name = sandbox("drop_commit")
    repo2_name = util.create_test_repo(client, "drop_commit2")

    # Create provenance between repos (which creates an auto commit)
    client.create_branch(
        repo2_name,
        "master",
        provenance=[
            pfs_proto.Branch(
                repo=pfs_proto.Repo(name=repo_name, type="user"), name="master"
            )
        ],
    )
    # Head commit is still open in repo2
    client.finish_commit((repo2_name, "master"))

    with client.commit(repo_name, "master"):
        pass
    client.finish_commit((repo2_name, "master"))

    with client.commit(repo_name, "master") as commit2:
        pass
    client.finish_commit((repo2_name, "master"))

    client.wait_commit(commit2.id)

    commits = list(client.list_commit(repo_name))
    assert len(commits) == 2

    client.drop_commit(commit2.id)
    commits = list(client.list_commit(repo_name))
    assert len(commits) == 1

    commits = list(client.list_commit(repo2_name))
    assert len(commits) == 0  # since list_commit defaults to user commits
    commits = list(
        client.list_commit(repo2_name, origin_kind=pfs_proto.OriginKind.AUTO)
    )
    assert len(commits) == 2
Esempio n. 3
0
def test_wait_commit():
    """
    Ensure wait_commit works
    """
    client, repo_name = sandbox("wait_commit")
    repo2_name = util.create_test_repo(client, "wait_commit2")

    # Create provenance between repos (which creates a new commit)
    client.create_branch(
        repo2_name,
        "master",
        provenance=[
            pfs_proto.Branch(
                repo=pfs_proto.Repo(name=repo_name, type="user"), name="master"
            )
        ],
    )
    # Head commit is still open in repo2
    client.finish_commit((repo2_name, "master"))

    with client.commit(repo_name, "master") as c:
        client.put_file_bytes(c, "input.json", b"hello world")
    client.finish_commit((repo2_name, "master"))

    # Just block until all of the commits are yielded
    commits = client.wait_commit(c.id)
    assert len(commits) == 2
    assert commits[1].finished

    with client.commit(repo_name, "master") as c2:
        client.put_file_bytes(c2, "input.json", b"bye world")
    client.finish_commit((repo2_name, "master"))

    # Just block until the commit in repo1 is finished
    commits = client.wait_commit(c2)
    assert len(commits) == 1
    assert commits[0].finished

    files = list(client.list_file(c2, "/"))
    assert len(files) == 1
Esempio n. 4
0
def test_inspect_commit():
    client, repo_name = sandbox("inspect_commit")
    repo2_name = util.create_test_repo(client, "inspect_commit2")

    # Create provenance between repos (which creates a new commit)
    client.create_branch(
        repo2_name,
        "master",
        provenance=[
            pfs_proto.Branch(
                repo=pfs_proto.Repo(name=repo_name, type="user"), name="master"
            )
        ],
    )
    # Head commit is still open in repo2
    client.finish_commit((repo2_name, "master"))

    with client.commit(repo_name, "master") as c:
        client.put_file_bytes(c, "input.json", b"hello world")
    client.finish_commit((repo2_name, "master"))

    # Inspect commit at a specific repo
    commits = list(client.inspect_commit(c, pfs_proto.CommitState.FINISHED))
    assert len(commits) == 1

    commit = commits[0]
    assert commit.commit.branch.name == "master"
    assert commit.finished
    assert commit.description == ""
    # assert commit.size_bytes == 11
    assert len(commit.commit.id) == 32
    assert commit.commit.branch.repo.name == repo_name

    # Inspect entire commit
    commits = list(client.inspect_commit(c.id, pfs_proto.CommitState.FINISHED))
    assert len(commits) == 2
Esempio n. 5
0
 def create_repo_request():
     return transaction_proto.TransactionRequest(
         create_repo=pfs_proto.CreateRepoRequest(
             repo=pfs_proto.Repo(name=util.test_repo_name("test_batch_transaction"))
         )
     )