From 7d820f043ad56e0cc9dabb3921f1d64416777452 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Thu, 23 Jun 2022 20:27:15 +0200 Subject: [PATCH] DEV: Adjust string formatting to be able to use mutmut (#1020) Relates to https://github.com/davidhalter/parso/issues/207 Additionally, make Makefile more consistent --- Makefile | 2 +- PyPDF2/generic.py | 6 +++++- mutmut-test.sh | 1 + tests/test_writer.py | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) 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 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")") 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