Refactor Inotify

This commit is contained in:
R. Richard 2019-06-27 17:38:53 +02:00 committed by Kristóf Tóth
parent da19769362
commit 44a1433d3b
2 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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']