Exemplo n.º 1
0
def emitter(event_queue):
    watch = ObservedWatch(temp_dir, True)
    em = Emitter(event_queue, watch, timeout=0.2)
    em.start()
    yield em
    em.stop()
    em.join(5)
Exemplo n.º 2
0
 def makeEmitter(self, path=None):
     """
     Return an emitter.
     """
     return PollingEmitter(
         event_queue=self.emitter_queue,
         watch=self.ObservedWatch(path=path),
         timeout=0.1,
     )
Exemplo n.º 3
0
 def setUp(self):
     self.event_queue = queue.Queue()
     self.watch = ObservedWatch(temp_dir, True)
     self.emitter = Emitter(self.event_queue, self.watch, timeout=0.2)
Exemplo n.º 4
0
class TestPollingEmitter(unittest.TestCase):
    def setUp(self):
        self.event_queue = queue.Queue()
        self.watch = ObservedWatch(temp_dir, True)
        self.emitter = Emitter(self.event_queue, self.watch, timeout=0.2)

    def teardown(self):
        pass

    def test___init__(self):
        SLEEP_TIME = 0.4
        self.emitter.start()
        sleep(SLEEP_TIME)
        mkdir(p('project'))
        sleep(SLEEP_TIME)
        mkdir(p('project', 'blah'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        touch(p('fromfile'))
        sleep(SLEEP_TIME)
        mv(p('fromfile'), p('project', 'tofile'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        mv(p('project', 'blah'), p('project', 'boo'))
        sleep(SLEEP_TIME)
        rm(p('project'), recursive=True)
        sleep(SLEEP_TIME)
        rm(p('afile'))
        sleep(SLEEP_TIME)
        self.emitter.stop()

        # What we need here for the tests to pass is a collection type
        # that is:
        #   * unordered
        #   * non-unique
        # A multiset! Python's collections.Counter class seems appropriate.
        expected = set([
            DirModifiedEvent(p()),
            DirCreatedEvent(p('project')),
            DirModifiedEvent(p('project')),
            DirCreatedEvent(p('project', 'blah')),
            FileCreatedEvent(p('afile')),
            DirModifiedEvent(p()),
            FileCreatedEvent(p('fromfile')),
            DirModifiedEvent(p()),
            DirModifiedEvent(p()),
            FileModifiedEvent(p('afile')),
            DirModifiedEvent(p('project')),
            DirModifiedEvent(p()),
            FileDeletedEvent(p('project', 'tofile')),
            DirDeletedEvent(p('project', 'boo')),
            DirDeletedEvent(p('project')),
            DirModifiedEvent(p()),
            FileDeletedEvent(p('afile')),
        ])

        expected.add(FileMovedEvent(p('fromfile'), p('project', 'tofile')))
        expected.add(DirMovedEvent(p('project', 'blah'), p('project', 'boo')))

        got = set()
        while True:
            try:
                event, _ = self.event_queue.get_nowait()
                got.add(event)
            except queue.Empty:
                break

        self.assertEqual(expected, got)
 def setUp(self):
     self.event_queue = queue.Queue()
     self.watch = ObservedWatch(temp_dir, True)
     self.emitter = Emitter(self.event_queue, self.watch, timeout=0.2)
class TestPollingEmitter(unittest2.TestCase):
    def setUp(self):
        self.event_queue = queue.Queue()
        self.watch = ObservedWatch(temp_dir, True)
        self.emitter = Emitter(self.event_queue, self.watch, timeout=0.2)

    def teardown(self):
        pass

    def test___init__(self):
        SLEEP_TIME = 0.4
        self.emitter.start()
        sleep(SLEEP_TIME)
        mkdir(p('project'))
        sleep(SLEEP_TIME)
        mkdir(p('project', 'blah'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        touch(p('fromfile'))
        sleep(SLEEP_TIME)
        mv(p('fromfile'), p('project', 'tofile'))
        sleep(SLEEP_TIME)
        touch(p('afile'))
        sleep(SLEEP_TIME)
        mv(p('project', 'blah'), p('project', 'boo'))
        sleep(SLEEP_TIME)
        rm(p('project'), recursive=True)
        sleep(SLEEP_TIME)
        rm(p('afile'))
        sleep(SLEEP_TIME)
        self.emitter.stop()

        # What we need here for the tests to pass is a collection type
        # that is:
        #   * unordered
        #   * non-unique
        # A multiset! Python's collections.Counter class seems appropriate.
        expected = set([
            DirModifiedEvent(p()),
            DirCreatedEvent(p('project')),

            DirModifiedEvent(p('project')),
            DirCreatedEvent(p('project', 'blah')),

            FileCreatedEvent(p('afile')),
            DirModifiedEvent(p()),

            FileCreatedEvent(p('fromfile')),
            DirModifiedEvent(p()),

            DirModifiedEvent(p()),
            FileMovedEvent(p('fromfile'), p('project', 'tofile')),

            FileModifiedEvent(p('afile')),

            DirModifiedEvent(p('project')),
            DirMovedEvent(p('project', 'blah'), p('project', 'boo')),

            DirModifiedEvent(p()),
            FileDeletedEvent(p('project', 'boo')),
            DirDeletedEvent(p('project', 'boo')),
            DirDeletedEvent(p('project')),

            DirModifiedEvent(p()),
            FileDeletedEvent(p('afile')),

        ])
        got = set()

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

        self.assertEqual(expected, got)
Exemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     PollingEmitter.__init__(self, *args, **kwargs)
     self._modifying_files = collections.defaultdict(dict)
def emitter(event_queue):
    watch = ObservedWatch(temp_dir, True)
    em = Emitter(event_queue, watch, timeout=0.2)
    em.start()
    yield em
    em.stop()
Exemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     PollingEmitter.__init__(self, *args, **kwargs)
     self._modifying_files = collections.defaultdict(dict)