示例#1
0
    def test_select(self, __select):
        ebadf = socket.error()
        ebadf.errno = errno.EBADF
        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.return_value = {3}, set(), 0
            assert asynpool._select({3}, poll=poll) == ({3}, set(), 0)

            poll.return_value = {3}, set(), 0
            assert asynpool._select({3}, None, {3}, poll=poll) == (
                {3},
                set(),
                0,
            )

            eintr = socket.error()
            eintr.errno = errno.EINTR
            poll.side_effect = eintr

            readers = {3}
            assert asynpool._select(readers, poll=poll) == (set(), set(), 1)
            assert 3 in readers

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.side_effect = ebadf
            with patch('select.select') as selcheck:
                selcheck.side_effect = ebadf
                readers = {3}
                assert asynpool._select(readers, poll=poll) == (
                    set(),
                    set(),
                    1,
                )
                assert 3 not in readers

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.side_effect = MemoryError()
            with pytest.raises(MemoryError):
                asynpool._select({1}, poll=poll)

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            with patch('select.select') as selcheck:

                def se(*args):
                    selcheck.side_effect = MemoryError()
                    raise ebadf

                poll.side_effect = se
                with pytest.raises(MemoryError):
                    asynpool._select({3}, poll=poll)

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            with patch('select.select') as selcheck:

                def se2(*args):
                    selcheck.side_effect = socket.error()
                    selcheck.side_effect.errno = 1321
                    raise ebadf

                poll.side_effect = se2
                with pytest.raises(socket.error):
                    asynpool._select({3}, poll=poll)

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')

            poll.side_effect = socket.error()
            poll.side_effect.errno = 34134
            with pytest.raises(socket.error):
                asynpool._select({3}, poll=poll)
示例#2
0
    def test_select(self):
        ebadf = socket.error()
        ebadf.errno = errno.EBADF
        with patch('select.select') as select:
            select.return_value = ([3], [], [])
            self.assertEqual(
                asynpool._select(set([3])),
                ([3], [], 0),
            )

            select.return_value = ([], [], [3])
            self.assertEqual(
                asynpool._select(set([3]), None, set([3])),
                ([3], [], 0),
            )

            eintr = socket.error()
            eintr.errno = errno.EINTR
            select.side_effect = eintr

            readers = set([3])
            self.assertEqual(asynpool._select(readers), ([], [], 1))
            self.assertIn(3, readers)

        with patch('select.select') as select:
            select.side_effect = ebadf
            readers = set([3])
            self.assertEqual(asynpool._select(readers), ([], [], 1))
            select.assert_has_calls([call([3], [], [], 0)])
            self.assertNotIn(3, readers)

        with patch('select.select') as select:
            select.side_effect = MemoryError()
            with self.assertRaises(MemoryError):
                asynpool._select(set([1]))

        with patch('select.select') as select:

            def se(*args):
                select.side_effect = MemoryError()
                raise ebadf
            select.side_effect = se
            with self.assertRaises(MemoryError):
                asynpool._select(set([3]))

        with patch('select.select') as select:

            def se2(*args):
                select.side_effect = socket.error()
                select.side_effect.errno = 1321
                raise ebadf
            select.side_effect = se2
            with self.assertRaises(socket.error):
                asynpool._select(set([3]))

        with patch('select.select') as select:

            select.side_effect = socket.error()
            select.side_effect.errno = 34134
            with self.assertRaises(socket.error):
                asynpool._select(set([3]))
示例#3
0
    def test_select(self, __select):
        ebadf = socket.error()
        ebadf.errno = errno.EBADF
        with patch("select.poll", create=True) as poller:
            poll = poller.return_value = Mock(name="poll.poll")
            poll.return_value = {3}, set(), 0
            self.assertEqual(asynpool._select({3}, poll=poll), ({3}, set(), 0))

            poll.return_value = {3}, set(), 0
            self.assertEqual(asynpool._select({3}, None, {3}, poll=poll), ({3}, set(), 0))

            eintr = socket.error()
            eintr.errno = errno.EINTR
            poll.side_effect = eintr

            readers = {3}
            self.assertEqual(asynpool._select(readers, poll=poll), (set(), set(), 1))
            self.assertIn(3, readers)

        with patch("select.poll") as poller:
            poll = poller.return_value = Mock(name="poll.poll")
            poll.side_effect = ebadf
            with patch("select.select") as selcheck:
                selcheck.side_effect = ebadf
                readers = {3}
                self.assertEqual(asynpool._select(readers, poll=poll), (set(), set(), 1))
                self.assertNotIn(3, readers)

        with patch("select.poll") as poller:
            poll = poller.return_value = Mock(name="poll.poll")
            poll.side_effect = MemoryError()
            with self.assertRaises(MemoryError):
                asynpool._select({1}, poll=poll)

        with patch("select.poll") as poller:
            poll = poller.return_value = Mock(name="poll.poll")
            with patch("select.select") as selcheck:

                def se(*args):
                    selcheck.side_effect = MemoryError()
                    raise ebadf

                poll.side_effect = se
                with self.assertRaises(MemoryError):
                    asynpool._select({3}, poll=poll)

        with patch("select.poll") as poller:
            poll = poller.return_value = Mock(name="poll.poll")
            with patch("select.select") as selcheck:

                def se2(*args):
                    selcheck.side_effect = socket.error()
                    selcheck.side_effect.errno = 1321
                    raise ebadf

                poll.side_effect = se2
                with self.assertRaises(socket.error):
                    asynpool._select({3}, poll=poll)

        with patch("select.poll") as poller:
            poll = poller.return_value = Mock(name="poll.poll")

            poll.side_effect = socket.error()
            poll.side_effect.errno = 34134
            with self.assertRaises(socket.error):
                asynpool._select({3}, poll=poll)
