Skip to content

Commit

Permalink
Test read_string_from_stream-performance
Browse files Browse the repository at this point in the history
There is a saftey margin of a factor of 10 in both directions,
so the test should be fairly stable. Tests py-pdf#1350.
  • Loading branch information
mergezalot committed Sep 20, 2022
1 parent 141a765 commit 258d6c4
Showing 1 changed file with 14 additions and 0 deletions.
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 1 megabyte.
It should be faster than a second, even on ancient machines.
Runs in 200ms on a 2019 notebook. Takes 30 seconds prior to #1350.
"""
stream = BytesIO(b"(" + b"".join([b"x"]*1024*1024) + 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

0 comments on commit 258d6c4

Please sign in to comment.