Beispiel #1
0
    def test_read(self):
        """
        _wait_for_frame should properly read a frame of data
        """
        device = FakeReadDevice(b'\x7E\x00\x01\x00\xFF')
        xbee = XBeeBase(device)

        frame = xbee._wait_for_frame()
        self.assertEqual(frame.data, b'\x00')
Beispiel #2
0
 def test_read(self):
     """
     _wait_for_frame should properly read a frame of data
     """
     device = FakeReadDevice('\x7E\x00\x01\x00\xFF')
     xbee = XBeeBase(device)
     
     frame = xbee._wait_for_frame()
     self.assertEqual(frame.data, '\x00')
Beispiel #3
0
 def test_read_invalid_followed_by_valid(self):
     """
     _wait_for_frame should skip invalid data
     """
     device = FakeReadDevice(
         '\x7E\x00\x01\x00\xFA' + '\x7E\x00\x01\x05\xFA')
     xbee = XBeeBase(device)
     
     frame = xbee._wait_for_frame()
     self.assertEqual(frame.data, '\x05')
Beispiel #4
0
    def test_read_invalid_followed_by_valid(self):
        """
        _wait_for_frame should skip invalid data
        """
        device = FakeReadDevice(b'\x7E\x00\x01\x00\xFA' +
                                b'\x7E\x00\x01\x05\xFA')
        xbee = XBeeBase(device)

        frame = xbee._wait_for_frame()
        self.assertEqual(frame.data, b'\x05')
Beispiel #5
0
    def test_read_escaped(self):
        """
        _wait_for_frame should properly read a frame of data
        Verify that API mode 2 escaped bytes are read correctly
        """
        device = FakeReadDevice('\x7E\x00\x04\x7D\x5E\x7D\x5D\x7D\x31\x7D\x33\xE0')

        xbee = XBeeBase(device,escaped=True)
        
        frame = xbee._wait_for_frame()
        self.assertEqual(frame.data, '\x7E\x7D\x11\x13')
Beispiel #6
0
 def test_write_again(self):
     """
     _write method should write the expected data to the serial
     device
     """
     device = FakeDevice()
     
     xbee = XBeeBase(device)
     xbee._write('\x00\x01\x02')
     
     # Check resuting state of fake device
     expected_frame = '\x7E\x00\x03\x00\x01\x02\xFC'
     self.assertEqual(device.data, expected_frame)
Beispiel #7
0
    def test_write_escaped(self):
        """
        _write method should write the expected data to the serial
        device
        """
        device = FakeDevice()

        xbee = XBeeBase(device, escaped=True)
        xbee._write(b'\x7E\x01\x7D\x11\x13')

        # Check resuting state of fake device
        expected_frame = b'\x7E\x00\x05\x7D\x5E\x01\x7D\x5D\x7D\x31\x7D\x33\xDF'
        self.assertEqual(device.data, expected_frame)
Beispiel #8
0
    def test_write_again(self):
        """
        _write method should write the expected data to the serial
        device
        """
        device = FakeDevice()

        xbee = XBeeBase(device)
        xbee._write(b'\x00\x01\x02')

        # Check resuting state of fake device
        expected_frame = b'\x7E\x00\x03\x00\x01\x02\xFC'
        self.assertEqual(device.data, expected_frame)
 def test_write_escaped(self):
     """
     _write method should write the expected data to the serial
     device
     """
     device = FakeDevice()
     
     xbee = XBeeBase(device,escaped=True)
     xbee._write('\x7E\x01\x7D\x11\x13')
     
     # Check resuting state of fake device
     expected_frame = '\x7E\x00\x05\x7D\x5E\x01\x7D\x5D\x7D\x31\x7D\x33\xDF'
     self.assertEqual(device.data, expected_frame)
Beispiel #10
0
    def test_write_again(self):
        """
        _write method should write the expected data to the serial
        device
        """
        device = Serial()

        xbee = XBeeBase(device)
        xbee._write(b'\x00\x01\x02')

        # Check resuting state of fake device
        expected_frame = b'\x7E\x00\x03\x00\x01\x02\xFC'
        result_frame   = device.get_data_written()
        self.assertEqual(result_frame, expected_frame)
Beispiel #11
0
 def test_provide_callback(self):
     """
     XBeeBase constructor should accept a callback function
     """
     self.xbee = XBeeBase(self.serial,
                          callback=self.callback,
                          error_callback=self.error_callback)
Beispiel #12
0
class TestInitialization(unittest.TestCase):
    """
    Ensures that XBeeBase objects are properly constructed
    """
    def setUp(self):
        self.base = XBeeBase(None)

    def test_thread_always_initialized(self):
        """
        Even when a callback method is not supplied to the XBeeBase
        constructor, it must be properly initalized as a
        threading.Thread object
        """
        self.assertFalse(self.base.is_alive())
Beispiel #13
0
class TestInitialization(unittest.TestCase):
    """
    Ensures that XBeeBase objects are properly constructed
    """

    def setUp(self):
        self.base = XBeeBase(None)

    def test_thread_always_initialized(self):
        """
        Even when a callback method is not supplied to the XBeeBase
        constructor, it must be properly initalized as a
        threading.Thread object
        """
        self.assertFalse(self.base.is_alive())
Beispiel #14
0
 def setUp(self):
     self.base = XBeeBase(None)
Beispiel #15
0
 def setUp(self):
     self.base = XBeeBase(None)
Beispiel #16
0
 def setUp(self):
     """
     Set up a base class XBeeBase object which does not have 
     api_commands or api_responses defined
     """
     self.xbee = XBeeBase(None)