示例#4
0
    def test_select(self, __select):
        ebadf = socket.error()
        ebadf.errno = errno.EBADF
        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.return_value = {3}, set(), 0
            self.assertEqual(
                asynpool._select({3}, poll=poll),
                ({3}, set(), 0),
            )

            poll.return_value = {3}, set(), 0
            self.assertEqual(
                asynpool._select({3}, None, {3}, poll=poll),
                ({3}, set(), 0),
            )

            eintr = socket.error()
            eintr.errno = errno.EINTR
            poll.side_effect = eintr

            readers = {3}
            self.assertEqual(
                asynpool._select(readers, poll=poll),
                (set(), set(), 1),
            )
            self.assertIn(3, readers)

        with patch('select.poll') as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.side_effect = ebadf
            with patch('select.select') as selcheck:
                selcheck.side_effect = ebadf
                readers = {3}
                self.assertEqual(
                    asynpool._select(readers, poll=poll),
                    (set(), set(), 1),
                )
                self.assertNotIn(3, readers)

        with patch('select.poll') as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.side_effect = MemoryError()
            with self.assertRaises(MemoryError):
                asynpool._select({1}, poll=poll)

        with patch('select.poll') as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            with patch('select.select') as selcheck:

                def se(*args):
                    selcheck.side_effect = MemoryError()
                    raise ebadf

                poll.side_effect = se
                with self.assertRaises(MemoryError):
                    asynpool._select({3}, poll=poll)

        with patch('select.poll') as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            with patch('select.select') as selcheck:

                def se2(*args):
                    selcheck.side_effect = socket.error()
                    selcheck.side_effect.errno = 1321
                    raise ebadf

                poll.side_effect = se2
                with self.assertRaises(socket.error):
                    asynpool._select({3}, poll=poll)

        with patch('select.poll') as poller:
            poll = poller.return_value = Mock(name='poll.poll')

            poll.side_effect = socket.error()
            poll.side_effect.errno = 34134
            with self.assertRaises(socket.error):
                asynpool._select({3}, poll=poll)
示例#5
0
    def test_select(self):
        ebadf = socket.error()
        ebadf.errno = errno.EBADF
        with patch("select.select") as select:
            select.return_value = ([3], [], [])
            self.assertEqual(asynpool._select({3}), ([3], [], 0))

            select.return_value = ([], [], [3])
            self.assertEqual(asynpool._select({3}, None, {3}), ([3], [], 0))

            eintr = socket.error()
            eintr.errno = errno.EINTR
            select.side_effect = eintr

            readers = {3}
            self.assertEqual(asynpool._select(readers), ([], [], 1))
            self.assertIn(3, readers)

        with patch("select.select") as select:
            select.side_effect = ebadf
            readers = {3}
            self.assertEqual(asynpool._select(readers), ([], [], 1))
            select.assert_has_calls([call([3], [], [], 0)])
            self.assertNotIn(3, readers)

        with patch("select.select") as select:
            select.side_effect = MemoryError()
            with self.assertRaises(MemoryError):
                asynpool._select({1})

        with patch("select.select") as select:

            def se(*args):
                select.side_effect = MemoryError()
                raise ebadf

            select.side_effect = se
            with self.assertRaises(MemoryError):
                asynpool._select({3})

        with patch("select.select") as select:

            def se2(*args):
                select.side_effect = socket.error()
                select.side_effect.errno = 1321
                raise ebadf

            select.side_effect = se2
            with self.assertRaises(socket.error):
                asynpool._select({3})

        with patch("select.select") as select:

            select.side_effect = socket.error()
            select.side_effect.errno = 34134
            with self.assertRaises(socket.error):
                asynpool._select({3})
示例#6
0
    def test_select(self, __select):
        ebadf = socket.error()
        ebadf.errno = errno.EBADF
        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.return_value = {3}, set(), 0
            assert asynpool._select({3}, poll=poll) == ({3}, set(), 0)

            poll.return_value = {3}, set(), 0
            assert asynpool._select({3}, None, {3}, poll=poll) == (
                {3}, set(), 0,
            )

            eintr = socket.error()
            eintr.errno = errno.EINTR
            poll.side_effect = eintr

            readers = {3}
            assert asynpool._select(readers, poll=poll) == (set(), set(), 1)
            assert 3 in readers

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.side_effect = ebadf
            with patch('select.select') as selcheck:
                selcheck.side_effect = ebadf
                readers = {3}
                assert asynpool._select(readers, poll=poll) == (
                    set(), set(), 1,
                )
                assert 3 not in readers

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            poll.side_effect = MemoryError()
            with pytest.raises(MemoryError):
                asynpool._select({1}, poll=poll)

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            with patch('select.select') as selcheck:

                def se(*args):
                    selcheck.side_effect = MemoryError()
                    raise ebadf
                poll.side_effect = se
                with pytest.raises(MemoryError):
                    asynpool._select({3}, poll=poll)

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')
            with patch('select.select') as selcheck:

                def se2(*args):
                    selcheck.side_effect = socket.error()
                    selcheck.side_effect.errno = 1321
                    raise ebadf
                poll.side_effect = se2
                with pytest.raises(socket.error):
                    asynpool._select({3}, poll=poll)

        with patch('select.poll', create=True) as poller:
            poll = poller.return_value = Mock(name='poll.poll')

            poll.side_effect = socket.error()
            poll.side_effect.errno = 34134
            with pytest.raises(socket.error):
                asynpool._select({3}, poll=poll)