diff options
author | Edi Feschiyan <edi.feschiyan@konsulko.com> | 2020-07-13 18:42:16 +0300 |
---|---|---|
committer | Edi Feschiyan <edi.feschiyan@konsulko.com> | 2020-07-13 18:42:16 +0300 |
commit | 8d93b3beae86f6947645ce537bfac108c355d0b4 (patch) | |
tree | 6fb8ed984df8d3998179935ce633e7f9e4da0e09 | |
parent | f2b375ab71f654888c19a8fdfe777507a7f7095f (diff) |
converting test_subscribe_location into task and waiting for it more intelligently
-rw-r--r-- | pyagl/services/base.py | 4 | ||||
-rw-r--r-- | pyagl/tests/test_gps.py | 8 |
2 files changed, 8 insertions, 4 deletions
diff --git a/pyagl/services/base.py b/pyagl/services/base.py index 42468a8..766a51b 100644 --- a/pyagl/services/base.py +++ b/pyagl/services/base.py @@ -238,7 +238,9 @@ class AGLBaseService: self.logger.error("Unhandled seal: " + str(e)) async def afbresponse(self): - return AFBResponse(await self.response()) + resp = await self.response() + if resp is not None: + return AFBResponse(resp) async def request(self, verb: str, values: Union[str, dict] = "", msgid: int = None, api=None): msgid = next(newrand()) if msgid is None else msgid diff --git a/pyagl/tests/test_gps.py b/pyagl/tests/test_gps.py index 3bfeb48..9bcd073 100644 --- a/pyagl/tests/test_gps.py +++ b/pyagl/tests/test_gps.py @@ -48,13 +48,13 @@ async def test_subscribe_verb(event_loop, service: GPS): assert resp.msgid == msgid assert resp.status == 'success' - +@pytest.mark.dependency async def test_enable_recording(event_loop, service: GPS): msgid = await service.record() resp = await service.afbresponse() assert resp.status == 'success', resp.info - +@pytest.mark.dependency(depends=['test_enable_recording']) async def test_disable_recording(event_loop, service: GPS): msgid = await service.record('off') resp = await service.afbresponse() @@ -76,11 +76,13 @@ async def test_location_events(event_loop, service: GPS): resp = await service.afbresponse() assert resp.msgid == msgid assert resp.status == 'success' # successful subscription + task = asyncio.create_task(service.afbresponse()) try: - resp = await asyncio.wait_for(service.afbresponse(), 10) + resp = await asyncio.wait_for(task, 10) assert resp.type == AFBT.EVENT, f'Expected EVENT response, got {resp.type.name} instead' # TODO one more assert for the actual received event, haven't received a location event yet except TimeoutError: + task.cancel() pytest.xfail("Did not receive location event") |