Commit f848ffac authored by Jason Madden's avatar Jason Madden

Fix test__greenio.py

parent bb77e1d2
...@@ -24,6 +24,15 @@ import sys ...@@ -24,6 +24,15 @@ import sys
PYPY = hasattr(sys, 'pypy_version_info') PYPY = hasattr(sys, 'pypy_version_info')
PY3 = sys.version_info[0] >= 3
def _write_to_closed(f, s):
try:
r = f.write(s)
except ValueError:
assert PY3
else:
assert r is None, r
class TestGreenIo(TestCase): class TestGreenIo(TestCase):
...@@ -35,13 +44,12 @@ class TestGreenIo(TestCase): ...@@ -35,13 +44,12 @@ class TestGreenIo(TestCase):
# by closing the socket prior to using the made file # by closing the socket prior to using the made file
try: try:
conn, addr = listener.accept() conn, addr = listener.accept()
fd = conn.makefile() fd = conn.makefile(mode='wb')
conn.close() conn.close()
fd.write('hello\n') fd.write(b'hello\n')
fd.close() fd.close()
r = fd.write('a') _write_to_closed(fd, b'a')
assert r is None, r self.assertRaises(socket.error, conn.send, b'b')
self.assertRaises(socket.error, conn.send, 'b')
finally: finally:
listener.close() listener.close()
...@@ -50,23 +58,22 @@ class TestGreenIo(TestCase): ...@@ -50,23 +58,22 @@ class TestGreenIo(TestCase):
# by closing the made file and then sending a character # by closing the made file and then sending a character
try: try:
conn, addr = listener.accept() conn, addr = listener.accept()
fd = conn.makefile() fd = conn.makefile(mode='wb')
fd.write('hello') fd.write(b'hello')
fd.close() fd.close()
conn.send('\n') conn.send(b'\n')
conn.close() conn.close()
r = fd.write('a') _write_to_closed(fd, b'a')
assert r is None, r self.assertRaises(socket.error, conn.send, b'b')
self.assertRaises(socket.error, conn.send, 'b')
finally: finally:
listener.close() listener.close()
def did_it_work(server): def did_it_work(server):
client = socket.create_connection(('127.0.0.1', server.getsockname()[1])) client = socket.create_connection(('127.0.0.1', server.getsockname()[1]))
fd = client.makefile() fd = client.makefile(mode='rb')
client.close() client.close()
assert fd.readline() == 'hello\n' assert fd.readline() == b'hello\n'
assert fd.read() == '' assert fd.read() == b''
fd.close() fd.close()
server = tcp_listener(('0.0.0.0', 0)) server = tcp_listener(('0.0.0.0', 0))
...@@ -90,11 +97,10 @@ class TestGreenIo(TestCase): ...@@ -90,11 +97,10 @@ class TestGreenIo(TestCase):
# closing the file object should close everything # closing the file object should close everything
try: try:
conn, addr = listener.accept() conn, addr = listener.accept()
conn = conn.makefile() conn = conn.makefile(mode='wb')
conn.write('hello\n') conn.write(b'hello\n')
conn.close() conn.close()
r = conn.write('a') _write_to_closed(conn, b'a')
assert r is None, r
finally: finally:
listener.close() listener.close()
......
...@@ -85,7 +85,6 @@ test__refcount.py ...@@ -85,7 +85,6 @@ test__refcount.py
test__all__.py test__all__.py
test__pywsgi.py test__pywsgi.py
test__makefile_ref.py test__makefile_ref.py
FLAKY test__greenio.py
FLAKY test__socket_dns.py FLAKY test__socket_dns.py
'''.strip().split('\n') '''.strip().split('\n')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment