示例#1
0
def start_watching(path=None, use_full_emitter=False):
    global emitter
    path = p("") if path is None else path
    emitter = FSEventsEmitter(event_queue,
                              ObservedWatch(path, recursive=True),
                              suppress_history=True)
    emitter.start()
 def start(self):
     sleep(0.5)
     self.event_queue = queue.Queue()
     global temp_dir
     self.watch = ObservedWatch(temp_dir, True)
     self.emitter = Emitter(self.event_queue, self.watch, timeout=0.2)
     self.emitter.start()
     sleep(0.5)
 def start(self):
   sleep(0.5)
   self.event_queue = queue.Queue()
   global temp_dir
   self.watch = ObservedWatch(temp_dir, True)
   self.emitter = Emitter(self.event_queue, self.watch, timeout=0.2)
   self.emitter.start()
   sleep(0.5)
示例#4
0
def start_watching(path=None, use_full_emitter=False):
    global emitter
    path = p("") if path is None else path
    emitter = FSEventsEmitter(event_queue, ObservedWatch(path, recursive=True))
    emitter.start()
示例#5
0
 def cb(*args):
     FSEventsEmitter.stop(emitter)
     orig(*args)
class TestPollingEmitterSimple(unittest2.TestCase):
    def setUp(self):
        global temp_dir
        temp_dir = mkdtemp()

    def start(self):
        sleep(0.5)
        self.event_queue = queue.Queue()
        global temp_dir
        self.watch = ObservedWatch(temp_dir, True)
        self.emitter = Emitter(self.event_queue, self.watch, timeout=0.2)
        self.emitter.start()
        sleep(0.5)

    def tearDown(self):
        global temp_dir
        rm(temp_dir, True)
        pass

    def collect_results(self):
        sleep(0.5)
        self.emitter.stop()

        got = []
        while True:
            try:
                event, _ = self.event_queue.get_nowait()
                got.append(event)
            except queue.Empty:
                break

        return got

    def fs(self, action):
        sleep(0.4)
        action()

    def test_mkdir(self):

        self.start()

        self.fs(lambda: mkdir(p('project')))

        expected = [
            DirModifiedEvent(p()),
            DirCreatedEvent(p('project')),
        ]

        got = self.collect_results()

        self.assertEqual(expected, got)

    def test_create_mv_a_b(self):

        touch(p('a'))

        self.start()

        self.fs(lambda: mv(p('a'), p('b')))

        expected = [
            FileMovedEvent(p('a'), p('b')),
            DirModifiedEvent(p()),
        ]

        got = self.collect_results()

        self.assertEqual(expected, got)

    def test_create_file(self):
        self.start()

        self.fs(lambda: touch(p('file')))

        expected = [
            FileCreatedEvent(p('file')),
            DirModifiedEvent(p()),
        ]

        got = self.collect_results()

        self.assertEqual(expected, got)
class TestPollingEmitterSimple(unittest2.TestCase):
  def setUp(self):
    global temp_dir
    temp_dir = mkdtemp()

  def start(self):
    sleep(0.5)
    self.event_queue = queue.Queue()
    global temp_dir
    self.watch = ObservedWatch(temp_dir, True)
    self.emitter = Emitter(self.event_queue, self.watch, timeout=0.2)
    self.emitter.start()
    sleep(0.5)

  def tearDown(self):
    global temp_dir
    rm(temp_dir, True)
    pass

  def collect_results(self):
    sleep(0.5)
    self.emitter.stop()

    got = []
    while True:
      try:
        event, _ = self.event_queue.get_nowait()
        got.append(event)
      except queue.Empty:
        break

    return got

  def fs(self, action):
    sleep(0.4)
    action()

  def test_mkdir(self):

    self.start()

    self.fs(lambda: mkdir(p('project')))

    expected = [
      DirModifiedEvent(p()),
      DirCreatedEvent(p('project')),
      ]

    got = self.collect_results()

    self.assertEqual(expected, got)


  def test_create_mv_a_b(self):

    touch(p('a'))

    self.start()

    self.fs(lambda: mv(p('a'), p('b')))

    expected = [
      FileMovedEvent(p('a'), p('b')),
      DirModifiedEvent(p()),
      ]

    got = self.collect_results()

    self.assertEqual(expected, got)


  def test_create_file(self):
    self.start()

    self.fs(lambda: touch(p('file')))

    expected = [
      FileCreatedEvent(p('file')),
      DirModifiedEvent(p()),
      ]

    got = self.collect_results()

    self.assertEqual(expected, got)