From: Ben Darnell Date: Tue, 28 Aug 2012 19:24:55 +0000 (-0400) Subject: Fix tests on windows X-Git-Tag: v2.4.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b76e79611c58728c8e7c84529d79f353df22dbc0;p=thirdparty%2Ftornado.git Fix tests on windows --- diff --git a/tornado/test/options_test.py b/tornado/test/options_test.py index 29ce177ff..72be4459c 100644 --- a/tornado/test/options_test.py +++ b/tornado/test/options_test.py @@ -63,6 +63,7 @@ class LogFormatterTest(unittest.TestCase): self.logger.addHandler(self.handler) def tearDown(self): + self.handler.close() os.unlink(self.filename) os.rmdir(self.tempdir) diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index a9b541ea7..9c5ea89a3 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -2,10 +2,13 @@ from __future__ import absolute_import, division, with_statement import collections from contextlib import closing +import errno import gzip import logging +import os import re import socket +import sys from tornado.httpclient import AsyncHTTPClient from tornado.httputil import HTTPHeaders @@ -284,10 +287,20 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase): self.assertTrue(host_re.match(response.body), response.body) def test_connection_refused(self): - self.http_client.fetch("http://localhost:1/", self.stop) + port = get_unused_port() + self.http_client.fetch("http://localhost:%d/" % port, self.stop) response = self.wait() self.assertEqual(599, response.code) - self.assertTrue("Connection refused" in str(response.error)) + + if sys.platform != 'cygwin': + # cygwin returns EPERM instead of ECONNREFUSED here + self.assertTrue(str(errno.ECONNREFUSED) in str(response.error), + response.error) + # This is usually "Connection refused". + # On windows, strerror is broken and returns "Unknown error". + expected_message = os.strerror(errno.ECONNREFUSED) + self.assertTrue(expected_message in str(response.error), + response.error) class CreateAsyncHTTPClientTestCase(AsyncTestCase, LogTrapTestCase):