Пример #1
0
    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()
Пример #3
0
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()