Skip to content

Commit

Permalink
fix issue pytest-dev#303
Browse files Browse the repository at this point in the history
Implements __eq__ and __ne__ methods on teh File object.
If both objects are files, the paths are getting compared,
if the other object is a string it's compared with the path directly.
  • Loading branch information
barnabasJ committed May 29, 2018
1 parent de4df2e commit f10bbcb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ def test_file(host):
assert l.is_symlink
assert l.is_file
assert l.linked_to == "/d/f"
assert l.linked_to == f
assert f == f
assert not d == f

host.check_output("rm -f /d/p && mkfifo /d/p")
assert host.file("/d/p").is_pipe
Expand Down
10 changes: 10 additions & 0 deletions testinfra/modules/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ def size(self):
def __repr__(self):
return "<file %s>" % (self.path,)

def __eq__(self, other):
if isinstance(other, File):
return self.path == other.path
elif isinstance(other, str):
return self.path == other
return False

def __ne__(self, other):
return not self.__eq__(other)

@classmethod
def get_module_class(cls, host):
if host.system_info.type == "linux":
Expand Down

0 comments on commit f10bbcb

Please sign in to comment.