Commit 240b5846 authored by Denis Bilenko's avatar Denis Bilenko

test__os.py: buffer/memoryview fix on PY3

thanks to @fantix for original patch.
parent d3a3de6d
import sys
import six
from os import pipe
from gevent import os
from greentest import TestCase, main
......@@ -26,12 +28,12 @@ class TestOS_tp(TestCase):
def write(self, *args):
return os.tp_write(*args)
def test_if_pipe_blocks(self):
def _test_if_pipe_blocks(self, buffer_class):
r, w = self.pipe()
# set nbytes such that for sure it is > maximum pipe buffer
nbytes = 1000000
block = 'x' * 4096
buf = buffer(block)
buf = buffer_class(block)
# Lack of "nonlocal" keyword in Python 2.x:
bytesread = [0]
byteswritten = [0]
......@@ -57,6 +59,16 @@ class TestOS_tp(TestCase):
assert bytesread[0] == nbytes
assert bytesread[0] == byteswritten[0]
if sys.version_info[0] < 3:
def test_if_pipe_blocks_buffer(self):
self._test_if_pipe_blocks(six.builtins.buffer)
if sys.version_info[:2] >= (2, 7):
def test_if_pipe_blocks_memoryview(self):
self._test_if_pipe_blocks(six.builtins.memoryview)
if hasattr(os, 'make_nonblocking'):
......
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