2
2
from __future__ import print_function
3
3
import socket
4
4
import pytest
5
- from blynklib import Blynk , BlynkError , RedirectError
5
+ import blynklib
6
6
7
7
8
8
class TestBlynk :
9
9
@pytest .fixture
10
10
def bl (self ):
11
- blynk = Blynk ('1234' , log = print )
11
+ blynk = blynklib . Blynk ('1234' , log = print )
12
12
yield blynk
13
13
14
14
def test_connect (self , bl , mocker ):
@@ -17,13 +17,15 @@ def test_connect(self, bl, mocker):
17
17
with mocker .patch .object (bl , '_authenticate' , return_value = None ):
18
18
with mocker .patch .object (bl , '_set_heartbeat' , return_value = None ):
19
19
with mocker .patch .object (bl , 'call_handler' , return_value = None ):
20
- result = bl .connect ()
21
- assert result is True
20
+ with mocker .patch .object (blynklib , 'ticks_ms' , return_value = 42 ):
21
+ result = bl .connect ()
22
+ assert result is True
23
+ assert bl ._last_rcv_time == 42
22
24
23
25
def test_connect_exception (self , bl , mocker ):
24
26
with mocker .patch .object (bl , 'connected' , return_value = False ):
25
27
with mocker .patch .object (bl , '_get_socket' , return_value = None ):
26
- with mocker .patch .object (bl , '_authenticate' , side_effect = BlynkError ()):
28
+ with mocker .patch .object (bl , '_authenticate' , side_effect = blynklib . BlynkError ()):
27
29
with mocker .patch .object (bl , 'disconnect' , return_value = None ):
28
30
with mocker .patch ('time.sleep' , return_value = None ):
29
31
mocker .spy (bl , 'disconnect' )
@@ -34,7 +36,7 @@ def test_connect_exception(self, bl, mocker):
34
36
def test_connect_redirect_exception (self , bl , mocker ):
35
37
with mocker .patch .object (bl , 'connected' , return_value = False ):
36
38
with mocker .patch .object (bl , '_get_socket' , return_value = None ):
37
- with mocker .patch .object (bl , '_authenticate' , side_effect = RedirectError ('127.0.0.1' , 4444 )):
39
+ with mocker .patch .object (bl , '_authenticate' , side_effect = blynklib . RedirectError ('127.0.0.1' , 4444 )):
38
40
with mocker .patch .object (bl , 'disconnect' , return_value = None ):
39
41
with mocker .patch ('time.sleep' , return_value = None ):
40
42
mocker .spy (bl , 'disconnect' )
0 commit comments