Commit 3bf45acc authored by Jérémy Bobbio's avatar Jérémy Bobbio

Add support for sqlite3 database

parent b4aea6a4
......@@ -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,
......
# -*- coding: utf-8 -*-
#
# debbindiff: highlight differences between two builds of Debian packages
#
# Copyright © 2015 Jérémy Bobbio <lunar@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)]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# debbindiff: highlight differences between two builds of Debian packages
#
# Copyright © 2015 Jérémy Bobbio <lunar@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')
@pytest.fixture
def sqlite3db1():
return specialize(FilesystemFile(TEST_FILE1_PATH))
@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
@pytest.fixture
def differences(sqlite3db1, sqlite3db2):
return sqlite3db1.compare(sqlite3db2).details
@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
@@ -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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment