[pypy-svn] r50715 - in pypy/dist/pypy/module/select: . test

exarkun at codespeak.net exarkun at codespeak.net
Thu Jan 17 17:54:58 CET 2008


Author: exarkun
Date: Thu Jan 17 17:54:58 2008
New Revision: 50715

Modified:
   pypy/dist/pypy/module/select/app_select.py
   pypy/dist/pypy/module/select/test/test_select.py
Log:
Fix select readability of write pipes

Add a test asserting that the write end of a pipe is indicated
as readable by select when the read end has been closed.  The
read set indicates either that data may be available or that
the file descriptor is at EOF.

There are probably still some bugs in select.select() (particularly the
exception set).


Modified: pypy/dist/pypy/module/select/app_select.py
==============================================================================
--- pypy/dist/pypy/module/select/app_select.py	(original)
+++ pypy/dist/pypy/module/select/app_select.py	Thu Jan 17 17:54:58 2008
@@ -63,7 +63,7 @@
     else:
         ret = dict(p.poll())
 
-    iretd = [ f for f in iwtd if ret.get(fddict[id(f)], 0) & (POLLIN|POLLHUP)]
+    iretd = [ f for f in iwtd if ret.get(fddict[id(f)], 0) & (POLLIN|POLLHUP|POLLERR)]
     oretd = [ f for f in owtd if ret.get(fddict[id(f)], 0) & POLLOUT]
     eretd = [ f for f in ewtd if ret.get(fddict[id(f)], 0) & (POLLERR|POLLPRI)]
 

Modified: pypy/dist/pypy/module/select/test/test_select.py
==============================================================================
--- pypy/dist/pypy/module/select/test/test_select.py	(original)
+++ pypy/dist/pypy/module/select/test/test_select.py	Thu Jan 17 17:54:58 2008
@@ -38,6 +38,21 @@
             writeend.close()
             readend.close()
 
+    def test_writable(self):
+        """
+        select.select returns elements from the "write list" (the second
+        parameter) on which a write/send may be possible.
+        """
+        import select
+        readend, writeend = getpair()
+        try:
+            iwtd, owtd, ewtd = select.select([], [writeend], [], 0)
+            assert iwtd == ewtd == []
+            assert owtd == [writeend]
+        finally:
+            writeend.close()
+            readend.close()
+
     def test_write_read(self):
         """
         select.select returns elements from the "write list" (the second
@@ -73,7 +88,7 @@
             writeend.close()
             readend.close()
 
-    def test_close(self):
+    def test_write_close(self):
         """
         select.select returns elements from the "read list" (the first
         parameter) which have no data to be read but which have been closed.
@@ -106,6 +121,22 @@
         finally:
             readend.close()
 
+    def test_read_closed(self):
+        """
+        select.select returns elements from the "read list" (the first
+        parameter) which are at eof (even if they are the write end of a
+        pipe).
+        """
+        import select
+        readend, writeend = getpair()
+        try:
+            readend.close()
+            iwtd, owtd, ewtd = select.select([writeend], [], [], 0)
+            assert iwtd == [writeend]
+            assert owtd == ewtd == []
+        finally:
+            writeend.close()
+
     def test_read_many(self):
         """
         select.select returns only the elements from the "read list" (the



More information about the Pypy-commit mailing list