Ejemplo n.º 1
0
    def test_write_complete(self):
        m_select = self._patch('select.select')
        m_write = self._patch('os.write')

        wfd = 42
        m_sinkbuffer = self._make_mock()
        m_sinkbuffer.pending.side_effect = [True, False]
        m_sinkbuffer.take.return_value = 'foobar'
        m_write.return_value = 6
        m_select.return_value = ([], [wfd], [])

        self.m.add_sink(wfd, m_sinkbuffer)
        cont = self.m.process_events()

        self._assertCallsEqual(m_select, [call([], [wfd], [], SELECT_INTERVAL)])
        self._assertCallsEqual(
            m_sinkbuffer,
            [call.pending(),
             call.take(),
             call.pending()])
        self._assertCallsEqual(m_write, [call(wfd, 'foobar')])
        self.assertEqual(False, cont)
Ejemplo n.º 2
0
    def test_write_partial(self):
        m_select = self._patch('select.select')
        m_write = self._patch('os.write')

        wfd = 42
        m_sinkbuffer = self._make_mock()
        m_sinkbuffer.pending.return_value = True
        m_sinkbuffer.take.return_value = 'foobar'
        m_write.return_value = 3
        m_select.return_value = ([], [wfd], [])

        self.m.add_sink(wfd, m_sinkbuffer)
        cont = self.m.process_events()

        self._assertCallsEqual(m_select, [call([], [wfd], [], SELECT_INTERVAL)])
        self._assertCallsEqual(
            m_sinkbuffer,
            [call.pending(),
             call.take(),
             call.put_back('bar'),
             call.pending()])
        self._assertCallsEqual(m_write, [call(wfd, 'foobar')])
        self.assertEqual(True, cont)
Ejemplo n.º 3
0
    def test_write_close(self):
        m_select = self._patch('select.select')
        m_close = self._patch('os.close')

        wfd = 42
        m_sinkbuffer = self._make_mock()
        m_sinkbuffer.pending.return_value = True
        m_sinkbuffer.take.return_value = None
        m_select.return_value = ([], [wfd], [])

        self.m.add_sink(wfd, m_sinkbuffer)
        cont = self.m.process_events()

        self._assertCallsEqual(m_select, [call([], [wfd], [], SELECT_INTERVAL)])
        self._assertCallsEqual(
            m_sinkbuffer,
            [call.pending(),
             call.take()])
        self._assertCallsEqual(m_close, [call(wfd)])
        self.assertEqual(False, cont)