Skip to content

Commit

Permalink
TST : move test before others to prevent errors
Browse files Browse the repository at this point in the history
detected in py-pdf#2228
  • Loading branch information
pubpub-zz committed Oct 1, 2023
1 parent 06a0f1d commit 88a4f93
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
48 changes: 48 additions & 0 deletions tests/test_00veryfirsttests.py
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]'"
)
19 changes: 0 additions & 19 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test the pypdf.filters module."""
import string
import sys
from io import BytesIO
from itertools import product as cartesian_product
from pathlib import Path
Expand Down Expand Up @@ -258,24 +257,6 @@ def test_issue_399():
reader.pages[1].extract_text()


@pytest.mark.enable_socket()
def test_image_without_imagemagic():
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]'"
)


@pytest.mark.enable_socket()
def test_issue_1737():
url = "https://github.com/py-pdf/pypdf/files/11068604/tt1.pdf"
Expand Down

0 comments on commit 88a4f93

Please sign in to comment.