[Reproducible-commits] [diffoscope] 01/01: Fix epub detection

Reiner Herrmann reiner at reiner-h.de
Tue Oct 27 12:03:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

deki-guest pushed a commit to branch master
in repository diffoscope.

commit f2463ecd0b9e258d55a61a598e325296570ba96a
Author: Reiner Herrmann <reiner at reiner-h.de>
Date:   Tue Oct 27 12:23:57 2015 +0100

    Fix epub detection
---
 diffoscope/comparators/zip.py  |   2 +-
 tests/comparators/test_epub.py |  67 +++++++++++++++++++++++++++++++++++++++++
 tests/data/epub_expected_diffs |  66 ++++++++++++++++++++++++++++++++++++++++
 tests/data/test1.epub          | Bin 0 -> 3320 bytes
 tests/data/test2.epub          | Bin 0 -> 3317 bytes
 5 files changed, 134 insertions(+), 1 deletion(-)

diff --git a/diffoscope/comparators/zip.py b/diffoscope/comparators/zip.py
index 97444bb..377329f 100644
--- a/diffoscope/comparators/zip.py
+++ b/diffoscope/comparators/zip.py
@@ -86,7 +86,7 @@ class ZipContainer(Archive):
 
 
 class ZipFile(File):
-    RE_FILE_TYPE = re.compile(r'^(Zip archive|Java archive|EPUB ebook) data\b')
+    RE_FILE_TYPE = re.compile(r'^(Zip archive|Java archive|EPUB document)\b')
 
     @staticmethod
     def recognizes(file):
