github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/python-wrapper/tests/integration/test_reference.py (about) 1 import lakefs 2 3 4 def test_reference_log(setup_branch_with_commits): 5 branch = setup_branch_with_commits 6 7 for i, c in enumerate(branch.log(max_amount=199)): 8 assert c.message == f"commit {i}" 9 10 commits = list(branch.log(max_amount=2000)) 11 for i, c in enumerate(commits[:-1]): # Ignore initial commit 12 assert c.message == f"commit {i}" 13 assert len(commits) == 200 14 15 assert len(list(branch.log(limit=True, amount=10, max_amount=100))) == 10 16 17 18 def test_reference_diff(setup_branch_with_commits): 19 branch = setup_branch_with_commits 20 21 commits = list(branch.log(max_amount=2)) 22 assert len(list(branch.diff(branch.get_commit().id))) == 0 23 changes = list(branch.diff(commits[0].id, type="two_dot")) 24 assert len(changes) == 0 25 26 changes = list(branch.diff(commits[1].id, type="two_dot")) 27 assert len(changes) == 1 28 assert changes[0].path == "test1" 29 assert changes[0].type == "removed" 30 31 other_branch = lakefs.Repository(branch.repo_id).branch("other_branch").create("test_branch") 32 other_branch.object("prefix1/test1").upload(data="data1") 33 other_branch.object("prefix2/test2").upload(data="data2") 34 other_branch.commit("other commit") 35 36 changes = list(branch.diff(other_branch)) 37 assert len(changes) == 2 38 39 changes = list(branch.diff(other_branch, prefix="prefix2")) 40 assert len(changes) == 1 41 assert changes[0].path == "prefix2/test2" 42 assert changes[0].type == "added" 43 44 45 def test_reference_merge_into(setup_branch_with_commits): 46 branch = setup_branch_with_commits 47 repo = lakefs.Repository(branch.repo_id) 48 main = repo.branch("main") 49 50 commits = list(branch.log(max_amount=2)) 51 other_branch = repo.branch("test_reference_merge_into").create(main) 52 ref = repo.ref(commits[1].id) 53 ref.merge_into(other_branch, message="Merge1") 54 assert other_branch.get_commit().message == "Merge1" 55 assert list(other_branch.log(max_amount=2))[1].id == commits[1].id 56 57 branch.merge_into(other_branch.id, message="Merge2") 58 assert other_branch.get_commit().message == "Merge2" 59 assert list(other_branch.log(max_amount=3))[2].id == commits[0].id 60 61 62 def test_reference_objects(setup_repo): 63 _, repo = setup_repo 64 test_branch = repo.branch("main") 65 path_and_data = ["a", "b", "bar/a", "bar/b", "bar/c", "c", "foo/a", "foo/b", "foo/c"] 66 for s in path_and_data: 67 test_branch.object(s).upload(s) 68 69 objects = list(test_branch.objects()) 70 assert len(objects) == len(path_and_data) 71 for obj in objects: 72 assert obj.path in path_and_data 73 74 expected = ["a", "b", "bar/", "c", "foo/"] 75 i = 0 76 for obj in test_branch.objects(delimiter='/'): 77 i += 1 78 assert obj.path in expected 79 80 assert i == len(expected)