def test_closed(blocksize): raw = io.BytesIO() b = BlockBuffer(raw, blocksize) b.close() assert b.closed assert raw.closed with pytest.raises(ValueError, match="I/O operation on closed file."): b.size with pytest.raises(ValueError, match="I/O operation on closed file."): b.seekable() with pytest.raises(ValueError, match="I/O operation on closed file."): b.readable() with pytest.raises(ValueError, match="I/O operation on closed file."): b.tell() with pytest.raises(ValueError, match="I/O operation on closed file."): b.seek(0) with pytest.raises(ValueError, match="I/O operation on closed file."): b.read() # closing twice works b.close()
def test_real_file(tmpdir, blocksize): path = tmpdir.join("test_real_file.bin").strpath with open(path, "wb") as fp: fp.write(b"foxbar") real_file = open(path, "rb") b = BlockBuffer(real_file, blocksize) assert not b.closed assert b.size == 6 assert b.seekable() is True assert b.readable() is True assert b.tell() == 0 assert b.seek(1) == 1 assert b.read() == b"oxbar" # final close b.close() # closing twice works b.close()