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: Avoid catching not emitted warnings #2429

Merged
merged 2 commits into from
Feb 4, 2024
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
11 changes: 5 additions & 6 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
EmptyFileError,
FileNotDecryptedError,
PdfReadError,
PdfReadWarning,
WrongPasswordError,
)
from pypdf.generic import (
Expand Down Expand Up @@ -335,7 +334,7 @@ def test_get_images_raw(
)
pdf_stream = io.BytesIO(pdf_data)
if should_fail:
with pytest.raises(PdfReadError) as exc, pytest.warns(PdfReadWarning):
with pytest.raises(PdfReadError) as exc:
PdfReader(pdf_stream, strict=strict)
assert exc.type == PdfReadError
if startx_correction == -1:
Expand Down Expand Up @@ -530,7 +529,7 @@ def test_read_prev_0_trailer():
pdf_data.find(b"xref") - 1,
)
pdf_stream = io.BytesIO(pdf_data)
with pytest.raises(PdfReadError) as exc, pytest.warns(PdfReadWarning):
with pytest.raises(PdfReadError) as exc:
PdfReader(pdf_stream, strict=True)
assert exc.value.args[0] == "/Prev=0 in the trailer (try opening with strict=False)"

Expand Down Expand Up @@ -607,7 +606,7 @@ def test_read_unknown_zero_pages(caplog):
"Xref table not zero-indexed. ID numbers for objects will be corrected.",
]
assert normalize_warnings(caplog.text) == warnings
with pytest.raises(PdfReadError) as exc, pytest.warns(PdfReadWarning):
with pytest.raises(PdfReadError) as exc:
len(reader.pages)

assert exc.value.args[0] == "Could not find object."
Expand All @@ -617,7 +616,7 @@ def test_read_unknown_zero_pages(caplog):
"startxref on same line as offset",
]
assert normalize_warnings(caplog.text) == warnings
with pytest.raises(AttributeError) as exc, pytest.warns(PdfReadWarning):
with pytest.raises(AttributeError) as exc:
len(reader.pages)
assert exc.value.args[0] == "'NoneType' object has no attribute 'get_object'"

Expand Down Expand Up @@ -687,7 +686,7 @@ def test_issue604(caplog, strict):
outline = None
if strict:
pdf = PdfReader(f, strict=strict)
with pytest.raises(PdfReadError) as exc, pytest.warns(PdfReadWarning):
with pytest.raises(PdfReadError) as exc:
outline = pdf.outline
if "Unknown Destination" not in exc.value.args[0]:
raise Exception("Expected exception not raised")
Expand Down
Loading