mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-14 03:07:17 +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):
|
def _extract_files_from_paths(self):
|
||||||
files, paths = [], []
|
files, paths = [], []
|
||||||
for path in self._paths:
|
for path in self._paths:
|
||||||
|
path = abspath(path)
|
||||||
if isdir(path):
|
if isdir(path):
|
||||||
paths.append(path)
|
paths.append(path)
|
||||||
else:
|
else:
|
||||||
new_file = abspath(path)
|
paths.append(dirname(path))
|
||||||
files.append(new_file)
|
files.append(path)
|
||||||
paths.append(dirname(new_file))
|
|
||||||
self._files, self._paths = files, paths
|
self._files, self._paths = files, paths
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -120,7 +120,7 @@ class InotifyObserver:
|
|||||||
|
|
||||||
@patterns.setter
|
@patterns.setter
|
||||||
def patterns(self, patterns):
|
def patterns(self, patterns):
|
||||||
self._patterns = patterns
|
self._patterns = patterns or []
|
||||||
self._reset()
|
self._reset()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -5,7 +5,7 @@ from secrets import token_urlsafe
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from os import mkdir, rename
|
from os import mkdir, remove, rename
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
import watchdog
|
import watchdog
|
||||||
@ -140,11 +140,15 @@ def test_delete(context):
|
|||||||
|
|
||||||
def test_paths(context):
|
def test_paths(context):
|
||||||
context.observer.paths = context.subdir
|
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')
|
newfile = context.create_random_file(context.subdir, '.txt')
|
||||||
|
context.check_event(InotifyDirModifiedEvent, context.subdir)
|
||||||
context.check_event(InotifyFileCreatedEvent, newfile)
|
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()
|
assert context.check_any()
|
||||||
|
context.observer.paths = context.workdir
|
||||||
|
|
||||||
def test_patterns(context):
|
def test_patterns(context):
|
||||||
context.observer.patterns = ['*.txt']
|
context.observer.patterns = ['*.txt']
|
||||||
|
Loading…
Reference in New Issue
Block a user