@@ -158,13 +158,13 @@ def test_split_status_response(self):
158158 'status' :b'\x01 ' }
159159
160160 self .assertEqual (info , expected_info )
161-
161+
162162 def test_split_short_at_response (self ):
163163 """
164164 _split_response should properly split an at_response packet which
165165 has no parameter data
166166 """
167-
167+
168168 data = b'\x88 DMY\x01 '
169169 info = self .xbee ._split_response (data )
170170 expected_info = {'id' :'at_response' ,
@@ -187,28 +187,29 @@ def test_split_at_resp_with_param(self):
187187 'status' :b'\x01 ' ,
188188 'parameter' :b'ABCDEF' }
189189 self .assertEqual (info , expected_info )
190-
190+
191191 def test_generalized_packet_parsing (self ):
192192 """
193193 _split_response should properly parse packets in a generalized
194194 manner when specified by the protocol definition.
195195 """
196-
197- # Temporarily add parsing rule
196+
197+ # Temporarily modify parsing rule (taking a backup of the original rule)
198+ parse_rule_orig = self .xbee .api_responses [b"\x88 " ]["parsing" ]
198199 self .xbee .api_responses [b"\x88 " ]["parsing" ] = [("parameter" , lambda self ,orig : b"GHIJKL" )]
199-
200+
200201 data = b'\x88 DMY\x01 ABCDEF'
201-
202+
202203 info = self .xbee ._split_response (data )
203204 expected_info = {'id' :'at_response' ,
204205 'frame_id' :b'D' ,
205206 'command' :b'MY' ,
206207 'status' :b'\x01 ' ,
207208 'parameter' :b'GHIJKL' }
208-
209- # Remove all parsing rules
210- del ( self .xbee .api_responses [b"\x88 " ]["parsing" ])
211-
209+
210+ # Restore parsing rule to original
211+ self .xbee .api_responses [b"\x88 " ]["parsing" ] = parse_rule_orig
212+
212213 self .assertEqual (info , expected_info )
213214
214215class TestParseIOData (InitXBee ):
@@ -580,20 +581,20 @@ def test_is_response_parsed_as_io(self):
580581 """
581582 I/O data in a AT response for an IS command is parsed.
582583 """
583- # # Build IO data
584+ # Build IO data
584585 # One sample, ADC 0 enabled
585586 # DIO 1,3,5,7 enabled
586587 header = b'\x01 \x02 \xAA '
587-
588+
588589 # First 7 bits ignored, DIO8 low, DIO 0-7 alternating
589590 # ADC0 value of 255
590591 sample = b'\x00 \xAA \x00 \xFF '
591592 data = header + sample
592-
593+
593594 device = Serial ()
594- device .set_read_data (APIFrame (data = b'\x88 DIS\x00 ' + data ).output ());
595+ device .set_read_data (APIFrame (data = b'\x88 DIS\x00 ' + data ).output ())
595596 xbee = XBee (device )
596-
597+
597598 info = xbee .wait_read_frame ()
598599 expected_info = {'id' :'at_response' ,
599600 'frame_id' :b'D' ,
@@ -605,26 +606,26 @@ def test_is_response_parsed_as_io(self):
605606 'dio-7' :True ,
606607 'adc-0' :255 }]}
607608 self .assertEqual (info , expected_info )
608-
609+
609610 def test_is_remote_response_parsed_as_io (self ):
610611 """
611612 I/O data in a Remote AT response for an IS command is parsed.
612613 """
613- # # Build IO data
614+ # Build IO data
614615 # One sample, ADC 0 enabled
615616 # DIO 1,3,5,7 enabled
616617 header = b'\x01 \x02 \xAA '
617-
618+
618619 # First 7 bits ignored, DIO8 low, DIO 0-7 alternating
619620 # ADC0 value of 255
620621 sample = b'\x00 \xAA \x00 \xFF '
621622 data = header + sample
622623
623624 device = Serial ()
624625 device .set_read_data (APIFrame (data = b'\x97 D\x00 \x13 \xa2 \x00 @oG\xe4 v\x1a IS\x00 ' + data ).output ())
625-
626+
626627 xbee = XBee (device )
627-
628+
628629 info = xbee .wait_read_frame ()
629630 expected_info = {'id' :'remote_at_response' ,
630631 'frame_id' :b'D' ,
@@ -643,7 +644,7 @@ def test_read_io_data(self):
643644 """
644645 XBee class should properly read and parse incoming IO data
645646 """
646- ## Build IO data
647+ # Build IO data
647648 # One sample, ADC 0 enabled
648649 # DIO 1,3,5,7 enabled
649650 header = b'\x01 \x02 \xAA '
@@ -732,7 +733,7 @@ def test_empty_frame_ignored(self):
732733 device = Serial ()
733734 device .set_read_data (b'\x7E \x00 \x00 \xFF \x7E \x00 \x05 \x88 DMY\x01 \x8c ' )
734735 xbee = XBee (device )
735-
736+
736737 #import pdb
737738 #pdb.set_trace()
738739 info = xbee .wait_read_frame ()
0 commit comments