Fix event order problem

This commit is contained in:
R. Richard 2019-08-07 09:42:03 +02:00
parent e6d2777520
commit 1210a30c31

View File

@ -55,12 +55,14 @@ class InotifyContext:
def join(self, path): def join(self, path):
return join(self.workdir, path) return join(self.workdir, path)
def check_event(self, event_type, path): def check_event(self, event_type, paths):
self.missing_events += 1 if isinstance(paths, str):
paths = [paths]
self.missing_events += len(paths)
for _ in range(len(paths)):
event = self.event_to_queue[event_type].get(timeout=0.1) event = self.event_to_queue[event_type].get(timeout=0.1)
assert isinstance(event, event_type) assert isinstance(event, event_type)
assert event.src_path == path assert event.src_path in paths
return event
def check_empty(self, event_type): def check_empty(self, event_type):
with pytest.raises(Empty): with pytest.raises(Empty):
@ -128,10 +130,15 @@ def test_modify(context):
context.check_event(InotifyDirModifiedEvent, context.subdir) context.check_event(InotifyDirModifiedEvent, context.subdir)
assert context.check_any() assert context.check_any()
def test_move(context): def test_file_move(context):
rename(context.subfile, context.subfile + '_new')
context.check_event(InotifyFileMovedEvent, context.subfile)
assert context.check_any()
def test_folder_move(context):
remove(context.subfile)
rename(context.subdir, context.subdir + '_new') rename(context.subdir, context.subdir + '_new')
context.check_event(InotifyDirMovedEvent, context.subdir) context.check_event(InotifyDirMovedEvent, context.subdir)
context.check_event(InotifyFileMovedEvent, context.subfile)
assert context.check_any() assert context.check_any()
def test_delete(context): def test_delete(context):
@ -171,9 +178,8 @@ def test_exclude(context):
context.observer.exclude = None context.observer.exclude = None
def test_stress(context): def test_stress(context):
newfile = [] newfiles = []
for i in range(1024): for _ in range(1024):
newfile.append(context.create_random_file(context.subdir, '.txt')) newfiles.append(context.create_random_file(context.subdir, '.txt'))
for i in range(1024): context.check_event(InotifyFileCreatedEvent, newfiles)
context.check_event(InotifyFileCreatedEvent, newfile[i])
assert context.check_any() assert context.check_any()