def start_watching(path=None): path = p('') if path is None else path global emitter emitter = Emitter(event_queue, ObservedWatch(path, recursive=True)) if platform.is_darwin(): # FSEvents will report old evens (like create for mkdtemp in test # setup. Waiting for a considerable time seems to 'flush' the events. time.sleep(10) emitter.start()
def test_passing_bytes_should_give_bytes(p): path = p('').encode() event_queue = Queue() emitter = Emitter(event_queue, ObservedWatch(path, recursive=True)) emitter.start() touch(p('a')) event = event_queue.get(timeout=5)[0] assert isinstance(event.src_path, bytes)
def _setup_emitter(path): event_queue = Queue() if platform.is_darwin(): # FSEvents will report old evens (like create for mkdtemp in test # setup. Waiting for a considerable time seems to 'flush' the events. time.sleep(10) emitter = Emitter(event_queue, ObservedWatch(path, recursive=True)) emitter.start() return event_queue, emitter
def test_passing_bytes_should_give_bytes(p): from watchdog.utils.unicode_paths import bytes_cls path = bytes_cls(p(''), 'ascii') assert isinstance(p(''), bytes_cls) event_queue = Queue() emitter = Emitter(event_queue, ObservedWatch(path, recursive=True)) emitter.start() touch(p('a')) event = event_queue.get(timeout=5)[0] assert isinstance(event.src_path, bytes_cls)
def makeEmitter(self, path=None): """ Return a new emitter monitoring `path`. """ return InotifyEmitter( event_queue=self.emitter_queue, watch=self.ObservedWatch(path=path), timeout=0, )
def test_close_clean(tmpdir): """ On InotifyBuffer.close() InotifyBuffer.read_event() is un-blocked so that Inotify thread waiting for it can be closed. This is also a test for Inotify.queue_events handling of STOP_EVENT and InotifyBuffer.close() is test as side effect of Inotify.stop() """ watch = ObservedWatch(path=tmpdir, recursive=False) emitter = InotifyEmitter([], watch) emitter.start() emitter.stop() emitter.join(1) assert not emitter.isAlive()