Example #1
0
async def test_new_exception(ota_mock):
    class App(zigpy.application.ControllerApplication):
        async def shutdown(self):
            pass

        async def startup(self, auto_form=False):
            pass

        async def request(
            self,
            device,
            profile,
            cluster,
            src_ep,
            dst_ep,
            sequence,
            data,
            expect_reply=True,
            use_ieee=False,
        ):
            pass

        async def permit_ncp(self, time_s=60):
            pass

        async def probe(self, config):
            return True

    p1 = mock.patch.object(App, "_load_db", CoroutineMock())
    p2 = mock.patch.object(App, "startup", CoroutineMock())
    p3 = mock.patch.object(App, "shutdown", CoroutineMock())
    ota_mock.return_value.initialize.side_effect = CoroutineMock()

    with p1 as db_mck, p2 as start_mck, p3 as shut_mck:
        await App.new(ZIGPY_SCHEMA({CONF_DATABASE: "/dev/null"}))
    assert db_mck.call_count == 1
    assert db_mck.await_count == 1
    assert ota_mock.return_value.initialize.call_count == 1
    assert start_mck.call_count == 1
    assert start_mck.await_count == 1
    assert shut_mck.call_count == 0
    assert shut_mck.await_count == 0

    start_mck.side_effect = asyncio.TimeoutError
    with p1 as db_mck, p2 as start_mck, p3 as shut_mck:
        with pytest.raises(asyncio.TimeoutError):
            await App.new(ZIGPY_SCHEMA({CONF_DATABASE: "/dev/null"}))
    assert db_mck.call_count == 2
    assert db_mck.await_count == 2
    assert ota_mock.return_value.initialize.call_count == 2
    assert start_mck.call_count == 2
    assert start_mck.await_count == 2
    assert shut_mck.call_count == 1
    assert shut_mck.await_count == 1
Example #2
0
async def make_app(database_file):
    class App(zigpy.application.ControllerApplication):
        async def shutdown(self):
            pass

        async def startup(self, auto_form=False):
            pass

        async def request(
            self,
            device,
            profile,
            cluster,
            src_ep,
            dst_ep,
            sequence,
            data,
            expect_reply=True,
            use_ieee=False,
        ):
            pass

        async def permit_ncp(self, time_s=60):
            pass

        async def probe(self, config):
            return True

    p2 = patch("zigpy.topology.Topology.scan_loop", AsyncMock())
    with patch("zigpy.ota.OTA.initialize", AsyncMock()), p2:
        app = await App.new(ZIGPY_SCHEMA({CONF_DATABASE: database_file}))
    return app
Example #3
0
async def make_app(database_file):
    class App(zigpy.application.ControllerApplication):
        async def shutdown(self):
            pass

        async def startup(self, auto_form=False):
            pass

        async def request(
            self,
            device,
            profile,
            cluster,
            src_ep,
            dst_ep,
            sequence,
            data,
            expect_reply=True,
            use_ieee=False,
        ):
            pass

        async def permit_ncp(self, time_s=60):
            pass

    with mock.patch("zigpy.ota.OTA.initialize", CoroutineMock()):
        app = await App.new(ZIGPY_SCHEMA({CONF_DATABASE: database_file}))
    return app
Example #4
0
async def test_startup_log_on_uninitialized_device(ieee, caplog):
    class App(zigpy.application.ControllerApplication):
        async def _noop(self, *args, **kwargs):
            pass

        startup = request = permit_ncp = probe = shutdown = _noop

        async def _load_db(self):
            self.add_device(ieee, 1)

    caplog.set_level(logging.WARNING)

    await App.new(ZIGPY_SCHEMA({CONF_DATABASE: "/dev/null"}))
    assert "Device is partially initialized" in caplog.text