Commits

Enrico Ambrosini  committed b655e2f Merge

Bunch of fixes to the tests.

  • Participants
  • Parent commits f845b24, 11194fb

Comments (0)

Files changed (12)

 b80978a0201c08e8e8e29adaabdc628ec3f245c7 0.13.1b1
 151020147788c4081799f6194881be8bd6b212c3 0.13.1b2
 63e08a21e032fad45224c7f9f8054e1152964a03 0.13.1
+eaf32edeb23a20ab5978090f73dd5965c53ed549 0.13.2-wip

File examples/echoserver.py

 def echo(socket, address):
     print('New connection from %s:%s' % address)
     # using a makefile because we want to use readline()
-    fileobj = socket.makefile()
+    fileobj = socket.makefile(mode='rw')
     fileobj.write('Welcome to the echo server! Type quit to exit.\r\n')
     fileobj.flush()
     while True:

File gevent/core.pyx

         cdef char pbuf[30]
         cdef levent.evutil_addrinfo hints
 
-        if isinstance(host, str):
+        if host is None:
+            pass
+        elif isinstance(host, str):
             host = host.encode('idna')
             nodename = host
         elif isinstance(host, bytes):
 
         if isinstance(port, str):
             port = port.encode('ascii')
-
-        if isinstance(port, (int, long)):
+        if port is None:
+            pass
+        elif isinstance(port, (int, long)):
             PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", <long>port)
             servname = pbuf
         else:
                 result.append((res.ai_family,
                                res.ai_socktype,
                                res.ai_protocol,
-                               canonname,
+                               canonname.decode('ascii'),
                                makesockaddr(-1, res.ai_addr, res.ai_addrlen, res.ai_protocol)))
                 res = res.ai_next
             callback(result, None)

File gevent/socket.py

                                 (self._closed and " [closed] ") or "",
                                 s[7:])
         return s
-        return '<%s at %s %s>' % (type(self).__name__, hex(id(self)), self._formatinfo())
+        #return '<%s at %s %s>' % (type(self).__name__, hex(id(self)), self._formatinfo())
 
     def __str__(self):
         return '<%s %s>' % (type(self).__name__, self._formatinfo())
                 sock.settimeout(timeout)
             if source_address:
                 sock.bind(source_address)
+            print('sock.connect: %s' % sock.connect)
             sock.connect(sa)
             return sock
         except error:

File gevent/socketmodule.c

         set_gaierror(error);
         return NULL;
     }
-    return PyBytes_FromString(buf);
+    return PyUnicode_FromString(buf);
 }
 
 
 #ifdef linux
         if (a->sun_path[0] == 0) {  /* Linux abstract namespace */
             addrlen -= offsetof(struct sockaddr_un, sun_path);
-            return PyBytes_FromStringAndSize(a->sun_path,
-                                              addrlen);
+            return PyUnicode_FromStringAndSize(a->sun_path,
+                                               addrlen);
         }
         else
 #endif /* linux */
         {
             /* regular NULL-terminated string */
-            return PyBytes_FromString(a->sun_path);
+            return PyUnicode_FromString(a->sun_path);
         }
     }
 #endif /* AF_UNIX */

File greentest/test__examples.py

 
     def test(self):
         def test_client(message):
-            conn = socket.create_connection(('127.0.0.1', 6000)).makefile(bufsize=1)
+            conn = socket.create_connection(('127.0.0.1', 6000)).makefile(mode='rw', buffering=1)
             welcome = conn.readline()
             assert 'Welcome' in welcome, repr(welcome)
             conn.write(message)

File greentest/test__server.py

         try:
             self.send_request()
         except socket.error as ex:
-            if ex[0] != errno.ECONNRESET:
+            if ex.errno != errno.ECONNRESET:
                 raise
 
     @staticmethod
             conn = self.makefile()
             raise AssertionError('Connection was not refused: %r' % (conn._sock, ))
         except socket.error as ex:
-            if ex[0] not in (errno.ECONNREFUSED, errno.EADDRNOTAVAIL):
+            if ex.errno not in (errno.ECONNREFUSED, errno.EADDRNOTAVAIL):
                 raise
 
     def assert500(self):
                 if result:
                     assert result.startswith('HTTP/1.0 500 Internal Server Error'), repr(result)
             except socket.error as ex:
-                if ex[0] != errno.ECONNRESET:
+                if ex.errno != errno.ECONNRESET:
                     raise
         finally:
             timeout.cancel()

File greentest/test__socket_errors.py

         try:
             s.connect(('127.0.0.1', 81))
         except error as ex:
-            assert ex[0] == ECONNREFUSED, repr(ex)
+            assert ex.errno == ECONNREFUSED, repr(ex)
             assert 'refused' in str(ex).lower(), str(ex)
 
 

File greentest/test_socketserver.py

         self.server_close()
         raise
 
-teststring = "hello world\n"
+teststring = b"hello world\n"
 
 def receive(sock, n, timeout=5):
     r, w, x = select.select([sock], [], [], timeout)
 
 def testdgram(proto, addr):
     s = socket.socket(proto, socket.SOCK_DGRAM)
