[diffoscope] 02/02: Add support for comparing Gnumeric spreadsheets. (Closes: #893311)
Chris Lamb
chris at chris-lamb.co.uk
Sun Mar 18 01:30:15 CET 2018
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch master
in repository diffoscope.
commit f2d71c1e5a63a94c0cf04a69ac048987f9609978
Author: Chris Lamb <lamby at debian.org>
Date: Sat Mar 17 20:29:58 2018 -0400
Add support for comparing Gnumeric spreadsheets. (Closes: #893311)
---
debian/control | 1 +
diffoscope/comparators/__init__.py | 1 +
diffoscope/comparators/gnumeric.py | 63 +++++++++++++++++++++++++++++++++++++
diffoscope/external_tools.py | 3 ++
tests/comparators/test_gnumeric.py | 54 +++++++++++++++++++++++++++++++
tests/data/gnumeric_expected_diff | 3 ++
tests/data/test1.gnumeric | Bin 0 -> 1803 bytes
tests/data/test2.gnumeric | Bin 0 -> 1803 bytes
8 files changed, 125 insertions(+)
diff --git a/debian/control b/debian/control
index 4d151ed..0a2c47f 100644
--- a/debian/control
+++ b/debian/control
@@ -30,6 +30,7 @@ Build-Depends:
ghc <!nocheck>,
ghostscript <!nocheck>,
giflib-tools <!nocheck>,
+ gnumeric <!nocheck>,
help2man,
imagemagick <!nocheck>,
jsbeautifier <!nocheck>,
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index a1f7433..6cedc21 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -58,6 +58,7 @@ class ComparatorManager(object):
('gettext.MoFile',),
('ipk.IpkFile',),
('rust.RustObjectFile',),
+ ('gnumeric.GnumericFile',),
('gzip.GzipFile',),
('haskell.HiFile',),
('icc.IccFile',),
diff --git a/diffoscope/comparators/gnumeric.py b/diffoscope/comparators/gnumeric.py
new file mode 100644
index 0000000..32d66da
--- /dev/null
+++ b/diffoscope/comparators/gnumeric.py
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2018 Chris Lamb <lamby 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 <https://www.gnu.org/licenses/>.
+
+import subprocess
+
+from diffoscope.tools import tool_required
+from diffoscope.tempfiles import get_named_temporary_file
+from diffoscope.difference import Difference
+
+from .utils.file import File
+
+from .missing_file import MissingFile
+
+
+class GnumericFile(File):
+ FILE_EXTENSION_SUFFIX = '.gnumeric'
+
+ @tool_required('ssconvert')
+ def compare_details(self, other, source=None):
+ if isinstance(other, MissingFile):
+ return [Difference(
+ None,
+ self.name,
+ other.name,
+ comment="Trying to compare two non-existing files."
+ )]
+
+ return [Difference.from_text(
+ self.dump(self),
+ self.dump(other),
+ self.name,
+ other.name,
+ source='ssconvert'
+ )]
+
+ def dump(self, file):
+ t = get_named_temporary_file()
+
+ subprocess.check_call((
+ 'ssconvert',
+ '--export-type=Gnumeric_stf:stf_assistant',
+ file.path,
+ t.name,
+ ))
+
+ with open(t.name) as f:
+ return f.read()
diff --git a/diffoscope/external_tools.py b/diffoscope/external_tools.py
index 0530255..808d0ad 100644
--- a/diffoscope/external_tools.py
+++ b/diffoscope/external_tools.py
@@ -220,6 +220,9 @@ EXTERNAL_TOOLS = {
'sng': {
'debian': 'sng',
},
+ 'ssconvert': {
+ 'debian': 'gnumeric',
+ },
'ssh-keygen': {
'debian': 'openssh-client',
'arch': 'openssh',
diff --git a/tests/comparators/test_gnumeric.py b/tests/comparators/test_gnumeric.py
new file mode 100644
index 0000000..7a95738
--- /dev/null
+++ b/tests/comparators/test_gnumeric.py
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2018 Chris Lamb <lamby 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 <https://www.gnu.org/licenses/>.
+
+import pytest
+
+from diffoscope.comparators.gnumeric import GnumericFile
+
+from ..utils.data import load_fixture, get_data
+from ..utils.tools import skip_unless_tools_exist
+from ..utils.nonexisting import assert_non_existing
+
+gnumeric1 = load_fixture('test1.gnumeric')
+gnumeric2 = load_fixture('test2.gnumeric')
+
+
+def test_identification(gnumeric1):
+ assert isinstance(gnumeric1, GnumericFile)
+
+
+def test_no_differences(gnumeric1):
+ difference = gnumeric1.compare(gnumeric1)
+ assert difference is None
+
+
+ at pytest.fixture
+def differences(gnumeric1, gnumeric2):
+ return gnumeric1.compare(gnumeric2).details
+
+
+ at skip_unless_tools_exist('ssconvert')
+def test_diff(differences):
+ expected_diff = get_data('gnumeric_expected_diff')
+ assert differences[0].unified_diff == expected_diff
+
+
+ at skip_unless_tools_exist('ssconvert')
+def test_compare_non_existing(monkeypatch, gnumeric1):
+ assert_non_existing(monkeypatch, gnumeric1, has_null_source=False)
diff --git a/tests/data/gnumeric_expected_diff b/tests/data/gnumeric_expected_diff
new file mode 100644
index 0000000..6578d19
--- /dev/null
+++ b/tests/data/gnumeric_expected_diff
@@ -0,0 +1,3 @@
+@@ -1 +1 @@
+-foo
++bar
diff --git a/tests/data/test1.gnumeric b/tests/data/test1.gnumeric
new file mode 100644
index 0000000..28b9816
Binary files /dev/null and b/tests/data/test1.gnumeric differ
diff --git a/tests/data/test2.gnumeric b/tests/data/test2.gnumeric
new file mode 100644
index 0000000..98c37ba
Binary files /dev/null and b/tests/data/test2.gnumeric differ
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list