diff --git a/tornado/iostream.py b/tornado/iostream.py index 0ec3bd6f83..18b4460acd 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -43,6 +43,11 @@ except ImportError: ssl = None +try: + from tornado.platform.posix import _set_nonblocking +except ImportError: + _set_nonblocking = None + class BaseIOStream(object): """A utility class to write to and read from a non-blocking file or socket. @@ -804,7 +809,6 @@ class PipeIOStream(BaseIOStream): by `os.pipe`) rather than an open file object. """ def __init__(self, fd, *args, **kwargs): - from tornado.platform.posix import _set_nonblocking self.fd = fd _set_nonblocking(fd) super(PipeIOStream, self).__init__(*args, **kwargs) diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index 9f5b5cf09c..119a4f6cd8 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -4,7 +4,7 @@ from tornado.iostream import IOStream, SSLIOStream, PipeIOStream from tornado.log import gen_log from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, bind_unused_port, ExpectLog -from tornado.test.util import unittest +from tornado.test.util import unittest, skipIfNonUnix from tornado.util import b from tornado.web import RequestHandler, Application import errno @@ -415,3 +415,4 @@ def test_pipe_iostream(self): self.assertEqual(data, b("ld")) rs.close() +TestPipeIOStream = skipIfNonUnix(TestPipeIOStream) diff --git a/tornado/test/process_test.py b/tornado/test/process_test.py index 950aa8d454..7bd7503407 100644 --- a/tornado/test/process_test.py +++ b/tornado/test/process_test.py @@ -14,7 +14,7 @@ from tornado.process import fork_processes, task_id, Subprocess from tornado.simple_httpclient import SimpleAsyncHTTPClient from tornado.testing import bind_unused_port, ExpectLog, AsyncTestCase -from tornado.test.util import unittest +from tornado.test.util import unittest, skipIfNonUnix from tornado.util import b from tornado.web import RequestHandler, Application @@ -120,8 +120,7 @@ def fetch(url, fail_ok=False): except Exception: logging.error("exception in child process %d", id, exc_info=True) raise -ProcessTest = unittest.skipIf(os.name != 'posix' or sys.platform == 'cygwin', - "non-unix platform")(ProcessTest) +ProcessTest = skipIfNonUnix(ProcessTest) class SubprocessTest(AsyncTestCase): @@ -167,3 +166,4 @@ def test_sigchild_signal(self): self.assertEqual(subproc.returncode, ret) self.assertTrue(os.WIFSIGNALED(ret)) self.assertEqual(os.WTERMSIG(ret), signal.SIGTERM) +SubprocessTest = skipIfNonUnix(SubprocessTest) diff --git a/tornado/test/util.py b/tornado/test/util.py index 26d843d5bf..b048b5027f 100644 --- a/tornado/test/util.py +++ b/tornado/test/util.py @@ -1,5 +1,6 @@ from __future__ import absolute_import, division, with_statement +import os import sys # Encapsulate the choice of unittest or unittest2 here. @@ -8,3 +9,6 @@ import unittest else: import unittest2 as unittest + +skipIfNonUnix = unittest.skipIf(os.name != 'posix' or sys.platform == 'cygwin', + "non-unix platform")