From 6dccc504328e2de332bd8d86855bc8fda6da323d Mon Sep 17 00:00:00 2001 From: Edi Feschiyan Date: Thu, 14 May 2020 15:40:10 +0300 Subject: working first test with asyncio for gps and weather.py imports cleanup --- aglbaseservice.py | 2 +- test_gps.py | 8 ++++++-- weather.py | 5 +---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/aglbaseservice.py b/aglbaseservice.py index 6d68095..e4fcfcd 100644 --- a/aglbaseservice.py +++ b/aglbaseservice.py @@ -88,7 +88,7 @@ class AGLBaseService: exit(1) URL = f'ws://{self.ip}:{self.port}/api?token={self.token}&uuid={self.uuid}' - self._conn = connect(close_timeout=0, uri=URL, subprotocols=['x-afb-ws-json1'], ping_interval=None, timeout=2) + self._conn = connect(close_timeout=10000, uri=URL, subprotocols=['x-afb-ws-json1'], ping_interval=None) self.websocket = await self._conn.__aenter__() return self diff --git a/test_gps.py b/test_gps.py index 4c8d245..fe27307 100644 --- a/test_gps.py +++ b/test_gps.py @@ -4,16 +4,20 @@ import pytest from gps import GPSService from concurrent import futures import logging +from functools import partial + logger = logging.getLogger('pytest-gps') logger.setLevel(logging.DEBUG) @pytest.fixture async def service(): + event_loop = asyncio.get_running_loop() address = os.environ.get('AGL_TGT_IP', 'localhost') gpss = await GPSService(ip=address) + # gpss = await GPSService(ip=address) yield gpss - gpss.websocket.close() + await gpss.websocket.close() # @pytest.fixture # async def listener(service): @@ -31,7 +35,7 @@ async def service(): # logger.error(e) @pytest.mark.asyncio -async def test_location(service): +async def test_location(event_loop, service): await service.location() r = await service.response() print(r) diff --git a/weather.py b/weather.py index 22c2646..ef1461a 100644 --- a/weather.py +++ b/weather.py @@ -1,8 +1,5 @@ import asyncio -from random import randint -import json from aglbaseservice import AGLBaseService -msgq = {} class WeatherService(AGLBaseService): @@ -27,4 +24,4 @@ async def main(): if __name__ == '__main__': loop = asyncio.get_event_loop() - loop.run_until_complete(main()) \ No newline at end of file + loop.run_until_complete(main()) -- cgit 1.2.3-korg