]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Various minor test changes for windows.
authorBen Darnell <ben@bendarnell.com>
Sat, 3 Sep 2011 20:27:28 +0000 (13:27 -0700)
committerBen Darnell <ben@bendarnell.com>
Sat, 3 Sep 2011 20:27:28 +0000 (13:27 -0700)
tornado/autoreload.py
tornado/test/httpclient_test.py
tornado/test/httpserver_test.py
tornado/test/process_test.py
tornado/test/simple_httpclient_test.py
tornado/test/twisted_test.py

index bdd46b7a078f2ae41d5337217bcd9a601b5563dd..7e3a3d73c330ee46482513d9d285ec6616d2b510 100644 (file)
@@ -241,9 +241,10 @@ if __name__ == "__main__":
     # Conversely, when run as path/to/tornado/autoreload.py, the directory
     # containing autoreload.py gets added to the path, but we don't want
     # tornado modules importable at top level, so remove it.
+    path_prefix = '.' + os.pathsep
     if (sys.path[0] == '' and
-        not os.environ.get("PYTHONPATH", "").startswith(".:")):
-        os.environ["PYTHONPATH"] = ".:" + os.environ.get("PYTHONPATH", "")
+        not os.environ.get("PYTHONPATH", "").startswith(path_prefix)):
+        os.environ["PYTHONPATH"] = path_prefix + os.environ.get("PYTHONPATH", "")
     elif sys.path[0] == os.path.dirname(__file__):
         del sys.path[0]
     main()
index 5fe776f7b18612c52beb2d2d91f03d9f9f4dda12..8388338b48c15ec50d4e34a32aad1e5caf26ad34 100644 (file)
@@ -4,6 +4,8 @@ from __future__ import with_statement
 
 import base64
 import binascii
+from contextlib import closing
+import functools
 
 from tornado.escape import utf8
 from tornado.httpclient import AsyncHTTPClient
@@ -109,11 +111,9 @@ class HTTPClientCommonTestCase(AsyncHTTPTestCase, LogTrapTestCase):
         # over several ioloop iterations, but the connection is already closed.
         port = get_unused_port()
         (sock,) = netutil.bind_sockets(port, address="127.0.0.1")
-        def accept_callback(conn, address):
-            # fake an HTTP server using chunked encoding where the final chunks
-            # and connection close all happen at once
-            stream = IOStream(conn, io_loop=self.io_loop)
-            stream.write(b("""\
+        with closing(sock):
+            def write_response(stream, request_data):
+                stream.write(b("""\
 HTTP/1.1 200 OK
 Transfer-Encoding: chunked
 
@@ -124,11 +124,17 @@ Transfer-Encoding: chunked
 0
 
 """).replace(b("\n"), b("\r\n")), callback=stream.close)
-        netutil.add_accept_handler(sock, accept_callback, self.io_loop)
-        self.http_client.fetch("http://127.0.0.1:%d/" % port, self.stop)
-        resp = self.wait()
-        resp.rethrow()
-        self.assertEqual(resp.body, b("12"))
+            def accept_callback(conn, address):
+                # fake an HTTP server using chunked encoding where the final chunks
+                # and connection close all happen at once
+                stream = IOStream(conn, io_loop=self.io_loop)
+                stream.read_until(b("\r\n\r\n"),
+                                  functools.partial(write_response, stream))
+            netutil.add_accept_handler(sock, accept_callback, self.io_loop)
+            self.http_client.fetch("http://127.0.0.1:%d/" % port, self.stop)
+            resp = self.wait()
+            resp.rethrow()
+            self.assertEqual(resp.body, b("12"))
         
 
     def test_basic_auth(self):
index 37c7b05fb1d4a7f56822f27f418732e3d0993380..c7fec50bcfb8e1099031716abcc9e89e3cd48828 100644 (file)
@@ -12,6 +12,7 @@ from tornado.web import Application, RequestHandler
 import os
 import shutil
 import socket
+import sys
 import tempfile
 
 try:
@@ -240,3 +241,6 @@ class UnixSocketTest(AsyncTestCase, LogTrapTestCase):
         stream.read_bytes(int(headers["Content-Length"]), self.stop)
         body = self.wait()
         self.assertEqual(body, b("Hello world"))
+
+if not hasattr(socket, 'AF_UNIX') or sys.platform == 'cygwin':
+    del UnixSocketTest
index b606e92088e574f5d4ecea4bf4bf95d6a7e80816..d1498fa287c0de7dae248b48db980e54088ac105 100644 (file)
@@ -3,6 +3,7 @@
 import logging
 import os
 import signal
+import sys
 from tornado.httpclient import HTTPClient, HTTPError
 from tornado.httpserver import HTTPServer
 from tornado.ioloop import IOLoop
@@ -109,6 +110,6 @@ class ProcessTest(LogTrapTestCase):
             raise
             
 
-if os.name != 'posix':
+if os.name != 'posix' or sys.platform == 'cygwin':
     # All sorts of unixisms here
     del ProcessTest
index 3ba14bf386464befabed6cefe673ba07feef2f08..9e674f01bed457e5daaa0162eaf75680cdfcc1fa 100644 (file)
@@ -138,7 +138,7 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
     def test_request_timeout(self):
         response = self.fetch('/hang', request_timeout=0.1)
         self.assertEqual(response.code, 599)
-        self.assertEqual(int(response.request_time * 10), 1)
+        self.assertTrue(0.099 < response.request_time < 0.11, response.request_time)
         self.assertEqual(str(response.error), "HTTP 599: Timeout")
 
     def test_ipv6(self):
index e182f264499c0a4cf578e111d9340103fed91a1c..56312458fabc01b16ef32f9a3e1dc89d7ff10bd3 100644 (file)
 Unittest for the twisted-style reactor.
 """
 
-import fcntl
 import os
-import sys
 import thread
 import threading
 import unittest
 
 try:
+    import fcntl
     import twisted
     from twisted.internet.interfaces import IReadDescriptor, IWriteDescriptor
     from tornado.platform.twisted import TornadoReactor
     from zope.interface import implements
 except ImportError:
+    fcntl = None
     twisted = None
     IReadDescriptor = IWriteDescriptor = None
     def implements(f): pass