-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test case for miot mdns and network
- Loading branch information
Showing
4 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Unit test for miot_mdns.py.""" | ||
import asyncio | ||
import pytest | ||
|
||
from zeroconf import IPVersion | ||
from zeroconf.asyncio import AsyncZeroconf | ||
|
||
# pylint: disable=import-outside-toplevel, unused-argument | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_service_loop_async(): | ||
from miot.miot_mdns import MipsService, MipsServiceData, MipsServiceState | ||
|
||
async def on_service_state_change( | ||
group_id: str, state: MipsServiceState, data: MipsServiceData): | ||
print( | ||
'on_service_state_change, %s, %s, %s', group_id, state, data) | ||
|
||
async with AsyncZeroconf(ip_version=IPVersion.V4Only) as aiozc: | ||
mips_service = MipsService(aiozc) | ||
mips_service.sub_service_change('test', '*', on_service_state_change) | ||
await mips_service.init_async() | ||
services_detail = mips_service.get_services() | ||
print('get all service, ', services_detail.keys()) | ||
for name, data in services_detail.items(): | ||
print( | ||
'\tinfo, ', name, data['did'], data['addresses'], data['port']) | ||
await mips_service.deinit_async() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Unit test for miot_network.py.""" | ||
import pytest | ||
import asyncio | ||
|
||
# pylint: disable=import-outside-toplevel, unused-argument | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_network_monitor_loop_async(): | ||
from miot.miot_network import MIoTNetwork, InterfaceStatus, NetworkInfo | ||
miot_net = MIoTNetwork() | ||
|
||
async def on_network_status_changed(status: bool): | ||
print(f'on_network_status_changed, {status}') | ||
miot_net.sub_network_status(key='test', handler=on_network_status_changed) | ||
|
||
async def on_network_info_changed( | ||
status: InterfaceStatus, info: NetworkInfo): | ||
print(f'on_network_info_changed, {status}, {info}') | ||
miot_net.sub_network_info(key='test', handler=on_network_info_changed) | ||
|
||
await miot_net.init_async(3) | ||
await asyncio.sleep(3) | ||
print(f'net status: {miot_net.network_status}') | ||
print(f'net info: {miot_net.network_info}') | ||
await miot_net.deinit_async() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters