From 70166cb1daeeb6453731de1c28c29fc5de5eeee0 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Wed, 22 Jun 2022 22:57:06 +0200 Subject: [PATCH 1/3] DEV: Adjust string formatting to be able to use mutmut Relates to https://github.com/davidhalter/parso/issues/207 --- PyPDF2/generic.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PyPDF2/generic.py b/PyPDF2/generic.py index 719b6948c..3b2a7c8d4 100644 --- a/PyPDF2/generic.py +++ b/PyPDF2/generic.py @@ -565,7 +565,11 @@ def write_to_stream( stream.write(b"(") for c in bytearr: if not chr(c).isalnum() and c != b" ": - stream.write(b_(rf"\{c:0>3o}")) + # This: + # stream.write(b_(rf"\{c:0>3o}")) + # gives + # https://github.com/davidhalter/parso/issues/207 + stream.write(b_("\\%03o" % c)) else: stream.write(b_(chr(c))) stream.write(b")") From cb05d724f7e02a945494bf03851cc8b8ec4ba519 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Thu, 23 Jun 2022 08:29:27 +0200 Subject: [PATCH 2/3] Add mypy to mutation test check; check if producer is set --- mutmut-test.sh | 1 + tests/test_writer.py | 1 + 2 files changed, 2 insertions(+) diff --git a/mutmut-test.sh b/mutmut-test.sh index 2284ed765..39dfb2272 100755 --- a/mutmut-test.sh +++ b/mutmut-test.sh @@ -1,2 +1,3 @@ #!/bin/bash -e pytest -x +mypy PyPDF2 --show-error-codes --disallow-untyped-defs --disallow-incomplete-defs --ignore-missing-imports diff --git a/tests/test_writer.py b/tests/test_writer.py index 332e3dbff..a412e352f 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -291,6 +291,7 @@ def test_encrypt(use_128bit): reader = PdfReader(tmp_filename, password="userpwd") new_text = reader.pages[0].extract_text() + assert reader.metadata.get("/Producer") == "PyPDF2" assert new_text == orig_text From e1fbc538984521863a965f0b9a0c144a8fca1c1a Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Thu, 23 Jun 2022 08:29:52 +0200 Subject: [PATCH 3/3] Make makefile more consistent --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 29e6f5f3e..caa6c463d 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ testtype: mutation-test: mutmut run -mutmut-results: +mutation-results: mutmut junitxml --suspicious-policy=ignore --untested-policy=ignore > mutmut-results.xml junit2html mutmut-results.xml mutmut-results.html