Skip to content

Commit

Permalink
TST: Check Error messages
Browse files Browse the repository at this point in the history
Doing so somethings shows that not the error message you've
expected is thrown, but another one of the same Exception type
  • Loading branch information
MartinThoma committed Apr 16, 2022
1 parent 1f0fbf3 commit 133f31a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Tests/test_basic_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ def test_basic_features():


def test_convertToInt():
with pytest.raises(PdfReadError):
with pytest.raises(PdfReadError) as exc:
convertToInt(256, 16)
assert exc.value.args[0] == "invalid size in convertToInt"
3 changes: 2 additions & 1 deletion Tests/test_pagerange.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def test_str_init(range_str, expected):
def test_str_init_error():
init_str = "1-2"
assert PageRange.valid(init_str) is False
with pytest.raises(ParseError):
with pytest.raises(ParseError) as exc:
PageRange(init_str)
assert exc.value.args[0] == "1-2"


@pytest.mark.parametrize(
Expand Down
3 changes: 2 additions & 1 deletion Tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ def test_get_images_raw(strict, with_prev_0, should_fail):
)
pdf_stream = io.BytesIO(pdf_data)
if should_fail:
with pytest.raises(PdfReadError):
with pytest.raises(PdfReadError) as exc:
PdfFileReader(pdf_stream, strict=strict)
assert exc.value.args[0] == "/Prev=0 in the trailer (try opening with strict=False)"
else:
PdfFileReader(pdf_stream, strict=strict)

Expand Down
4 changes: 3 additions & 1 deletion Tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import PyPDF2.utils
from PyPDF2.errors import PdfStreamError
from PyPDF2 import PdfFileReader

TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -59,8 +60,9 @@ def test_readUntilRegex_premature_ending_raise():
import re

stream = io.BytesIO(b"")
with pytest.raises(PyPDF2.utils.PdfStreamError):
with pytest.raises(PdfStreamError) as exc:
PyPDF2.utils.readUntilRegex(stream, re.compile(b"."))
assert exc.value.args[0] == "Stream has ended unexpectedly"


def test_readUntilRegex_premature_ending_name():
Expand Down
3 changes: 2 additions & 1 deletion Tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def test_writer_operations():

writer = PdfFileWriter()
page = reader.pages[0]
with pytest.raises(PageSizeNotDefinedError):
with pytest.raises(PageSizeNotDefinedError) as exc:
writer.addBlankPage()
assert exc.value.args == ()
writer.insertPage(page, 1)
writer.removeText()
writer.insertPage(reader_outline.pages[0], 0)
Expand Down

0 comments on commit 133f31a

Please sign in to comment.