Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: read_string_from_stream performance #1355

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from io import BytesIO
from pathlib import Path
import time
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -170,6 +171,19 @@ def test_readStringFromStream_excape_digit2():
assert read_string_from_stream(stream) == "hello \x01\x02\x03\x04"


def test_readStringFromStream_performance():
"""
This test simulates reading an embedded base64 image of 256kb.
It should be faster than a second, even on ancient machines.
Runs < 100ms on a 2019 notebook. Takes 10 seconds prior to #1350.
"""
stream = BytesIO(b"(" + b"".join([b"x"] * 1024 * 256) + b")")
start = time.time()
assert read_string_from_stream(stream)
end = time.time()
assert end - start < 2, test_readStringFromStream_performance.__doc__


def test_NameObject(caplog):
stream = BytesIO(b"x")
with pytest.raises(PdfReadError) as exc:
Expand Down