Exemple #1
0
def test_deep_merge_deep_keep_first_container_left_intact():
    cs = [Container(a="a"), Container(c="a", d="b"), Container(e="c")]
    first_container = cs[0].copy()

    result = deep_merge(*cs, initializer={})
    assert dict(a="a", c="a", d="b", e="c") == result
    assert cs[0] == first_container
Exemple #2
0
def test_deep_merge_deep_keep_first_container_changed():
    cs = [Container(a="a"), Container(c="a", d="b"), Container(e="c")]
    first_container = cs[0].copy()

    result = deep_merge(*cs)
    assert dict(a="a", c="a", d="b", e="c") == result
    assert cs[0] != first_container
Exemple #3
0
    async def loop(self):
        logger.debug("Loop start")

        replies_missing = 0

        while self.run_state not in (RunState.STOP, RunState.ERROR):
            tstart = time.time()
            if self.run_state == RunState.RUN:
                try:
                    await self.busy.acquire()
                    result = await asyncio.gather(
                        *self.panel.get_status_requests())
                    merged = deep_merge(*result,
                                        extend_lists=True,
                                        initializer={})
                    self.work_loop.call_soon(self._process_status, merged)
                    replies_missing = max(0, replies_missing - 1)
                except ConnectionError:
                    raise
                except (StatusRequestException, asyncio.TimeoutError):
                    replies_missing += 1
                    if replies_missing > 3:
                        logger.error("Lost communication with panel")
                        await self.disconnect()
                        return
                except:
                    logger.exception("Loop")
                finally:
                    self.busy.release()

                if replies_missing > 0:
                    logger.debug(
                        "Loop: Replies missing: {}".format(replies_missing))

            # cfg.Listen for events

            max_wait_time = max(
                (tstart + cfg.KEEP_ALIVE_INTERVAL) - time.time(), 0)
            try:
                await asyncio.wait_for(self.loop_wait_event.wait(),
                                       max_wait_time)
            except asyncio.TimeoutError:
                # It is fine to timeout to go to the next loop
                pass
            finally:
                self.loop_wait_event.clear()
Exemple #4
0
    async def async_loop(self):
        logger.debug("Loop start")
        
        replies_missing = 0

        while self.run not in(State.STOP, State.ERROR):
            tstart = time.time()
            if self.run == State.RUN:
                try:
                    result = await asyncio.gather(*[self._status_request(i) for i in cfg.STATUS_REQUESTS])
                    merged = deep_merge(*result, extend_lists=True, initializer={})
                    self.work_loop.call_soon(self._process_status, merged)
                    replies_missing = max(0, replies_missing - 1)
                except ConnectionError:
                    raise
                except StatusRequestException:
                    replies_missing += 1
                    if replies_missing > 3:
                        logger.error("Lost communication with panel")
                        self.disconnect()
                except Exception:
                    logger.exception("Loop")

                if replies_missing > 0:
                    logger.debug("Loop: Replies missing: {}".format(replies_missing))

            # cfg.Listen for events

            max_wait_time = max((tstart + cfg.KEEP_ALIVE_INTERVAL) - time.time(), 0)
            try:
                await asyncio.wait_for(self.loop_wait_event.wait(), max_wait_time)
            except asyncio.TimeoutError:
                # It is fine to timeout to go to the next loop
                pass
            finally:
                self.loop_wait_event.clear()
Exemple #5
0
def test_deep_merge():
    cs = [Container(a="a"), Container(c="a", d="b"), Container(e="c")]

    result = deep_merge(*cs)
    assert dict(a="a", c="a", d="b", e="c") == result
Exemple #6
0
def test_deep_merge_extend_lists():
    cs = [Container(a=[1, 2]), Container(a=[3])]

    result = deep_merge(*cs, extend_lists=True)
    assert dict(a=[1, 2, 3]) == result
Exemple #7
0
def test_deep_merge_deep():
    cs = [Container(a=Container(c="a", d=Container(e="c")))]

    result = deep_merge(*cs)
    assert dict(a=dict(c="a", d=dict(e="c"))) == result
Exemple #8
0
 def deep_merge(self, *dicts):
     deep_merge(self, *dicts)