예제 #1
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)
예제 #2
0
파일: test_stentura.py 프로젝트: gcr/plover
    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)
예제 #3
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)
예제 #4
0
파일: test_stentura.py 프로젝트: gcr/plover
    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)
예제 #5
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)
예제 #6
0
파일: test_stentura.py 프로젝트: gcr/plover
    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)
예제 #7
0
    def test_read_data_simple(self):
        class MockPort(object):
            def inWaiting(self):
                return 5

            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, 1)
        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, 1)
        self.assertSequenceEqual([chr(b) for b in buf], "123412345")
예제 #8
0
파일: test_stentura.py 프로젝트: gcr/plover
    def test_read_data_simple(self):
        class MockPort(object):
            def inWaiting(self):
                return 5

            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, 1)
        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, 1)
        self.assertSequenceEqual([chr(b) for b in buf], "123412345")
예제 #9
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")
예제 #10
0
파일: test_stentura.py 프로젝트: gcr/plover
    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")