8 Tests frame module for proper behavior 15 XBee class must be able to create a valid API frame given binary 16 data, in byte string form. 20 create a frame containing a single byte 24 expected_frame =
'\x7E\x00\x01\x00\xFF' 27 self.assertEqual(frame, expected_frame)
31 XBee class must be able to read and validate the data contained 37 remaining_bytes() should provide accurate indication 38 of remaining bytes required before parsing a packet 42 frame =
'\x7E\x00\x04\x00\x00\x00\x00\xFF' 43 self.assertEqual(api_frame.remaining_bytes(), 3)
44 api_frame.fill(frame[0])
45 self.assertEqual(api_frame.remaining_bytes(), 2)
46 api_frame.fill(frame[1])
47 self.assertEqual(api_frame.remaining_bytes(), 1)
48 api_frame.fill(frame[2])
49 self.assertEqual(api_frame.remaining_bytes(), 5)
50 api_frame.fill(frame[3])
51 self.assertEqual(api_frame.remaining_bytes(), 4)
55 read a frame containing a single byte 59 frame =
'\x7E\x00\x01\x00\xFF' 60 expected_data =
'\x00' 66 self.assertEqual(api_frame.data, expected_data)
70 when an invalid frame is read, an exception must be raised 73 frame =
'\x7E\x00\x01\x00\xF6' 78 self.assertRaises(ValueError, api_frame.parse)
82 APIFrame class must properly escape data 87 APIFrame.escape() must work as expected 89 test_data = APIFrame.START_BYTE
90 new_data = APIFrame.escape(test_data)
91 self.assertEqual(new_data, APIFrame.ESCAPE_BYTE +
'\x5e')
def test_single_byte(self)
def test_remaining_bytes(self)
def test_invalid_checksum(self)
def test_single_byte(self)
def test_escape_method(self)