Get the sizes closer to the code that depends on them.
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index dcada77..b17f1bd 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -2217,16 +2217,27 @@
+def _make_memoryview(size):
+ """
+ Create a new ``memoryview`` wrapped around a ``bytearray`` of the given
+ size.
+ """
+ return memoryview(bytearray(size))
+
+
+
class ConnectionRecvIntoTests(TestCase, _LoopbackMixin):
"""
Tests for :py:obj:`Connection.recv_into`
"""
- def _no_length_test(self, output_buffer):
+ def _no_length_test(self, factory):
"""
Assert that when the given buffer is passed to
``Connection.recv_into``, whatever bytes are available to be received
that fit into that buffer are written into that buffer.
"""
+ output_buffer = factory(5)
+
server, client = self._loopback()
server.send(b('xy'))
@@ -2239,15 +2250,17 @@
:py:obj:`Connection.recv_into` can be passed a ``bytearray`` instance
and data in the receive buffer is written to it.
"""
- self._no_length_test(bytearray(5))
+ self._no_length_test(bytearray)
- def _respects_length_test(self, output_buffer):
+ def _respects_length_test(self, factory):
"""
Assert that when the given buffer is passed to ``Connection.recv_into``
along with a value for ``nbytes`` that is less than the size of that
buffer, only ``nbytes`` bytes are written into the buffer.
"""
+ output_buffer = factory(10)
+
server, client = self._loopback()
server.send(b('abcdefghij'))
@@ -2263,16 +2276,18 @@
:py:obj:`Connection.recv_into` respects the ``nbytes`` parameter and
doesn't copy in more than that number of bytes.
"""
- self._respects_length_test(bytearray(10))
+ self._respects_length_test(bytearray)
- def _doesnt_overfill_test(self, output_buffer):
+ def _doesnt_overfill_test(self, factory):
"""
Assert that if there are more bytes available to be read from the
receive buffer than would fit into the buffer passed to
:py:obj:`Connection.recv_into`, only as many as fit are written into
it.
"""
+ output_buffer = factory(5)
+
server, client = self._loopback()
server.send(b('abcdefghij'))
@@ -2288,15 +2303,17 @@
:py:obj:`Connection.recv_into` respects the size of the array and
doesn't write more bytes into it than will fit.
"""
- self._doesnt_overfill_test(bytearray(5))
+ self._doesnt_overfill_test(bytearray)
- def _really_doesnt_overfill_test(self, output_buffer):
+ def _really_doesnt_overfill_test(self, factory):
"""
Assert that if the value given by ``nbytes`` is greater than the actual
size of the output buffer passed to :py:obj:`Connection.recv_into`, the
behavior is as if no value was given for ``nbytes`` at all.
"""
+ output_buffer = factory(5)
+
server, client = self._loopback()
server.send(b('abcdefghij'))
@@ -2313,7 +2330,7 @@
array and not the ``nbytes`` value and doesn't write more bytes into
the buffer than will fit.
"""
- self._doesnt_overfill_test(bytearray(5))
+ self._doesnt_overfill_test(bytearray)
try:
@@ -2326,7 +2343,7 @@
:py:obj:`Connection.recv_into` can be passed a ``memoryview``
instance and data in the receive buffer is written to it.
"""
- self._no_length_test(memoryview(bytearray(5)))
+ self._no_length_test(_make_memoryview)
def test_memoryview_respects_length(self):
@@ -2335,7 +2352,7 @@
:py:obj:`Connection.recv_into` respects the ``nbytes`` parameter
and doesn't copy more than that number of bytes in.
"""
- self._respects_length_test(memoryview(bytearray(10)))
+ self._respects_length_test(_make_memoryview)
def test_memoryview_doesnt_overfill(self):
@@ -2344,7 +2361,7 @@
:py:obj:`Connection.recv_into` respects the size of the array and
doesn't write more bytes into it than will fit.
"""
- self._doesnt_overfill_test(memoryview(bytearray(5)))
+ self._doesnt_overfill_test(_make_memoryview)
def test_memoryview_really_doesnt_overfill(self):
@@ -2354,7 +2371,7 @@
of the array and not the ``nbytes`` value and doesn't write more
bytes into the buffer than will fit.
"""
- self._doesnt_overfill_test(memoryview(bytearray(5)))
+ self._doesnt_overfill_test(_make_memoryview)