Skip to content

Commit

Permalink
test diff of non unique hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Northo committed Aug 9, 2024
1 parent 1f0bb3c commit 4278ea5
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/index/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,57 @@ def test_diff():
}


def test_diff_non_unique_hash():
"""Test rename when multiple entries share the same hash."""
def entry(key):
return DataIndexEntry(
key=key,
meta=Meta(),
hash_info=HashInfo(name="md5", value="d3b07384d113edec49eaa6238ad5ff00"),
)

old_foo_entry = entry(("foo",))
old_bar_entry = entry(("bar",))
old_baz_entry = entry(("baz",))
old = DataIndex({
("foo",): old_foo_entry,
("bar",): old_bar_entry,
("baz",): old_baz_entry,
})

assert set(diff(old, old, with_unchanged=True)) == {
Change(UNCHANGED, old_foo_entry, old_foo_entry),
Change(UNCHANGED, old_bar_entry, old_bar_entry),
Change(UNCHANGED, old_baz_entry, old_baz_entry),
}
assert set(diff(old, old, with_renames=True, with_unchanged=True)) == {
Change(UNCHANGED, old_foo_entry, old_foo_entry),
Change(UNCHANGED, old_bar_entry, old_bar_entry),
Change(UNCHANGED, old_baz_entry, old_baz_entry),
}

new_foo_entry = entry(("my","new", "foo",))
new_bar_entry = entry(("new", "bar",))
new = DataIndex({
("my", "new", "foo",): new_foo_entry,
("new", "bar",): new_bar_entry,
("baz",): old_baz_entry,
})

assert set(diff(old, new, with_unchanged=True)) == {
Change(ADD, None, new_foo_entry),
Change(DELETE, old_foo_entry, None),
Change(ADD, None, new_bar_entry),
Change(DELETE, old_bar_entry, None),
Change(UNCHANGED, old_baz_entry, old_baz_entry),
}
assert set(diff(old, new, with_renames=True, with_unchanged=True)) == {
Change(RENAME, old_foo_entry, new_foo_entry),
Change(RENAME, old_bar_entry, new_bar_entry),
Change(UNCHANGED, old_baz_entry, old_baz_entry),
}


def test_diff_no_hashes():
index = DataIndex(
{
Expand Down

0 comments on commit 4278ea5

Please sign in to comment.