Exemplo n.º 1
0
 def test_read_data_stop_set(self):
     class MockPort:
         def read(self, count):
             return b"0000"
     buf = bytearray()
     event = threading.Event()
     event.set()
     with self.assertRaises(stentura._StopException):
         stentura._read_data(MockPort(), event, buf, 0, 4)
Exemplo n.º 2
0
 def test_read_data_stop_set(self):
     class MockPort(object):
         def read(self, count):
             return b"0000"
     buf = bytearray()
     event = threading.Event()
     event.set()
     with self.assertRaises(stentura._StopException):
         stentura._read_data(MockPort(), event, buf, 0, 4)
Exemplo n.º 3
0
    def test_read_data_timeout(self):
        class MockPort(object):
            def inWaiting(self):
                return 0

        port = MockPort()
        buf = array.array('B')
        with self.assertRaises(stentura._TimeoutException):
            stentura._read_data(port, threading.Event(), buf, 0, 0.001)
Exemplo n.º 4
0
    def test_read_data_timeout(self):
        class MockPort(object):
            def inWaiting(self):
                return 0

        port = MockPort()
        buf = array.array('B')
        with self.assertRaises(stentura._TimeoutException):
            stentura._read_data(port, threading.Event(), buf, 0, 0.001)
Exemplo n.º 5
0
    def test_read_data_stop_immediately(self):
        class MockPort(object):
            def inWaiting(self):
                return 0

        buf = array.array('B')
        event = threading.Event()
        event.set()
        with self.assertRaises(stentura._StopException):
            stentura._read_data(MockPort(), event, buf, 0, 1)
Exemplo n.º 6
0
    def test_read_data_stop_immediately(self):
        class MockPort(object):
            def inWaiting(self):
                return 0

        buf = array.array('B')
        event = threading.Event()
        event.set()
        with self.assertRaises(stentura._StopException):
            stentura._read_data(MockPort(), event, buf, 0, 1)
Exemplo n.º 7
0
    def test_read_data_timeout(self):
        class MockPort(object):
            def read(self, count):
                # When serial time out occurs read() returns
                # less characters as requested
                return "123"

        port = MockPort()
        buf = bytearray()
        with self.assertRaises(stentura._TimeoutException):
            stentura._read_data(port, threading.Event(), buf, 0, 4)
Exemplo n.º 8
0
    def test_read_data_timeout(self):
        class MockPort(object):
            def read(self, count):
                # When serial time out occurs read() returns
                # less characters as requested
                return "123"

        port = MockPort()
        buf = bytearray()
        with self.assertRaises(stentura._TimeoutException):
            stentura._read_data(port, threading.Event(), buf, 0, 4)
Exemplo n.º 9
0
    def test_read_data_simple(self):
        class MockPort(object):
            def read(self, count):
                if count != 5:
                    raise Exception("Incorrect number read.")
                return b"12345"

        port = MockPort()
        buf = bytearray([0] * 20)
        count = stentura._read_data(port, threading.Event(), buf, 0, 5)
        self.assertEqual(count, 5)
        self.assertEqual(buf, b'12345' + (b'\x00' * 15))

        # Test the offset parameter.
        count = stentura._read_data(port, threading.Event(), buf, 4, 5)
        self.assertEqual(buf, b'123412345' + (b'\x00' * 11))
Exemplo n.º 10
0
    def test_read_data_simple(self):
        class MockPort(object):
            def read(self, count):
                if count != 5:
                    raise Exception("Incorrect number read.")
                return b"12345"

        port = MockPort()
        buf = bytearray([0] * 20)
        count = stentura._read_data(port, threading.Event(), buf, 0, 5)
        self.assertEqual(count, 5)
        self.assertEqual(buf, b'12345' + (b'\x00' * 15))

        # Test the offset parameter.
        count = stentura._read_data(port, threading.Event(), buf, 4, 5)
        self.assertEqual(buf, b'123412345' + (b'\x00' * 11))
Exemplo n.º 11
0
    def test_read_data_simple(self):
        class MockPort(object):
            def read(self, count):
                if count != 5:
                    raise Exception("Incorrect number read.")
                return "12345"

        port = MockPort()
        buf = array.array('B')
        count = stentura._read_data(port, threading.Event(), buf, 0, 5)
        self.assertEqual(count, 5)
        self.assertSequenceEqual([chr(b) for b in buf], "12345")

        # Test the offset parameter.
        count = stentura._read_data(port, threading.Event(), buf, 4, 5)
        self.assertSequenceEqual([chr(b) for b in buf], "123412345")
Exemplo n.º 12
0
    def test_read_data_simple(self):
        class MockPort(object):
            def read(self, count):
                if count != 5:
                    raise Exception("Incorrect number read.")
                return "12345"

        port = MockPort()
        buf = array.array('B')
        count = stentura._read_data(port, threading.Event(), buf, 0, 5)
        self.assertEqual(count, 5)
        self.assertSequenceEqual([chr(b) for b in buf], "12345")

        # Test the offset parameter.
        count = stentura._read_data(port, threading.Event(), buf, 4, 5)
        self.assertSequenceEqual([chr(b) for b in buf], "123412345")
Exemplo n.º 13
0
    def test_read_data_stop_waiting(self):
        class MockPort(object):
            def __init__(self):
                self.event = threading.Event()
                self._times = 0

            def inWaiting(self):
                self._times += 1
                if self._times < 5:
                    return 0
                if self._times == 5:
                    self.event.set()
                    return 0

        port = MockPort()
        buf = array.array('B')
        with self.assertRaises(stentura._StopException):
            stentura._read_data(port, port.event, buf, 0, 1)
Exemplo n.º 14
0
    def test_read_data_stop_waiting(self):
        class MockPort(object):
            def __init__(self):
                self.event = threading.Event()
                self._times = 0

            def inWaiting(self):
                self._times += 1
                if self._times < 5:
                    return 0
                if self._times == 5:
                    self.event.set()
                    return 0

        port = MockPort()
        buf = array.array('B')
        with self.assertRaises(stentura._StopException):
            stentura._read_data(port, port.event, buf, 0, 1)
Exemplo n.º 15
0
    def test_read_data_waiting(self):
        class MockPort(object):
            def __init__(self):
                self._times = 0

            def inWaiting(self):
                self._times += 1
                if self._times == 5:
                    return 4

            def read(self, count):
                if self._times != 5:
                    raise Exception("Called read too early.")
                if count != 4:
                    raise Exception("Wrong count.")

                return "1234"

        buf = array.array('B')
        count = stentura._read_data(MockPort(), threading.Event(), buf, 0, 1)
        self.assertEqual(count, 4)
        self.assertSequenceEqual([chr(b) for b in buf], "1234")
Exemplo n.º 16
0
    def test_read_data_waiting(self):
        class MockPort(object):
            def __init__(self):
                self._times = 0

            def inWaiting(self):
                self._times += 1
                if self._times == 5:
                    return 4

            def read(self, count):
                if self._times != 5:
                    raise Exception("Called read too early.")
                if count != 4:
                    raise Exception("Wrong count.")

                return "1234"

        buf = array.array('B')
        count = stentura._read_data(MockPort(), threading.Event(), buf, 0, 1)
        self.assertEqual(count, 4)
        self.assertSequenceEqual([chr(b) for b in buf], "1234")