[Reproducible-commits] [debbindiff] 02/02: Add tests for binary comparator

Jérémy Bobbio lunar at moszumanska.debian.org
Tue Jun 23 15:35:28 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 b9a185f2911b9eab1d560b70eaa216aac1512733
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Tue Jun 23 15:35:08 2015 +0000

    Add tests for binary comparator
---
 tests/comparators/test_binary.py        | 63 +++++++++++++++++++++++++++++++++
 tests/data/binary1                      |  1 +
 tests/data/binary2                      |  1 +
 tests/data/binary_expected_diff         |  3 ++
 tests/data/binary_hexdump_expected_diff |  3 ++
 5 files changed, 71 insertions(+)

diff --git a/tests/comparators/test_binary.py b/tests/comparators/test_binary.py
new file mode 100644
index 0000000..b188a70
--- /dev/null
+++ b/tests/comparators/test_binary.py
@@ -0,0 +1,63 @@
+#!/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
+import debbindiff.comparators.binary
+from debbindiff.comparators.binary import compare_binary_files, are_same_binaries
+from debbindiff import RequiredToolNotFound
+
+TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/binary1') 
+TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/binary2') 
+
+def test_are_same_binaries(tmpdir):
+    new_path = str(tmpdir.join('binary2'))
+    shutil.copy(TEST_FILE1_PATH, new_path)
+    assert are_same_binaries(TEST_FILE1_PATH, new_path)
+
+def test_are_not_same_binaries(tmpdir):
+    assert not are_same_binaries(TEST_FILE1_PATH, TEST_FILE2_PATH)
+
+def test_no_differences_with_xxd():
+    differences = compare_binary_files(TEST_FILE1_PATH, TEST_FILE1_PATH)
+    assert len(differences) == 0
+
+def test_compare_with_xxd():
+    differences = compare_binary_files(TEST_FILE1_PATH, TEST_FILE2_PATH)
+    assert len(differences) == 1
+    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/binary_expected_diff')).read()
+    assert differences[0].unified_diff == expected_diff
+
+ at pytest.fixture
+def xxd_not_found(monkeypatch):
+    def mock_xxd(path):
+        raise RequiredToolNotFound('xxd')
+    monkeypatch.setattr(debbindiff.comparators.binary, 'xxd', mock_xxd)
+
+def test_no_differences_without_xxd(xxd_not_found):
+    differences = compare_binary_files(TEST_FILE1_PATH, TEST_FILE1_PATH)
+    assert len(differences) == 0
+
+def test_compare_without_xxd(xxd_not_found):
+    differences = compare_binary_files(TEST_FILE1_PATH, TEST_FILE2_PATH)
+    assert len(differences) == 1
+    expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/binary_hexdump_expected_diff')).read()
+    assert differences[0].unified_diff == expected_diff
diff --git a/tests/data/binary1 b/tests/data/binary1
new file mode 100644
index 0000000..6b2e015
--- /dev/null
+++ b/tests/data/binary1
@@ -0,0 +1 @@
+�3����"����%#	
\ No newline at end of file
diff --git a/tests/data/binary2 b/tests/data/binary2
new file mode 100644
index 0000000..7f41023
--- /dev/null
+++ b/tests/data/binary2
@@ -0,0 +1 @@
+ϩA�����e���/��
\ No newline at end of file
diff --git a/tests/data/binary_expected_diff b/tests/data/binary_expected_diff
new file mode 100644
index 0000000..e7cb9c7
--- /dev/null
+++ b/tests/data/binary_expected_diff
@@ -0,0 +1,3 @@
+@@ -1 +1 @@
+-00000000: c633 e589 d7d7 ed19 228e d7d3 e325 2309  .3......"....%#.
++00000000: cfa9 41f6 baf2 e1f3 65af 9f01 cf2f f2f5  ..A.....e..../..
diff --git a/tests/data/binary_hexdump_expected_diff b/tests/data/binary_hexdump_expected_diff
new file mode 100644
index 0000000..1b828b6
--- /dev/null
+++ b/tests/data/binary_hexdump_expected_diff
@@ -0,0 +1,3 @@
+@@ -1 +1 @@
+-c633e589d7d7ed19228ed7d3e3252309
++cfa941f6baf2e1f365af9f01cf2ff2f5

-- 
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