def observer2(): obs = BaseObserver(EventEmitter) yield obs obs.stop() try: obs.join() except RuntimeError: pass
def test_basic(self): observer = BaseObserver(EventEmitter) handler = LoggingEventHandler() watch = observer.schedule(handler, "/foobar", True) observer.add_handler_for_watch(handler, watch) observer.add_handler_for_watch(handler, watch) observer.remove_handler_for_watch(handler, watch) self.assertRaises(KeyError, observer.remove_handler_for_watch, handler, watch) observer.unschedule(watch) self.assertRaises(KeyError, observer.unschedule, watch) watch = observer.schedule(handler, "/foobar", True) observer.event_queue.put((FileModifiedEvent("/foobar"), watch)) observer.start() time.sleep(1) observer.unschedule_all() observer.stop()
def test_basic(self): observer = BaseObserver(EventEmitter) handler = LoggingEventHandler() watch = observer.schedule(handler, '/foobar', True) observer.add_handler_for_watch(handler, watch) observer.add_handler_for_watch(handler, watch) observer.remove_handler_for_watch(handler, watch) self.assertRaises(KeyError, observer.remove_handler_for_watch, handler, watch) observer.unschedule(watch) self.assertRaises(KeyError, observer.unschedule, watch) watch = observer.schedule(handler, '/foobar', True) observer.event_queue.put((FileModifiedEvent('/foobar'), watch)) observer.start() time.sleep(1) observer.unschedule_all() observer.stop()
def test_observer_basic(): observer = BaseObserver(EventEmitter) handler = LoggingEventHandler() watch = observer.schedule(handler, '/foobar', True) observer.add_handler_for_watch(handler, watch) observer.add_handler_for_watch(handler, watch) observer.remove_handler_for_watch(handler, watch) with pytest.raises(KeyError): observer.remove_handler_for_watch(handler, watch) observer.unschedule(watch) with pytest.raises(KeyError): observer.unschedule(watch) watch = observer.schedule(handler, '/foobar', True) observer.event_queue.put((FileModifiedEvent('/foobar'), watch)) observer.start() time.sleep(1) observer.unschedule_all() observer.stop()
def observer2(): obs = BaseObserver(EventEmitter) yield obs obs.stop() with contextlib.suppress(RuntimeError): obs.join()
def observer2(): obs = BaseObserver(EventEmitter) yield obs obs.stop()