mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-09 01:17:16 +00:00
Refactor Inotify
This commit is contained in:
parent
da19769362
commit
44a1433d3b
@ -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
|
||||
|
@ -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']
|
||||
|
Loading…
Reference in New Issue
Block a user