diff --git a/lib/tfw/components/inotify/inotify.py b/lib/tfw/components/inotify/inotify.py index 4e2d1dd..a989f83 100644 --- a/lib/tfw/components/inotify/inotify.py +++ b/lib/tfw/components/inotify/inotify.py @@ -97,12 +97,12 @@ class InotifyObserver: def _extract_files_from_paths(self): files, paths = [], [] for path in self._paths: + path = abspath(path) if isdir(path): paths.append(path) else: - new_file = abspath(path) - files.append(new_file) - paths.append(dirname(new_file)) + paths.append(dirname(path)) + files.append(path) self._files, self._paths = files, paths @property @@ -120,7 +120,7 @@ class InotifyObserver: @patterns.setter def patterns(self, patterns): - self._patterns = patterns + self._patterns = patterns or [] self._reset() @property diff --git a/lib/tfw/components/inotify/test_inotify.py b/lib/tfw/components/inotify/test_inotify.py index c6d0e12..aa910fe 100644 --- a/lib/tfw/components/inotify/test_inotify.py +++ b/lib/tfw/components/inotify/test_inotify.py @@ -5,7 +5,7 @@ from secrets import token_urlsafe from pathlib import Path from shutil import rmtree from os.path import join -from os import mkdir, rename +from os import mkdir, remove, rename from tempfile import TemporaryDirectory import watchdog @@ -140,11 +140,15 @@ def test_delete(context): def test_paths(context): context.observer.paths = context.subdir - context.create_random_folder(context.workdir) + newdir = context.create_random_folder(context.workdir) newfile = context.create_random_file(context.subdir, '.txt') + context.check_event(InotifyDirModifiedEvent, context.subdir) context.check_event(InotifyFileCreatedEvent, newfile) - context.observer.paths = context.subdir + context.observer.paths = [newdir, newfile] + remove(newfile) + context.check_event(InotifyFileDeletedEvent, newfile) assert context.check_any() + context.observer.paths = context.workdir def test_patterns(context): context.observer.patterns = ['*.txt']