[pypy-svn] r18554 - in pypy/dist/pypy/module/_socket: . test

dialtone at codespeak.net dialtone at codespeak.net
Fri Oct 14 16:56:32 CEST 2005


Author: dialtone
Date: Fri Oct 14 16:56:30 2005
New Revision: 18554

Modified:
   pypy/dist/pypy/module/_socket/interp_socket.py
   pypy/dist/pypy/module/_socket/test/test_socket2.py
Log:
(valentino, afa)
add missing test for fromfd
whitespace cleanup
change wrong definition of _socket.fromfd


Modified: pypy/dist/pypy/module/_socket/interp_socket.py
==============================================================================
--- pypy/dist/pypy/module/_socket/interp_socket.py	(original)
+++ pypy/dist/pypy/module/_socket/interp_socket.py	Fri Oct 14 16:56:30 2005
@@ -77,11 +77,11 @@
     Create a socket object from the given file descriptor.
     The remaining arguments are the same as for socket().
     """
-    if proto is None:
+    if w_proto is None:
         return space.wrap(socket.fromfd(fd, family, type))
     else:
-        return space.wrap(socket.fromfd(fd, family, type, space.int_w(proto)))
-fromfd.unwrap_spec = [ObjSpace, int, int, int, int]
+        return space.wrap(socket.fromfd(fd, family, type, space.int_w(w_proto)))
+fromfd.unwrap_spec = [ObjSpace, int, int, int, W_Root]
 
 #    fromfd socketpair
 #    ntohs ntohl htons htonl inet_aton inet_ntoa inet_pton inet_ntop

Modified: pypy/dist/pypy/module/_socket/test/test_socket2.py
==============================================================================
--- pypy/dist/pypy/module/_socket/test/test_socket2.py	(original)
+++ pypy/dist/pypy/module/_socket/test/test_socket2.py	Fri Oct 14 16:56:30 2005
@@ -1,12 +1,14 @@
-from pypy.objspace.std import StdObjSpace 
+from pypy.objspace.std import StdObjSpace
 from pypy.tool.udir import udir
 import py
 import socket, sys
 
-def setup_module(mod): 
+def setup_module(mod):
     mod.space = StdObjSpace(usemodules=['_socket'])
     mod.w_socket = space.appexec([], "(): import _socket as m; return m")
-    
+    mod.path = udir.join('fd')
+    mod.path.write('fo')
+
 def test_gethostname():
     host = space.appexec([w_socket], "(_socket): return _socket.gethostname()")
     assert space.unwrap(host) == socket.gethostname()
@@ -62,7 +64,7 @@
                          except TypeError:
                              return 'OK'
                          """)
-    assert space.unwrap(name) == 'OK' 
+    assert space.unwrap(name) == 'OK'
     # 1 arg version
     name = space.appexec([w_socket, space.wrap(port)],
                          "(_socket, port): return _socket.getservbyport(port)")
@@ -73,9 +75,24 @@
     num = space.appexec([w_socket, space.wrap(name)],
                         "(_socket, name): return _socket.getprotobyname(name)")
     assert space.unwrap(num) == socket.IPPROTO_TCP
-    
 
 def test_has_ipv6():
     res = space.appexec([w_socket], "(_socket): return _socket.has_ipv6")
     assert space.unwrap(res) == socket.has_ipv6
 
+def test_fromfd():
+    # XXX review
+    orig_fd = path.open()
+    fd = space.appexec([w_socket, space.wrap(orig_fd.fileno()),
+            space.wrap(socket.AF_INET), space.wrap(socket.SOCK_STREAM),
+            space.wrap(0)],
+           """(_socket, fd, family, type, proto): 
+                 return _socket.fromfd(fd, family, type, proto)""")
+
+    assert space.unwrap(fd).fileno()
+    fd = space.appexec([w_socket, space.wrap(orig_fd.fileno()),
+            space.wrap(socket.AF_INET), space.wrap(socket.SOCK_STREAM)],
+                """(_socket, fd, family, type):
+                    return _socket.fromfd(fd, family, type)""")
+
+    assert space.unwrap(fd).fileno()



More information about the Pypy-commit mailing list