Skip to content

Commit

Permalink
Merge pull request #378 from gerritholl/avoid-attributeerror
Browse files Browse the repository at this point in the history
Don't fail comparing FileInfo to other type
  • Loading branch information
olemke authored Oct 16, 2020
2 parents fa4137a + 66915db commit eaf4b3d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion typhon/files/handlers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ def __init__(self, path=None, times=None, attr=None):
self.attr = attr

def __eq__(self, other):
return self.path == other.path and self.times == other.times
return (isinstance(other, type(self))
and self.path == other.path
and self.times == other.times)

def __fspath__(self):
return self.path
Expand Down
30 changes: 30 additions & 0 deletions typhon/tests/files/test_fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,33 @@ def _repr_file_info(self, file_info):
return "FileInfo(\n\t{}, \t{}, \t{}),".format(
path, repr(file_info.times), repr(file_info.attr)
)

def test_compare_fileinfo(self):
"""Test comparing two FileInfo instances."""
f1 = FileInfo(
path="fake/path",
times=[datetime.datetime(1900, 1, 1, 0),
datetime.datetime(1900, 1, 1, 2)],
attr={})
f2 = FileInfo(
path="fake/path",
times=[datetime.datetime(1900, 1, 1, 0),
datetime.datetime(1900, 1, 1, 2)],
attr={})
f3 = FileInfo(
path="other/fake/path",
times=[datetime.datetime(1900, 1, 1, 0),
datetime.datetime(1900, 1, 1, 2)],
attr={})
f4 = FileInfo(
path="fake/path",
times=[datetime.datetime(1910, 1, 1, 0),
datetime.datetime(1910, 1, 1, 2)],
attr={})
assert f1 == f2
assert f1 != f3
assert f1 != f4
assert f2 != f3
assert f2 != f4
assert f3 != f4
assert f1 != "fake/path"

0 comments on commit eaf4b3d

Please sign in to comment.