Esempio n. 1
0
    def test_close(self, m_read):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)

        tr._close = unittest.mock.Mock()
        tr.close()
        tr._close.assert_called_with(None)
Esempio n. 2
0
    def test_close_already_closing(self, m_read):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)

        tr._closing = True
        tr._close = unittest.mock.Mock()
        tr.close()
        self.assertFalse(tr._close.called)
Esempio n. 3
0
    def test__read_ready(self, m_read):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)
        m_read.return_value = b'data'
        tr._read_ready()

        m_read.assert_called_with(5, tr.max_size)
        self.protocol.data_received.assert_called_with(b'data')
Esempio n. 4
0
    def test_pause_reading(self, m_read):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)

        m = unittest.mock.Mock()
        self.loop.add_reader(5, m)
        tr.pause_reading()
        self.assertFalse(self.loop.readers)
Esempio n. 5
0
    def test__read_ready_blocked(self, m_read):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)
        m_read.side_effect = BlockingIOError
        tr._read_ready()

        m_read.assert_called_with(5, tr.max_size)
        test_utils.run_briefly(self.loop)
        self.assertFalse(self.protocol.data_received.called)
Esempio n. 6
0
    def test__close(self, m_read):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)

        err = object()
        tr._close(err)
        self.assertTrue(tr._closing)
        self.assertFalse(self.loop.readers)
        test_utils.run_briefly(self.loop)
        self.protocol.connection_lost.assert_called_with(err)
Esempio n. 7
0
 def _make_read_pipe_transport(self,
                               pipe,
                               protocol,
                               waiter=None,
                               extra=None):
     if sys.platform != 'win32':
         from asyncio import unix_events
         return unix_events._UnixReadPipeTransport(self, pipe, protocol,
                                                   waiter, extra)
     raise NotImplementedError
Esempio n. 8
0
    def test__read_ready_error(self, m_read, m_logexc):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)
        err = OSError()
        m_read.side_effect = err
        tr._close = unittest.mock.Mock()
        tr._read_ready()

        m_read.assert_called_with(5, tr.max_size)
        tr._close.assert_called_with(err)
        m_logexc.assert_called_with('Fatal error for %s', tr)
Esempio n. 9
0
    def test__read_ready_eof(self, m_read):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)
        m_read.return_value = b''
        tr._read_ready()

        m_read.assert_called_with(5, tr.max_size)
        self.assertFalse(self.loop.readers)
        test_utils.run_briefly(self.loop)
        self.protocol.eof_received.assert_called_with()
        self.protocol.connection_lost.assert_called_with(None)
Esempio n. 10
0
    def test__call_connection_lost_with_err(self):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)

        err = OSError()
        tr._call_connection_lost(err)
        self.protocol.connection_lost.assert_called_with(err)
        self.pipe.close.assert_called_with()

        self.assertIsNone(tr._protocol)
        self.assertEqual(2, sys.getrefcount(self.protocol),
                         pprint.pformat(gc.get_referrers(self.protocol)))
        self.assertIsNone(tr._loop)
        self.assertEqual(2, sys.getrefcount(self.loop),
                         pprint.pformat(gc.get_referrers(self.loop)))
Esempio n. 11
0
    def test_resume_reading(self, m_read):
        tr = unix_events._UnixReadPipeTransport(
            self.loop, self.pipe, self.protocol)

        tr.resume_reading()
        self.loop.assert_reader(5, tr._read_ready)
Esempio n. 12
0
 def test_ctor_with_waiter(self):
     fut = asyncio.Future(loop=self.loop)
     unix_events._UnixReadPipeTransport(
         self.loop, self.pipe, self.protocol, fut)
     test_utils.run_briefly(self.loop)
     self.assertIsNone(fut.result())
Esempio n. 13
0
 def test_ctor(self):
     tr = unix_events._UnixReadPipeTransport(
         self.loop, self.pipe, self.protocol)
     self.loop.assert_reader(5, tr._read_ready)
     test_utils.run_briefly(self.loop)
     self.protocol.connection_made.assert_called_with(tr)
Esempio n. 14
0
 def _make_read_pipe_transport(self, pipe, protocol, waiter=None, extra=None):
     if sys.platform != 'win32':
         from asyncio import unix_events
         return unix_events._UnixReadPipeTransport(self, pipe, protocol, waiter, extra)
     raise NotImplementedError