build: Move testing utilities to tests/helpers.py

This commit is contained in:
2023-10-30 13:36:22 +01:00
parent 5ad13cea75
commit 53994b77a7
4 changed files with 49 additions and 27 deletions

View File

@@ -20,36 +20,11 @@
import struct
from io import BytesIO
NONCE_SIZE = 24
MAX_NONCE = 8 * NONCE_SIZE
class AsyncBuffer(BytesIO):
"""Just a BytesIO with an async read method."""
async def read(self, n=None):
v = super(AsyncBuffer, self).read(n)
return v
readexactly = read
def append(self, data):
"""Append data to the buffer without changing the current position."""
pos = self.tell()
self.write(data)
self.seek(pos)
async def async_comprehend(generator):
"""Emulate ``[elem async for elem in generator]``."""
results = []
async for msg in generator:
results.append(msg)
return results
def inc_nonce(nonce):
num = bytes_to_long(nonce) + 1
if num > 2**MAX_NONCE: