コード例 #1
0
    def test_should_not_start_already_started_driver(self):
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf.start(drv)
        self.queue.push(None)
        try:
            self.assertRaises(ValueError, buf.start, drv)
        finally:
            buf.stop()
コード例 #2
0
    def test_should_not_start_already_started_driver(self):
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf.start(drv)
        self.queue.push(None)
        try:
            self.assertRaises(ValueError, buf.start, drv)
        finally:
            buf.stop()
コード例 #3
0
    def test_should_start_and_stop_driver(self):
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf.start(drv)
        drv.started.wait()
        self.queue.push_none_and_wait()

        buf.stop()
        self.assertTrue(drv.stopped)
コード例 #4
0
    def test_should_start_and_stop_driver(self):
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf.start(drv)
        drv.started.wait()
        self.queue.push_none_and_wait()

        buf.stop()
        self.assertTrue(drv.stopped)
コード例 #5
0
    def test_should_restart_driver(self):
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf.start(drv)
        self.queue.push(None)

        queue2 = ScreenBufferTest.Queue()
        drv2 = ScreenBufferTest.FakeDriver(queue2)
        buf.restart(drv2)
        queue2.push(None)

        buf.stop()
コード例 #6
0
    def test_should_restart_driver(self):
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf.start(drv)
        self.queue.push(None)

        queue2 = ScreenBufferTest.Queue()
        drv2 = ScreenBufferTest.FakeDriver(queue2)
        buf.restart(drv2)
        queue2.push(None)

        buf.stop()
コード例 #7
0
    def test_should_wait_with_timeout(self):
        buf = ScreenBuffer(2, buffer_size=5, timeout=13)
        drv = ScreenBufferTest.FakeDriver(self.queue)

        with patch.object(buf._condition_var, 'wait',
                wraps=buf._condition_var.wait) as cond_wait:
            buf.start(drv)
            drv.started.wait()

            self.queue.push_backward_records(14, 7)
            self.queue.wait()

            buf.stop()
            cond_wait.assert_called_once_with(13)
コード例 #8
0
    def test_should_wait_with_timeout(self):
        buf = ScreenBuffer(2, buffer_size=5, timeout=13)
        drv = ScreenBufferTest.FakeDriver(self.queue)

        with patch.object(buf._condition_var,
                          'wait',
                          wraps=buf._condition_var.wait) as cond_wait:
            buf.start(drv)
            drv.started.wait()

            self.queue.push_backward_records(14, 7)
            self.queue.wait()

            buf.stop()
            cond_wait.assert_called_once_with(13)
コード例 #9
0
    def test_should_fetch_records_from_thread(self):
        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        buf.start(drv)
        self.queue.push_backward_records(2, 2)
        self.queue.wait()

        cur = buf.get_current_lines()
        buf.stop()
        self.assertTrue(drv.stopped)
        self.assertFalse(drv.error)
        self.assertEqual((None, True, 7), drv.instruction)

        self.assertEqual(2, len(cur))
        self.assertEqual('1', cur[0].message)
        self.assertEqual('2', cur[1].message)
コード例 #10
0
    def test_should_clear_existing_records_on_restart(self):
        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        buf.start(drv)
        self.queue.push_backward_records(2, 2)
        self.queue.wait()

        queue2 = ScreenBufferTest.Queue()
        drv2 = ScreenBufferTest.FakeDriver(queue2)
        buf.restart(drv2)
        queue2.push_none_and_wait()

        try:
            self.assertEqual(0, len(buf.get_current_lines()))
        finally:
            buf.stop()
コード例 #11
0
    def test_should_fetch_records_from_thread(self):
        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        buf.start(drv)
        self.queue.push_backward_records(2, 2)
        self.queue.wait()

        cur = buf.get_current_lines()
        buf.stop()
        self.assertTrue(drv.stopped)
        self.assertFalse(drv.error)
        self.assertEqual((None, True, 7), drv.instruction)

        self.assertEqual(2, len(cur))
        self.assertEqual('1', cur[0].message)
        self.assertEqual('2', cur[1].message)
コード例 #12
0
    def test_should_clear_existing_records_on_restart(self):
        drv = ScreenBufferTest.FakeDriver(self.queue)
        buf = ScreenBuffer(page_size=2, buffer_size=5)

        buf.start(drv)
        self.queue.push_backward_records(2, 2)
        self.queue.wait()

        queue2 = ScreenBufferTest.Queue()
        drv2 = ScreenBufferTest.FakeDriver(queue2)
        buf.restart(drv2)
        queue2.push_none_and_wait()

        try:
            self.assertEqual(0, len(buf.get_current_lines()))
        finally:
            buf.stop()