diff --git a/tests/comparators/test_epub.py b/tests/comparators/test_epub.py
new file mode 100644
index 0000000..aa34e6f
--- /dev/null
+++ b/tests/comparators/test_epub.py
@@ -0,0 +1,67 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <http://www.gnu.org/licenses/>.
+
+import os.path
+import pytest
+from diffoscope.comparators import specialize
+from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
+from diffoscope.comparators.zip import ZipFile
+from diffoscope.config import Config
+from conftest import tool_missing
+
+TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.epub')
+TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.epub')
+
+ at pytest.fixture
+def epub1():
+    return specialize(FilesystemFile(TEST_FILE1_PATH))
+
+ at pytest.fixture
+def epub2():
+    return specialize(FilesystemFile(TEST_FILE2_PATH))
+
+def test_identification(epub1):
+    assert isinstance(epub1, ZipFile)
+
+def test_no_differences(epub1):
+    difference = epub1.compare(epub1)
+    assert difference is None
+
+ at pytest.fixture
+def differences(epub1, epub2):
+    return epub1.compare(epub2).details
+
+ at pytest.mark.skipif(tool_missing('zipinfo'), reason='missing zip')
+def test_differences(differences):
+    assert differences[0].source1 == 'zipinfo {}'
+    assert differences[0].source1 == 'zipinfo {}'
+    assert differences[1].source1 == 'ch001.xhtml'
+    assert differences[1].source2 == 'ch001.xhtml'
+    assert differences[2].source1 == 'content.opf'
+    assert differences[2].source2 == 'content.opf'
+    assert differences[3].source1 == 'toc.ncx'
+    assert differences[3].source2 == 'toc.ncx'
+    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/epub_expected_diffs')).read()
+    assert expected_diff == "".join(map(lambda x: x.unified_diff, differences))
+
+def test_compare_non_existing(monkeypatch, epub1):
+    monkeypatch.setattr(Config.general, 'new_file', True)
+    difference = epub1.compare(NonExistingFile('/nonexisting', epub1))
+    assert difference.source2 == '/nonexisting'
+    assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/data/epub_expected_diffs b/tests/data/epub_expected_diffs
new file mode 100644
index 0000000..775af9c
--- /dev/null
+++ b/tests/data/epub_expected_diffs
@@ -0,0 +1,66 @@
+@@ -1,11 +1,11 @@
+-Zip file size: 3320 bytes, number of entries: 9
+--rw----     0.0 fat       20 b- stor 15-Oct-27 11:32 mimetype
+--rw----     0.0 fat      246 b- defX 15-Oct-27 11:32 META-INF/container.xml
+--rw----     0.0 fat      160 b- defX 15-Oct-27 11:32 META-INF/com.apple.ibooks.display-options.xml
+--rw----     0.0 fat      439 b- defX 15-Oct-27 11:32 stylesheet.css
+--rw----     0.0 fat      529 b- defX 15-Oct-27 11:32 title_page.xhtml
+--rw----     0.0 fat     1129 b- defX 15-Oct-27 11:32 content.opf
+--rw----     0.0 fat      742 b- defX 15-Oct-27 11:32 toc.ncx
+--rw----     0.0 fat      655 b- defX 15-Oct-27 11:32 nav.xhtml
+--rw----     0.0 fat      615 b- defX 15-Oct-27 11:32 ch001.xhtml
+-9 files, 4535 bytes uncompressed, 2328 bytes compressed:  48.7%
++Zip file size: 3317 bytes, number of entries: 9
++-rw----     0.0 fat       20 b- stor 15-Oct-27 11:33 mimetype
++-rw----     0.0 fat      246 b- defX 15-Oct-27 11:33 META-INF/container.xml
++-rw----     0.0 fat      160 b- defX 15-Oct-27 11:33 META-INF/com.apple.ibooks.display-options.xml
++-rw----     0.0 fat      439 b- defX 15-Oct-27 11:33 stylesheet.css
++-rw----     0.0 fat      529 b- defX 15-Oct-27 11:33 title_page.xhtml
++-rw----     0.0 fat     1129 b- defX 15-Oct-27 11:33 content.opf
++-rw----     0.0 fat      742 b- defX 15-Oct-27 11:33 toc.ncx
++-rw----     0.0 fat      655 b- defX 15-Oct-27 11:33 nav.xhtml
++-rw----     0.0 fat      615 b- defX 15-Oct-27 11:33 ch001.xhtml
++9 files, 4535 bytes uncompressed, 2325 bytes compressed:  48.7%
+@@ -8,12 +8,12 @@
+   <title>Test Ebook</title>
+   <link rel="stylesheet" type="text/css" href="stylesheet.css" />
+ </head>
+ <body>
+ <div id="test-ebook" class="section level1 unnumbered">
+ <h1>Test Ebook</h1>
+ <p>Hello World!</p>
+-<p>Time: 12:32</p>
++<p>Time: 12:33</p>
+ </div>
+ </body>
+ </html>
+ 
+@@ -1,13 +1,13 @@
+ <?xml version="1.0" encoding="UTF-8"?>
+ <package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="epub-id-1">
+   <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
+-    <dc:identifier id="epub-id-1">urn:uuid:488fe0b5-29d9-4d64-a023-ca08947d78ae</dc:identifier>
++    <dc:identifier id="epub-id-1">urn:uuid:c3082605-195c-4273-acad-528beceba843</dc:identifier>
+     <dc:title id="epub-title-1">Test Ebook</dc:title>
+-    <dc:date id="epub-date-1">2015-10-27T11:32:54Z</dc:date>
++    <dc:date id="epub-date-1">2015-10-27T11:33:20Z</dc:date>
+     <dc:language>en-US</dc:language>
+   </metadata>
+   <manifest>
+     <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />
+     <item id="style" href="stylesheet.css" media-type="text/css" />
+     <item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" />
+     <item id="title_page_xhtml" href="title_page.xhtml" media-type="application/xhtml+xml" />
+@@ -1,11 +1,11 @@
+ <?xml version="1.0" encoding="UTF-8"?>
+ <ncx version="2005-1" xmlns="http://www.daisy.org/z3986/2005/ncx/">
+   <head>
+-    <meta name="dtb:uid" content="urn:uuid:488fe0b5-29d9-4d64-a023-ca08947d78ae" />
++    <meta name="dtb:uid" content="urn:uuid:c3082605-195c-4273-acad-528beceba843" />
+     <meta name="dtb:depth" content="1" />
+     <meta name="dtb:totalPageCount" content="0" />
+     <meta name="dtb:maxPageNumber" content="0" />
+   </head>
+   <docTitle>
+     <text>Test Ebook</text>
+   </docTitle>
diff --git a/tests/data/test1.epub b/tests/data/test1.epub
new file mode 100644
index 0000000..bc43a02
Binary files /dev/null and b/tests/data/test1.epub differ
diff --git a/tests/data/test2.epub b/tests/data/test2.epub
new file mode 100644
index 0000000..64e145e
Binary files /dev/null and b/tests/data/test2.epub differ

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git



More information about the Reproducible-commits mailing list