blob: a3b59c75d11df1120779ae391c38c6bc6c71c6ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import asyncio
import os
import pytest
from gps import GPSService
import logging
from aglbaseservice import AFBResponse, AFBT
logger = logging.getLogger('pytest-gps')
logger.setLevel(logging.DEBUG)
pytestmark = pytest.mark.asyncio
@pytest.fixture(scope="module")
def event_loop():
loop = asyncio.get_event_loop()
yield loop
loop.close()
@pytest.fixture(scope='module')
async def service():
address = os.environ.get('AGL_TGT_IP', 'localhost')
gpss = await GPSService(ip=address)
yield gpss
await gpss.websocket.close()
# @pytest.fixture(scope='module')
# async def response(event_loop, service):
# async for _response in service.listener():
# yield _response
@pytest.mark.xfail # expecting this to fail because of "No 3D GNSS fix" and GPS is unavailable
async def test_location(event_loop, service: GPSService):
id = await service.location()
resp = AFBResponse(await service.response())
assert resp.status == 'success'
async def test_subscribe_location(event_loop, service: GPSService):
id = await service.subscribe('location')
resp = AFBResponse(await service.response())
assert resp.msgid == id
assert resp.status == 'success'
async def test_unsubscribe(event_loop, service: GPSService):
id = await service.unsubscribe('location')
resp = AFBResponse(await service.response())
assert resp.msgid == id
assert resp.status == 'success'
async def test_location_events(event_loop, service: GPSService):
id = await service.subscribe('location')
resp = AFBResponse(await service.response())
assert resp.msgid == id
assert resp.status == 'success' # successful subscription
resp = await asyncio.wait_for(service.response(), 10)
resp = AFBResponse(resp)
assert resp.type == AFBT.EVENT, f'Expected EVENT response, got {resp.type.name} instead'
|