diff --git a/changelog.rst b/changelog.rst index a8212125..5f0e7ddd 100644 --- a/changelog.rst +++ b/changelog.rst @@ -9,7 +9,8 @@ Changelog 2021-xx-xx • `full history `__ - Eliminate timeout in waiting on event queue. (`#861 `_) -- Thanks to our beloved contributors: @sattlerc +- [inotify] Fix ``not`` equality implementation for ``InotifyEvent``. (`#848 `_) +- Thanks to our beloved contributors: @sattlerc, @JanzenLiu, @BoboTiG 2.1.6 ~~~~~ diff --git a/src/watchdog/observers/inotify_c.py b/src/watchdog/observers/inotify_c.py index c297c67d..a4bbddbf 100644 --- a/src/watchdog/observers/inotify_c.py +++ b/src/watchdog/observers/inotify_c.py @@ -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) diff --git a/tests/test_inotify_c.py b/tests/test_inotify_c.py index 274fb6c1..50090ead 100644 --- a/tests/test_inotify_c.py +++ b/tests/test_inotify_c.py @@ -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 @@ -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