Commit d099423c authored by Jason Madden's avatar Jason Madden

Fix tests on windows, where SelectSelector._select is a normal method.

parent 3d4404d2
...@@ -28,14 +28,17 @@ else: ...@@ -28,14 +28,17 @@ else:
try: try:
from select import poll as original_poll
from select import POLLIN, POLLOUT, POLLNVAL from select import POLLIN, POLLOUT, POLLNVAL
__implements__ = ['select', 'poll'] __implements__ = ['select', 'poll']
except ImportError: except ImportError:
original_poll = None POLLIN = 1
POLLOUT = 4
POLLNVAL = 32
__implements__ = ['select'] __implements__ = ['select']
__all__ = ['error'] + __implements__ __all__ = ['error'] + __implements__
if 'poll' not in __all__:
__all__.append('poll')
import select as __select__ import select as __select__
...@@ -184,8 +187,8 @@ def select(rlist, wlist, xlist, timeout=None): # pylint:disable=unused-argument ...@@ -184,8 +187,8 @@ def select(rlist, wlist, xlist, timeout=None): # pylint:disable=unused-argument
return result.select(rlist, wlist, timeout) return result.select(rlist, wlist, timeout)
if original_poll is not None:
class PollResult(object): class PollResult(object):
__slots__ = ('events', 'event') __slots__ = ('events', 'event')
def __init__(self): def __init__(self):
...@@ -205,13 +208,17 @@ if original_poll is not None: ...@@ -205,13 +208,17 @@ if original_poll is not None:
self.events.add((fd, result_flags)) self.events.add((fd, result_flags))
self.event.set() self.event.set()
class poll(object): class poll(object):
""" """
An implementation of :class:`select.poll` that blocks only the current greenlet. An implementation of :class:`select.poll` that blocks only the current greenlet.
.. caution:: ``POLLPRI`` data is not supported. .. caution:: ``POLLPRI`` data is not supported.
.. versionadded:: 1.1b1 .. versionadded:: 1.1b1
.. versionchanged:: 1.5
This is now always defined, regardless of whether the standard library
defines :func:`select.poll` or not. Note that it may have different performance
characteristics.
""" """
def __init__(self): def __init__(self):
# {int -> flags} # {int -> flags}
...@@ -298,8 +305,6 @@ if original_poll is not None: ...@@ -298,8 +305,6 @@ if original_poll is not None:
fileno = get_fileno(fd) fileno = get_fileno(fd)
del self.fds[fileno] del self.fds[fileno]
del original_poll
def _gevent_do_monkey_patch(patch_request): def _gevent_do_monkey_patch(patch_request):
aggressive = patch_request.patch_kwargs['aggressive'] aggressive = patch_request.patch_kwargs['aggressive']
...@@ -323,13 +328,19 @@ def _gevent_do_monkey_patch(patch_request): ...@@ -323,13 +328,19 @@ def _gevent_do_monkey_patch(patch_request):
# package? If so, must be careful to deal with DoNotPatch exceptions. # package? If so, must be careful to deal with DoNotPatch exceptions.
# Python 3 wants to use `select.select` as a member function, # Python 3 wants to use `select.select` as a member function,
# leading to this error in selectors.py (because gevent.select.select is # leading to this error in selectors.py (because
# not a builtin and doesn't get the magic auto-static that they do) # gevent.select.select is not a builtin and doesn't get the
# magic auto-static that they do):
#
# r, w, _ = self._select(self._readers, self._writers, [], timeout) # r, w, _ = self._select(self._readers, self._writers, [], timeout)
# TypeError: select() takes from 3 to 4 positional arguments but 5 were given # TypeError: select() takes from 3 to 4 positional arguments but 5 were given
# Note that this obviously only happens if selectors was imported after we had patched #
# select; but there is a code path that leads to it being imported first (but now we've # Note that this obviously only happens if selectors was
# patched select---so we can't compare them identically) # imported after we had patched select; but there is a code
# path that leads to it being imported first (but now we've
# patched select---so we can't compare them identically). It also doesn't
# happen on Windows, because they define a normal method for _select, to work around
# some weirdness in the handling of the third argument.
orig_select_select = patch_request.get_original('select', 'select') orig_select_select = patch_request.get_original('select', 'select')
assert target_mod.select is not orig_select_select assert target_mod.select is not orig_select_select
......
...@@ -21,6 +21,9 @@ patch_all() ...@@ -21,6 +21,9 @@ patch_all()
) )
class TestSelectors(greentest.TestCase): class TestSelectors(greentest.TestCase):
@greentest.skipOnWindows(
"SelectSelector._select is a normal function on Windows"
)
def test_selectors_select_is_patched(self): def test_selectors_select_is_patched(self):
# https://github.com/gevent/gevent/issues/835 # https://github.com/gevent/gevent/issues/835
_select = selectors.SelectSelector._select _select = selectors.SelectSelector._select
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment