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: Use pytest.warns() for warnings, and .raises() for exceptions #1325

Merged
merged 1 commit into from Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/test_utils.py
Expand Up @@ -107,10 +107,10 @@ def test_b():


def test_deprecate_no_replacement():
with pytest.raises(PendingDeprecationWarning) as exc:
with pytest.warns(PendingDeprecationWarning) as warn:
PyPDF2._utils.deprecate_no_replacement("foo")
error_msg = "foo is deprecated and will be removed in PyPDF2 3.0.0."
assert exc.value.args[0] == error_msg
assert warn[0].message.args[0] == error_msg


@pytest.mark.parametrize(
Expand Down
54 changes: 9 additions & 45 deletions tests/test_workflows.py
Expand Up @@ -260,62 +260,26 @@ def test_extract_textbench(enable, url, pages, print_result=False):

def test_orientations():
p = PdfReader(RESOURCE_ROOT / "test Orient.pdf").pages[0]
try:
with pytest.warns(DeprecationWarning):
p.extract_text("", "")
except DeprecationWarning:
pass
else:
raise Exception("DeprecationWarning expected")
try:
with pytest.warns(DeprecationWarning):
p.extract_text("", "", 0)
except DeprecationWarning:
pass
else:
raise Exception("DeprecationWarning expected")
try:
with pytest.warns(DeprecationWarning):
p.extract_text("", "", 0, 200)
except DeprecationWarning:
pass
else:
raise Exception("DeprecationWarning expected")

try:
with pytest.warns(DeprecationWarning):
p.extract_text(Tj_sep="", TJ_sep="")
except DeprecationWarning:
pass
else:
raise Exception("DeprecationWarning expected")
assert findall("\\((.)\\)", p.extract_text()) == ["T", "B", "L", "R"]
try:
with pytest.raises(Exception):
p.extract_text(None)
except Exception:
pass
else:
raise Exception("Argument 1 check invalid")
try:
with pytest.raises(Exception):
p.extract_text("", 0)
except Exception:
pass
else:
raise Exception("Argument 2 check invalid")
try:
with pytest.raises(Exception):
p.extract_text("", "", None)
except Exception:
pass
else:
raise Exception("Argument 3 check invalid")
try:
with pytest.raises(Exception):
p.extract_text("", "", 0, "")
except Exception:
pass
else:
raise Exception("Argument 4 check invalid")
try:
with pytest.raises(Exception):
p.extract_text(0, "")
except Exception:
pass
else:
raise Exception("Argument 1 new syntax check invalid")

p.extract_text(0, 0)
p.extract_text(orientations=0)
Expand Down