From: Ben Darnell Date: Sat, 3 Sep 2011 20:27:28 +0000 (-0700) Subject: Various minor test changes for windows. X-Git-Tag: v2.1.0~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0142d2ee3b2bcc3d4d11a2047be2ad93adb5506;p=thirdparty%2Ftornado.git Various minor test changes for windows. --- diff --git a/tornado/autoreload.py b/tornado/autoreload.py index bdd46b7a0..7e3a3d73c 100644 --- a/tornado/autoreload.py +++ b/tornado/autoreload.py @@ -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() diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index 5fe776f7b..8388338b4 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -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): diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index 37c7b05fb..c7fec50bc 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -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 diff --git a/tornado/test/process_test.py b/tornado/test/process_test.py index b606e9208..d1498fa28 100644 --- a/tornado/test/process_test.py +++ b/tornado/test/process_test.py @@ -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 diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index 3ba14bf38..9e674f01b 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -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): diff --git a/tornado/test/twisted_test.py b/tornado/test/twisted_test.py index e182f2644..56312458f 100644 --- a/tornado/test/twisted_test.py +++ b/tornado/test/twisted_test.py @@ -17,19 +17,19 @@ 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