-    s.sendto(teststring, addr)
+    # sendto() wants 3 positional arguments, so we specify
+    # the default value for flags, which is 0.
+    s.sendto(teststring, 0, addr)
     buf = data = receive(s, 100)
-    while data and '\n' not in buf:
+    while data and b'\n' not in buf:
         data = receive(s, 100)
         buf += data
     verify(buf == teststring)
     s.connect(addr)
     s.sendall(teststring)
     buf = data = receive(s, 100)
-    while data and '\n' not in buf:
+    while data and b'\n' not in buf:
         data = receive(s, 100)
         buf += data
     verify(buf == teststring)

File greentest/test_threading_2.py

                 stderr=subprocess.PIPE)
             stdout, stderr = p.communicate()
             stdout = stdout.strip()
-            assert re.match('^Woke up, sleep function is: <.*?sleep.*?>$', stdout), repr(stdout)
-            stderr = re.sub(r"^\[\d+ refs\]", "", stderr, re.MULTILINE).strip()
+            assert re.match(b'^Woke up, sleep function is: <.*?sleep.*?>$', stdout), repr(stdout)
+            stderr = re.sub(br"^\[\d+ refs\]", "", stderr, re.MULTILINE).strip()
             self.assertEqual(stderr, "")
 
     def test_enumerate_after_join(self):
         import subprocess
         p = subprocess.Popen([sys.executable, "-c", script], stdout=subprocess.PIPE)
         rc = p.wait()
-        data = p.stdout.read().replace('\r', '')
-        self.assertEqual(data, "end of main\nend of thread\n")
+        data = p.stdout.read().replace(b'\r', b'')
+        self.assertEqual(data, b"end of main\nend of thread\n")
         self.failIf(rc == 2, "interpreter was blocked")
         self.failUnless(rc == 0, "Unexpected error")
 

File greentest/testsuite.txt

+# The "tuples" in the results column, if present, represents different result on Windows and Linux respectively
 test_hub_shutdown.py                PASS
 test_patched_asyncore.py            PASS - Some "did not switch" warnings
 test_patched_ftplib.py              PASS
 test_patched_httplib.py             PASS - Lots of warnings
-test_patched_httpservers.py         FAIL - timeouts on test_post
+test_patched_httpservers.py         PASS
 test_patched_queue.py               PASS - Lots of warnings
-test_patched_select.py              SKIP - can't easily test on this system
+test_patched_select.py              (SKIP - can't easily test on this system, PASS)
 test_patched_smtplib.py             PASS
-test_patched_socket.py              FAIL - multiple errors (errors=2, skipped=2 over 132 tests)
+test_patched_socket.py              (Must recheck, PASS)
 test_patched_socket_ssl.py          FAIL - Can't find module test_socket_ssl
 test_patched_ssl.py                 FAIL - Interpreter crash
 test_patched_telnetlib.py           PASS - Some "did not switch" warnings
 test_patched_threading_local.py     PASS
 test_patched_timeout.py             PASS
 test_patched_urllib.py              PASS - Many "did not switch" warnings
-test_patched_urllib2.py             FAIL - file not on local host
+test_patched_urllib2.py             (FAIL - file not on local host, PASS)
 test_patched_urllib2net.py          PASS - with WARNING: OtherNetworkTests.setUp does not call base class setUp
 test_patched_urllib2_localnet.py    PASS
 test_patched_wsgiref.py             PASS - All "did not switch" warnings
 test_queue.py                       PASS
-test_socketserver.py                FAIL - sendto() args mismatch and Type str doesn't support the buffer API
+test_socketserver.py                PASS
 test_ssl.py                         FAIL - Interpreter crash
 test_support.py                     WTF?  - Doesn't run
 test_thread.py                      PASS
 test__api_timeout.py                PASS
 test__backdoor.py                   FAIL - _socket.socket miss accept() attribute
 test__benchmarks.py                 PASS
-test__core_active_event.py          PASS?
+test__core_active_event.py          PASS
 test__dns.py                        FAIL - dns_resolve_ipv4
-test__doctests.py                   FAIL
+test__doctests.py                   PASS
 test__event.py                      PASS
 test__examples.py                   FAIL - Py2 modules missing in Py3
 test__exc_info.py                   FAIL - Expected. exc_clear() isn't there anymore in py3
 test__server_wsgi.py                FAIL
 test__shutdown.py                   PASS
 test__signal.py                     PASS - but no tests!
-test__socket.py                     FAIL - 1 over 5: RuntimeError: test is taking too long
+test__socket.py                     (FAIL - RuntimeError: test is taking too long, PASS)
 test__socket_close.py               PASS
 test__socket_dns.py                 FAIL - unicode/bytes mismatchs
-test__socket_errors.py              FAIL - test is taking too long
+test__socket_errors.py              (Must recheck, PASS)
 test__socket_ssl.py                 SKIP
 test__socket_timeout.py             PASS
 test__threading_patched_local.py    PASS?
 
     def initialize_options(self):
         build_ext.build_ext.initialize_options(self)
-        self.cython = "cython.py"
+        self.cython = "cython"
 
     def compile_cython(self):
         if os.path.exists(cython_output):