forked from py-pdf/pypdf
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST : move test before others to prevent errors
detected in py-pdf#2228
- Loading branch information
Showing
2 changed files
with
48 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Test the pypdf.filters module.""" | ||
import string | ||
import sys | ||
from io import BytesIO | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from pypdf import PdfReader | ||
|
||
from . import get_data_from_url | ||
|
||
filter_inputs = ( | ||
# "", '', """""", | ||
string.ascii_lowercase, | ||
string.ascii_uppercase, | ||
string.ascii_letters, | ||
string.digits, | ||
string.hexdigits, | ||
string.punctuation, | ||
string.whitespace, # Add more... | ||
) | ||
|
||
TESTS_ROOT = Path(__file__).parent.resolve() | ||
PROJECT_ROOT = TESTS_ROOT.parent | ||
RESOURCE_ROOT = PROJECT_ROOT / "resources" | ||
|
||
# Tests to be run before others | ||
|
||
|
||
# issues if images is used before due to some initialisations | ||
@pytest.mark.enable_socket() | ||
def test_image_without_pillow(): | ||
with patch.dict(sys.modules): | ||
sys.modules["PIL"] = None | ||
url = "https://corpora.tika.apache.org/base/docs/govdocs1/914/914102.pdf" | ||
name = "tika-914102.pdf" | ||
data = BytesIO(get_data_from_url(url, name=name)) | ||
reader = PdfReader(data, strict=True) | ||
|
||
for page in reader.pages: | ||
with pytest.raises(ImportError) as exc: | ||
page.images[0] | ||
assert exc.value.args[0] == ( | ||
"pillow is required to do image extraction. " | ||
"It can be installed via 'pip install pypdf[image]'" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters