[Reproducible-commits] [debbindiff] 03/04: Add support for sqlite3 database
Jérémy Bobbio
lunar at moszumanska.debian.org
Fri Jul 31 05:44:50 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository debbindiff.
commit 3bf45acc76866a53c8676218108c872e825a57c7
Author: Jérémy Bobbio <lunar at debian.org>
Date: Fri Jul 31 03:40:05 2015 +0000
Add support for sqlite3 database
---
debbindiff/comparators/__init__.py | 2 ++
debbindiff/comparators/sqlite.py | 40 +++++++++++++++++++++++++++
tests/comparators/test_sqlite.py | 54 +++++++++++++++++++++++++++++++++++++
tests/data/sqlite3_expected_diff | 7 +++++
tests/data/test1.sqlite3 | Bin 0 -> 2048 bytes
tests/data/test2.sqlite3 | Bin 0 -> 2048 bytes
6 files changed, 103 insertions(+)
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index f737ffb..b1634ad 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -49,6 +49,7 @@ except ImportError as ex:
if ex.message != 'No module named rpm':
raise
from debbindiff.comparators.rpm_fallback import RpmFile
+from debbindiff.comparators.sqlite import Sqlite3Database
from debbindiff.comparators.squashfs import SquashfsFile
from debbindiff.comparators.symlink import Symlink
from debbindiff.comparators.text import TextFile
@@ -90,6 +91,7 @@ FILE_CLASSES = (
DebFile,
ElfFile,
StaticLibFile,
+ Sqlite3Database,
TtfFile,
MoFile,
IpkFile,
diff --git a/debbindiff/comparators/sqlite.py b/debbindiff/comparators/sqlite.py
new file mode 100644
index 0000000..0925690
--- /dev/null
+++ b/debbindiff/comparators/sqlite.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
+#
+# debbindiff 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.
+#
+# debbindiff 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 debbindiff. If not, see <http://www.gnu.org/licenses/>.
+
+from debbindiff import tool_required
+from debbindiff.comparators.binary import File, needs_content
+from debbindiff.comparators.utils import Command
+from debbindiff.difference import Difference
+
+
+class Sqlite3Dump(Command):
+ @tool_required('sqlite3')
+ def cmdline(self):
+ return ['sqlite3', self.path, '.dump']
+
+
+class Sqlite3Database(File):
+ @staticmethod
+ def recognizes(file):
+ return file.magic_file_type == 'SQLite 3.x database'
+
+ @needs_content
+ def compare_details(self, other, source=None):
+ return [Difference.from_command(Sqlite3Dump, self.path, other.path)]
+
diff --git a/tests/comparators/test_sqlite.py b/tests/comparators/test_sqlite.py
new file mode 100644
index 0000000..1bf0969
--- /dev/null
+++ b/tests/comparators/test_sqlite.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# debbindiff: highlight differences between two builds of Debian packages
+#
+# Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
+#
+# debbindiff 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.
+#
+# debbindiff 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 debbindiff. If not, see <http://www.gnu.org/licenses/>.
+
+import os.path
+import shutil
+import pytest
+from debbindiff.comparators import specialize
+from debbindiff.comparators.binary import FilesystemFile
+from debbindiff.comparators.sqlite import Sqlite3Database
+from conftest import tool_missing
+
+TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.sqlite3')
+TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.sqlite3')
+
+ at pytest.fixture
+def sqlite3db1():
+ return specialize(FilesystemFile(TEST_FILE1_PATH))
+
+ at pytest.fixture
+def sqlite3db2():
+ return specialize(FilesystemFile(TEST_FILE2_PATH))
+
+def test_identification(sqlite3db1):
+ assert isinstance(sqlite3db1, Sqlite3Database)
+
+def test_no_differences(sqlite3db1):
+ difference = sqlite3db1.compare(sqlite3db1)
+ assert difference is None
+
+ at pytest.fixture
+def differences(sqlite3db1, sqlite3db2):
+ return sqlite3db1.compare(sqlite3db2).details
+
+ at pytest.mark.skipif(tool_missing('sqlite3'), reason='missing sqlite3')
+def test_diff(differences):
+ expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/sqlite3_expected_diff')).read()
+ assert differences[0].unified_diff == expected_diff
diff --git a/tests/data/sqlite3_expected_diff b/tests/data/sqlite3_expected_diff
new file mode 100644
index 0000000..08cb8fc
--- /dev/null
+++ b/tests/data/sqlite3_expected_diff
@@ -0,0 +1,7 @@
+@@ -1,5 +1,5 @@
+ PRAGMA foreign_keys=OFF;
+ BEGIN TRANSACTION;
+ CREATE TABLE test (value val);
+-INSERT INTO "test" VALUES(1);
++INSERT INTO "test" VALUES(2);
+ COMMIT;
diff --git a/tests/data/test1.sqlite3 b/tests/data/test1.sqlite3
new file mode 100644
index 0000000..2f32bb4
Binary files /dev/null and b/tests/data/test1.sqlite3 differ
diff --git a/tests/data/test2.sqlite3 b/tests/data/test2.sqlite3
new file mode 100644
index 0000000..4c6ba26
Binary files /dev/null and b/tests/data/test2.sqlite3 differ
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git
More information about the Reproducible-commits
mailing list