@@ -19,65 +19,39 @@ class TestATClient:
1919
2020 @pytest .fixture
2121 def at_client (self ):
22- self .serial = Mock ()
23- return ATClient (self .serial )
22+ self .comms = Mock ()
23+ return ATClient (self .comms )
2424
2525 @pytest .fixture
2626 def ok_resp (self , at_client ):
27- self .serial . readline .return_value = 'OK\r \n ' . encode ( 'utf-8' )
27+ self .comms . read_line .return_value = 'OK\r \n '
2828
2929 @pytest .fixture
3030 def not_at_client_resp (self , at_client ):
31- self .serial . readline .side_effect = [b 'AT: command not found' , b '' ]
31+ self .comms . read_line .side_effect = ['AT: command not found' , '' ]
3232
3333 @pytest .fixture
3434 def error_resp (self , at_client ):
35- self .serial . readline .return_value = 'ERROR\r \n ' . encode ( 'utf-8' )
35+ self .comms . read_line .return_value = 'ERROR\r \n '
3636
3737 @pytest .fixture
3838 def error_code_resp (self , at_client ):
39- self .serial . readline .return_value = '+CME ERROR: 514\r \n ' . encode ( 'utf-8' )
39+ self .comms . read_line .return_value = '+CME ERROR: 514\r \n '
4040
4141 @pytest .fixture
4242 def error_code_0_resp (self , at_client ):
43- self .serial . readline .return_value = '+CME ERROR: 0\r \n ' . encode ( 'utf-8' )
43+ self .comms . read_line .return_value = '+CME ERROR: 0\r \n '
4444
4545 @pytest .fixture
4646 def error_ok_resp (self , at_client ):
47- self .serial . readline .side_effect = [b 'ERROR' , b 'OK' ]
47+ self .comms . read_line .side_effect = ['ERROR' , 'OK' ]
4848
4949 def test_create_without_serial_device (self ):
5050 with pytest .raises (RuntimeError ):
5151 ATClient (None )
5252
53- def test_at_command_with_serial_closed (self , at_client ):
54- with pytest .raises (ConnectionError ):
55- self .serial .is_open = False
56- at_client .at_command ('AT' )
57-
58- def test_verify_with_serial_closed (self , at_client ):
59- with pytest .raises (ConnectionError ):
60- self .serial .is_open = False
61- at_client .verify ()
62-
6353 def test_exposes_serial_device (self , at_client ):
64- assert at_client .device is self .serial
65-
66- def test_connect_sets_port (self , at_client ):
67- at_client .connect ('/dev/tty.usb' )
68- assert self .serial .port == '/dev/tty.usb'
69-
70- def test_connect_sets_baudrate (self , at_client ):
71- at_client .connect ('foo' , 123 )
72- assert self .serial .baudrate == 123
73-
74- def test_connect_sets_timeout (self , at_client ):
75- at_client .connect ('foo' , timeout = 3 )
76- assert self .serial .timeout == 3
77-
78- def test_connect_opens_serial_connection_to_device (self , at_client ):
79- at_client .connect ('foo' )
80- self .serial .open .assert_called ()
54+ assert at_client .comms is self .comms
8155
8256 def test_verify_fails_for_wrong_response (self , at_client , not_at_client_resp ):
8357 """Test that the AT client verifiation raises NoATClientException when readline returns
@@ -88,7 +62,7 @@ def test_verify_fails_for_wrong_response(self, at_client, not_at_client_resp):
8862
8963 def test_verify_sends_at_command (self , at_client , ok_resp ):
9064 at_client .verify ()
91- self .serial .write .assert_called_with ('AT\r \n ' .encode ('utf-8' ))
65+ self .comms .write .assert_called_with ('AT\r \n ' .encode ('utf-8' ))
9266
9367 def test_verify_fails_on_error (self , at_client , error_resp ):
9468 with pytest .raises (NoATClientException ):
@@ -99,7 +73,7 @@ def test_verify_retries_on_first_error(self, at_client, error_ok_resp):
9973
10074 def test_enable_error_codes_sends_cmd (self , at_client , ok_resp ):
10175 at_client .enable_error_codes ()
102- self .serial .write .assert_called_with (encode_cmd ('AT+CMEE=1' ))
76+ self .comms .write .assert_called_with (encode_cmd ('AT+CMEE=1' ))
10377
10478 def test_at_command_error (self , at_client , error_resp ):
10579 with pytest .raises (ATCommandError ):
@@ -120,9 +94,9 @@ def test_unsupported_cmd_error_code(self, at_client, error_code_0_resp):
12094 assert 'AT command not supported by firmware version' in str (excinfo .value )
12195
12296 def test_at_command_with_single_line_response (self , at_client ):
123- self .serial . readline .side_effect = [b 'single' , b 'OK' ]
97+ self .comms . read_line .side_effect = ['single' , 'OK' ]
12498 assert at_client .at_command ('AT+CGSN' ) == ['single' ]
12599
126100 def test_at_command_with_multi_line_response (self , at_client ):
127- self .serial . readline .side_effect = [b 'foo' , b 'bar' , b 'OK' ]
101+ self .comms . read_line .side_effect = ['foo' , 'bar' , 'OK' ]
128102 assert at_client .at_command ('AT+CGSN' ) == ['foo' , 'bar' ]
0 commit comments