コード例 #1
0
ファイル: test_base.py プロジェクト: stanleyatala/IoTGateway
    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')
コード例 #2
0
ファイル: test_base.py プロジェクト: blalor/home-automator
 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')
コード例 #3
0
ファイル: test_base.py プロジェクト: blalor/home-automator
 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')
コード例 #4
0
ファイル: test_base.py プロジェクト: stanleyatala/IoTGateway
    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')
コード例 #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')
コード例 #6
0
ファイル: test_base.py プロジェクト: blalor/home-automator
 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)
コード例 #7
0
ファイル: test_base.py プロジェクト: stanleyatala/IoTGateway
    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)
コード例 #8
0
ファイル: test_base.py プロジェクト: stanleyatala/IoTGateway
    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)
コード例 #9
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('\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)
コード例 #10
0
ファイル: test_base.py プロジェクト: mlasevich/python-xbee
    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)
コード例 #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)
コード例 #12
0
ファイル: test_base.py プロジェクト: stanleyatala/IoTGateway
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())
コード例 #13
0
ファイル: test_base.py プロジェクト: blalor/home-automator
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())
コード例 #14
0
ファイル: test_base.py プロジェクト: blalor/home-automator
 def setUp(self):
     self.base = XBeeBase(None)
コード例 #15
0
ファイル: test_base.py プロジェクト: stanleyatala/IoTGateway
 def setUp(self):
     self.base = XBeeBase(None)
コード例 #16
0
ファイル: test_base.py プロジェクト: stanleyatala/IoTGateway
 def setUp(self):
     """
     Set up a base class XBeeBase object which does not have 
     api_commands or api_responses defined
     """
     self.xbee = XBeeBase(None)