From 432229e9abaa1a6acb7bbd35d6457ead7335716f Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Mon, 10 Apr 2023 10:47:19 +0200 Subject: [PATCH] TST: Deprecation error for arguments of PdfWriter.encrypt (#1780) --- pyproject.toml | 3 +++ tests/test_writer.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 933917f9d..f0aa3b3f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,6 +85,9 @@ exclude_lines = [ "@overload", "deprecated", + # Don't complain about type-checking code not being hit by unit tests + "if TYPE_CHECKING", + # Don't complain about missing debug-only code: "def __repr__", "def __str__", diff --git a/tests/test_writer.py b/tests/test_writer.py index 5066eecb6..b0e38b2ab 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -479,7 +479,22 @@ def test_encrypt(use_128bit, user_password, owner_password, pdf_file_path): orig_text = page.extract_text() writer.add_page(page) + with pytest.warns(UserWarning, match="pypdf only implements RC4 encryption"): + with pytest.raises(ValueError, match="owner_pwd of encrypt is deprecated."): + writer.encrypt( + owner_pwd=user_password, + owner_password=owner_password, + user_password=user_password, + use_128bit=use_128bit, + ) + with pytest.raises(ValueError, match="'user_pwd' argument is deprecated"): + writer.encrypt( + owner_password=owner_password, + user_password=user_password, + user_pwd=user_password, + use_128bit=use_128bit, + ) writer.encrypt( user_password=user_password, owner_password=owner_password,