dsoprea / PyInotify

An efficient and elegant inotify (Linux filesystem activity monitor) library for Python. Python 2 and 3 compatible.
GNU General Public License v2.0
245 stars 73 forks source link

event_names should be a SET. Cleaner and testsuite more robust #41

Open jcea opened 6 years ago

jcea commented 6 years ago

Currently many tests are failing because event_names like "['IN_CREATE', 'IN_ISDIR']" do not garantee ordering, so the "assertEqual()" fails.

This could be solved using a SET, and the result is cleaner because order names in an event is irrelevant (they are actually flags).

When running the tests now I get trivial errors like:

...
======================================================================
FAIL: test__renames (tests.test_inotify.TestInotifyTree)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/PyInotify/tests/test_inotify.py", line 235, in test__renames
    self.assertEquals(events1, expected)
AssertionError: Lists differ: [(_IN[52 chars], ['IN_CREATE', 'IN_ISDIR'], '/tmp/tmpfgwdg1uf', 'old_folder')] != [(_IN[52 chars], ['IN_ISDIR', 'IN_CREATE'], '/tmp/tmpfgwdg1uf', 'old_folder')]

First differing element 0:
(_INO[50 chars]), ['IN_CREATE', 'IN_ISDIR'], '/tmp/tmpfgwdg1uf', 'old_folder')
(_INO[50 chars]), ['IN_ISDIR', 'IN_CREATE'], '/tmp/tmpfgwdg1uf', 'old_folder')

  [(_INOTIFY_EVENT(wd=1, mask=1073742080, cookie=0, len=16),
-   ['IN_CREATE', 'IN_ISDIR'],
+   ['IN_ISDIR', 'IN_CREATE'],
    '/tmp/tmpfgwdg1uf'
...

I could submit a patch if you want.

blag commented 6 years ago

This makes total sense, please submit a PR!