diff --git a/swh/provenance/model.py b/swh/provenance/model.py --- a/swh/provenance/model.py +++ b/swh/provenance/model.py @@ -141,6 +141,20 @@ def __str__(self): return f"" + def __eq__(self, other): + sameFiles = (self._files is None and other._files is None) or ( + set(self._files) == set(other._files) + ) + sameDirs = (self._dirs is None and other._dirs is None) or ( + set(self._dirs) == set(other._dirs) + ) + return ( + isinstance(other, DirectoryEntry) + and (self.id, self.name) == (other.id, other.name) + and sameFiles + and sameDirs + ) + class FileEntry: def __init__(self, id: bytes, name: bytes): @@ -149,3 +163,9 @@ def __str__(self): return f"" + + def __eq__(self, other): + return isinstance(other, FileEntry) and (self.id, self.name) == ( + other.id, + other.name, + ) diff --git a/swh/provenance/provenance.py b/swh/provenance/provenance.py --- a/swh/provenance/provenance.py +++ b/swh/provenance/provenance.py @@ -314,6 +314,22 @@ self.children.append(node) return node + def __eq__(self, other): + sameDbDate = ( + self._dbdate is None and other._dbdate is None + ) or self._dbdate == other._dbdate + sameMaxdate = ( + self.maxdate is None and other.maxdate is None + ) or self.maxdate == other.maxdate + return ( + isinstance(other, IsochroneNode) + and (self.entry, self.depth, self.known, self.path) + == (other.entry, other.depth, other.known, other.path) + and sameDbDate + and sameMaxdate + and set(self.children) == set(other.children) + ) + def build_isochrone_graph( archive: ArchiveInterface,