Skip to content

Commit

Permalink
[inotify] Fix not equality implementation for InotifyEvent
Browse files Browse the repository at this point in the history
Credits goes to @JanzenLiu.

Closes #848.
  • Loading branch information
BoboTiG committed Dec 15, 2021
1 parent 61d8f86 commit 5f89548
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion changelog.rst
Expand Up @@ -9,7 +9,8 @@ Changelog
2021-xx-xx • `full history <https://github.com/gorakhargosh/watchdog/compare/v2.1.6...master>`__

- Eliminate timeout in waiting on event queue. (`#861 <https://github.com/gorakhargosh/watchdog/pull/861>`_)
- Thanks to our beloved contributors: @sattlerc
- [inotify] Fix ``not`` equality implementation for ``InotifyEvent``. (`#848 <https://github.com/gorakhargosh/watchdog/pull/848>`_)
- Thanks to our beloved contributors: @sattlerc, @JanzenLiu, @BoboTiG

2.1.6
~~~~~
Expand Down
2 changes: 1 addition & 1 deletion src/watchdog/observers/inotify_c.py
Expand Up @@ -541,7 +541,7 @@ def __eq__(self, inotify_event):
return self.key == inotify_event.key

def __ne__(self, inotify_event):
return self.key == inotify_event.key
return self.key != inotify_event.key

def __hash__(self):
return hash(self.key)
Expand Down
17 changes: 16 additions & 1 deletion tests/test_inotify_c.py
Expand Up @@ -17,7 +17,7 @@
from watchdog.events import DirCreatedEvent, DirDeletedEvent, DirModifiedEvent
from watchdog.observers.api import ObservedWatch
from watchdog.observers.inotify import InotifyFullEmitter, InotifyEmitter
from watchdog.observers.inotify_c import Inotify, InotifyConstants
from watchdog.observers.inotify_c import Inotify, InotifyConstants, InotifyEvent

from .shell import mkdtemp, rm

Expand Down Expand Up @@ -187,3 +187,18 @@ def test_watch_file():
os.remove(path)
event, _ = event_queue.get(timeout=5)
assert repr(event)


def test_event_equality():
wd_parent_dir = 42
filename = "file.ext"
full_path = p(filename)
event1 = InotifyEvent(
wd_parent_dir, InotifyConstants.IN_CREATE, 0, filename, full_path)
event2 = InotifyEvent(
wd_parent_dir, InotifyConstants.IN_CREATE, 0, filename, full_path)
event3 = InotifyEvent(
wd_parent_dir, InotifyConstants.IN_ACCESS, 0, filename, full_path)
assert event1 == event2
assert event1 != event3
assert event2 != event3

0 comments on commit 5f89548

Please sign in to comment.