def test_read_file_bigger_than_buffer(): old_max_buf = InputFile.max_buffer_size InputFile.max_buffer_size = 10 try: input_file = InputFile(rfile, len(bstr)) assert input_file.read() == test_file.read() finally: InputFile.max_buffer_size = old_max_buf
def test_iter_file_bigger_than_buffer(): old_max_buf = InputFile.max_buffer_size InputFile.max_buffer_size = 10 try: input_file = InputFile(rfile, len(bstr)) for a, b in zip(input_file, test_file): assert a == b finally: InputFile.max_buffer_size = old_max_buf
def test_seek_file_bigger_than_buffer(): old_max_buf = InputFile.max_buffer_size InputFile.max_buffer_size = 10 try: input_file = InputFile(rfile, len(bstr)) input_file.seek(2) test_file.seek(2) assert input_file.read(1) == test_file.read(1) input_file.seek(4) test_file.seek(4) assert input_file.read(1) == test_file.read(1) finally: InputFile.max_buffer_size = old_max_buf
def setup_function(function): global rfile, input_file, test_file rfile = BytesIO(bstr) test_file = BytesIO(bstr) input_file = InputFile(rfile, len(bstr))
import sys from io import BytesIO import pytest from wptserve.request import InputFile bstr = b'This is a test document\nWith new lines\nSeveral in fact...' rfile = '' test_file = '' # This will be used to test the InputFile functions against input_file = InputFile(None, 0) def setup_function(function): global rfile, input_file, test_file rfile = BytesIO(bstr) test_file = BytesIO(bstr) input_file = InputFile(rfile, len(bstr)) def teardown_function(function): rfile.close() test_file.close() def test_seek(): input_file.seek(2) test_file.seek(2) assert input_file.read(1) == test_file.read(1) input_file.seek(4)