File: conftest.py

package info (click to toggle)
pyxiaomigateway 0.14.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 132 kB
  • sloc: python: 662; makefile: 7
file content (34 lines) | stat: -rw-r--r-- 897 bytes parent folder | download
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
"""Set up some common test helper things."""
import pytest
import socket
import asyncio
from tests.gateway import AqaraGateway
from xiaomi_gateway import XiaomiGatewayDiscovery


@pytest.yield_fixture
def gateway_factory(event_loop):
    """Factory that creates new gateways"""
    gateways = []

    def start_gateway(config):
        gateways.append(AqaraGateway(config, event_loop))

    yield start_gateway
    [gateway.stop() for gateway in gateways]


@pytest.yield_fixture
def client_factory():
    """Factory that creates new gateway clients"""
    clients = []

    def start_client(ip, gateways):
        config = []
        [config.append({'key': g['key'], 'sid': g['sid']}) for g in gateways]
        client = XiaomiGatewayDiscovery(lambda: None, config, ip)
        clients.append(client)
        return client

    yield start_client
    [client.stop_listen() for client in clients]