3
3
4
4
import pytest
5
5
6
- from asynctest import CoroutineMock
6
+ try :
7
+ # Python 3.8 already has this
8
+ from mock import AsyncMock as CoroutineMock
9
+ except ImportError :
10
+ from asynctest import CoroutineMock
7
11
8
12
import zigpy
9
13
import zigpy_znp .types as t
@@ -770,9 +774,7 @@ async def test_zigpy_request_failure(application, mocker):
770
774
],
771
775
)
772
776
773
- mocker .patch .object (
774
- app , "_send_request" , new = CoroutineMock (wraps = app ._send_request )
775
- )
777
+ mocker .spy (app , "_send_request" )
776
778
777
779
# Fail to turn on the light
778
780
with pytest .raises (zigpy .exceptions .DeliveryError ):
@@ -793,21 +795,21 @@ async def test_request_use_ieee(application, mocker, use_ieee, dev_addr):
793
795
app , znp_server = application
794
796
device = app .add_device (ieee = t .EUI64 (range (8 )), nwk = 0xAABB )
795
797
796
- send_req = mocker .patch .object (app , "_send_request" , new = CoroutineMock ())
798
+ mocker .patch .object (app , "_send_request" , new = CoroutineMock ())
797
799
798
800
await app .request (
799
801
device ,
800
802
use_ieee = use_ieee ,
801
- profile = None ,
802
- cluster = None ,
803
- src_ep = None ,
804
- dst_ep = None ,
805
- sequence = None ,
806
- data = None ,
803
+ profile = 1 ,
804
+ cluster = 2 ,
805
+ src_ep = 3 ,
806
+ dst_ep = 4 ,
807
+ sequence = 5 ,
808
+ data = b"6" ,
807
809
)
808
810
809
- assert send_req .call_count == 1
810
- assert send_req .mock_calls [0 ][2 ]["dst_addr" ] == dev_addr
811
+ assert app . _send_request .call_count == 1
812
+ assert app . _send_request .mock_calls [0 ][2 ]["dst_addr" ] == dev_addr
811
813
812
814
813
815
@pytest_mark_asyncio_timeout (seconds = 3 )
@@ -831,7 +833,7 @@ async def test_update_network(mocker, caplog, application):
831
833
app , znp_server = application
832
834
833
835
await app .startup (auto_form = False )
834
- mocker .patch . object (app , "_reset" , new = CoroutineMock () )
836
+ mocker .spy (app , "_reset" )
835
837
836
838
channel = t .uint8_t (15 )
837
839
pan_id = t .PanId (0x1234 )
@@ -974,7 +976,7 @@ async def test_force_remove(application, mocker):
974
976
async def test_auto_form_unnecessary (application , mocker ):
975
977
app , znp_server = application
976
978
977
- mocker .patch .object (app , "form_network" )
979
+ mocker .patch .object (app , "form_network" , new = CoroutineMock () )
978
980
979
981
await app .startup (auto_form = True )
980
982
assert app .form_network .call_count == 0
@@ -986,7 +988,7 @@ async def test_auto_form_necessary(application, mocker):
986
988
nvram = {}
987
989
988
990
mocker .patch .object (app , "update_network" , new = CoroutineMock ())
989
- mocker .patch . object (app , "_reset" , new = CoroutineMock () )
991
+ mocker .spy (app , "_reset" )
990
992
991
993
def nvram_writer (req ):
992
994
nvram [req .Id ] = req .Value
0 commit comments