[Git][reproducible-builds/diffoscope][master] 5 commits: Don't write test data during test (!).

Chris Lamb (@lamby) gitlab at salsa.debian.org
Tue Feb 7 19:59:51 UTC 2023



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
25dcd1e6 by Chris Lamb at 2023-02-07T11:48:17-08:00
Don't write test data during test (!).

Gbp-Dch: ignore

- - - - -
99eaf974 by Daniel Kahn Gillmor at 2023-02-07T11:48:17-08:00
Update from PyPDF2 to pypdf (Closes: Debian:#1029741, Debian:#1029742)

The bulk of the work here was already done by Sam James in
6aed2e5320b5d412f0f81a36dd493ae4bd7c3ff4

If the two backward compatibility aliases
PdfFile.dump_pypdf2_{metadata,annotations} are not part of an
intentionally exported API, I think they can also be removed.

Signed-off-by: Chris Lamb <lamby at debian.org>

- - - - -
ff6d9bbd by Chris Lamb at 2023-02-07T11:48:17-08:00
Update pdf_annotations_expected_diff.

- - - - -
ccf3c2a4 by Chris Lamb at 2023-02-07T11:57:40-08:00
Tidy import of PyPDF2 as pypdf.

- - - - -
82a767d2 by Chris Lamb at 2023-02-07T11:58:08-08:00
Fix compatibility with PyPDF2. (Closes: reproducible-builds/diffoscope#331)

- - - - -


5 changed files:

- debian/control
- diffoscope/comparators/pdf.py
- diffoscope/external_tools.py
- tests/comparators/test_pdf.py
- tests/data/pdf_annotations_expected_diff


Changes:

=====================================
debian/control
=====================================
@@ -74,7 +74,7 @@ Build-Depends:
  python3-magic,
  python3-pdfminer <!nocheck>,
  python3-progressbar <!nocheck>,
- python3-pypdf2 <!nocheck>,
+ python3-pypdf <!nocheck>,
  python3-pytest <!nocheck>,
  python3-pytest-cov <!nocheck>,
  python3-pyxattr <!nocheck>,


=====================================
diffoscope/comparators/pdf.py
=====================================
@@ -37,9 +37,12 @@ try:
     try:
         import pypdf
     except ImportError:
-        import PyPDF2
+        import PyPDF2 as pypdf
 
-        pypdf = PyPDF2
+    try:
+        import pypdf.PdfReader as PdfReader
+    except ImportError:
+        import pypdf.PdfFileReader as PdfReader
 
     try:
         from pypdf.errors import PdfReadError
@@ -83,8 +86,8 @@ class PdfFile(File):
             )
         else:
             difference = Difference.from_text(
-                self.dump_pypdf2_metadata(self),
-                self.dump_pypdf2_metadata(other),
+                self.dump_pypdf_metadata(self),
+                self.dump_pypdf_metadata(other),
                 self.name,
                 other.name,
             )
@@ -93,8 +96,8 @@ class PdfFile(File):
             xs.append(difference)
 
             difference = Difference.from_text(
-                self.dump_pypdf2_annotations(self),
-                self.dump_pypdf2_annotations(other),
+                self.dump_pypdf_annotations(self),
+                self.dump_pypdf_annotations(other),
                 self.name,
                 other.name,
             )
@@ -113,7 +116,7 @@ class PdfFile(File):
 
         return xs
 
-    def dump_pypdf2_metadata(self, file):
+    def dump_pypdf_metadata(self, file):
         try:
             pdf = pypdf.PdfReader(file.path)
             document_info = pdf.metadata
@@ -132,7 +135,10 @@ class PdfFile(File):
             logger.error(msg)
             return ""
 
-    def dump_pypdf2_annotations(self, file):
+    # for backward compatibility:
+    dump_pypdf2_metadata = dump_pypdf_metadata
+
+    def dump_pypdf_annotations(self, file):
         try:
             pdf = pypdf.PdfReader(file.path)
 
@@ -154,3 +160,6 @@ class PdfFile(File):
             file.add_comment(msg)
             logger.error(msg)
             return ""
+
+    # for backward compatibility:
+    dump_pypdf2_annotations = dump_pypdf_annotations


=====================================
diffoscope/external_tools.py
=====================================
@@ -183,7 +183,7 @@ EXTERNAL_TOOLS = {
         "FreeBSD": "ghostscript9-base",
         "guix": "ghostscript",
     },
-    "pypdf2": {"debian": "python3-pypdf2"},
+    "pypdf": {"debian": "python3-pypdf"},
     "radare2": {"debian": "radare2", "arch": "radare2", "guix": "radare2"},
     "readelf": {
         "debian": "binutils-multiarch",


=====================================
tests/comparators/test_pdf.py
=====================================
@@ -83,6 +83,4 @@ def differences_annotations(pdf3, pdf4):
 @skip_unless_tools_exist("pdftotext")
 @skip_unless_module_exists("pypdf")
 def test_annotations(differences_annotations):
-    with open("tests/data/pdf_annotations_expected_diff", "w") as f:
-        f.write(differences_annotations[0].unified_diff)
     assert_diff(differences_annotations[0], "pdf_annotations_expected_diff")


=====================================
tests/data/pdf_annotations_expected_diff
=====================================
@@ -1,3 +1,8 @@
-@@ -0,0 +1,2 @@
-+1: A PDF comment created in Okular
-+11: Comment created with evince
+@@ -1,3 +1,7 @@
+ This is a test PDF.
+ 
++10: Typewriter annotation
++2: Another type of
++comment
++
+ 




View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/60ea9cc6418deb7880d218beb87db4ef9628015c...82a767d27544edcffc1732be15d12bf6207381c2

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/60ea9cc6418deb7880d218beb87db4ef9628015c...82a767d27544edcffc1732be15d12bf6207381c2
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20230207/ec6acf78/attachment.htm>


More information about the rb-commits mailing list