[diffoscope] 01/03: Add tests for comparing a device with a regular file fails (re. #850055)

Chris Lamb chris at chris-lamb.co.uk
Wed Feb 1 10:06:53 CET 2017


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

lamby pushed a commit to branch master
in repository diffoscope.

commit 37dc6ea02a84665ee3e989544df353aee11a71be
Author: Chris Lamb <lamby at debian.org>
Date:   Wed Feb 1 10:43:50 2017 +1300

    Add tests for comparing a device with a regular file fails (re. #850055)
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 tests/comparators/test_device.py        | 55 +++++++++++++++++++++++++++++++++
 tests/data/device_expected_diff         | 32 +++++++++++++++++++
 tests/data/device_expected_diff_reverse | 32 +++++++++++++++++++
 3 files changed, 119 insertions(+)

diff --git a/tests/comparators/test_device.py b/tests/comparators/test_device.py
new file mode 100644
index 0000000..cd9a798
--- /dev/null
+++ b/tests/comparators/test_device.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2017 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.binary import FilesystemFile
+from diffoscope.comparators.device import Device
+from diffoscope.comparators.utils.specialize import specialize
+
+from utils.data import load_fixture, data
+
+text_ascii1 = load_fixture('text_ascii1')
+
+ at pytest.fixture
+def devnull():
+    return specialize(FilesystemFile('/dev/null'))
+
+ at pytest.fixture
+def differences(devnull, text_ascii1):
+    return devnull.compare_bytes(text_ascii1)
+
+ at pytest.fixture
+def differences_reverse(text_ascii1, devnull):
+    return text_ascii1.compare_bytes(devnull)
+
+def test_identification(devnull):
+    assert isinstance(devnull, Device)
+
+def test_diff(differences):
+    with open(data('device_expected_diff')) as f:
+        expected_diff = f.read()
+    assert differences.unified_diff == expected_diff
+
+def test_diff_reverse(differences_reverse):
+    with open(data('device_expected_diff_reverse')) as f:
+        expected_diff = f.read()
+    with open('fixture', 'w') as f:
+        f.write(differences_reverse.unified_diff)
+    assert differences_reverse.unified_diff == expected_diff
diff --git a/tests/data/device_expected_diff b/tests/data/device_expected_diff
new file mode 100644
index 0000000..8faee99
--- /dev/null
+++ b/tests/data/device_expected_diff
@@ -0,0 +1,32 @@
+@@ -1,3 +1,28 @@
+-00000000: 6465 7669 6365 3a63 6861 7261 6374 6572  device:character
+-00000010: 0a6d 616a 6f72 3a20 310a 6d69 6e6f 723a  .major: 1.minor:
+-00000020: 2033 0a                                   3.
++00000000: 4c6f 7265 6d20 6970 7375 6d20 646f 6c6f  Lorem ipsum dolo
++00000010: 7220 7369 7420 616d 6574 2c20 636f 6e73  r sit amet, cons
++00000020: 6563 7465 7475 7220 6164 6970 6973 6369  ectetur adipisci
++00000030: 6e67 2065 6c69 742c 2073 6564 2064 6f20  ng elit, sed do 
++00000040: 6569 7573 6d6f 6420 7465 6d70 6f72 0a69  eiusmod tempor.i
++00000050: 6e63 6964 6964 756e 7420 7574 206c 6162  ncididunt ut lab
++00000060: 6f72 6520 6574 2064 6f6c 6f72 6520 6d61  ore et dolore ma
++00000070: 676e 6120 616c 6971 7561 2e20 5574 2065  gna aliqua. Ut e
++00000080: 6e69 6d20 6164 206d 696e 696d 2076 656e  nim ad minim ven
++00000090: 6961 6d2c 2071 7569 730a 6e6f 7374 7275  iam, quis.nostru
++000000a0: 6420 6578 6572 6369 7461 7469 6f6e 2075  d exercitation u
++000000b0: 6c6c 616d 636f 206c 6162 6f72 6973 206e  llamco laboris n
++000000c0: 6973 6920 7574 2061 6c69 7175 6970 2065  isi ut aliquip e
++000000d0: 7820 6561 2063 6f6d 6d6f 646f 2063 6f6e  x ea commodo con
++000000e0: 7365 7175 6174 2e0a 4475 6973 2061 7574  sequat..Duis aut
++000000f0: 6520 6972 7572 6520 646f 6c6f 7220 696e  e irure dolor in
++00000100: 2072 6570 7265 6865 6e64 6572 6974 2069   reprehenderit i
++00000110: 6e20 766f 6c75 7074 6174 6520 7665 6c69  n voluptate veli
++00000120: 7420 6573 7365 2063 696c 6c75 6d20 646f  t esse cillum do
++00000130: 6c6f 7265 2065 750a 6675 6769 6174 206e  lore eu.fugiat n
++00000140: 756c 6c61 2070 6172 6961 7475 722e 2045  ulla pariatur. E
++00000150: 7863 6570 7465 7572 2073 696e 7420 6f63  xcepteur sint oc
++00000160: 6361 6563 6174 2063 7570 6964 6174 6174  caecat cupidatat
++00000170: 206e 6f6e 2070 726f 6964 656e 742c 2073   non proident, s
++00000180: 756e 7420 696e 0a63 756c 7061 2071 7569  unt in.culpa qui
++00000190: 206f 6666 6963 6961 2064 6573 6572 756e   officia deserun
++000001a0: 7420 6d6f 6c6c 6974 2061 6e69 6d20 6964  t mollit anim id
++000001b0: 2065 7374 206c 6162 6f72 756d 2e0a        est laborum..
diff --git a/tests/data/device_expected_diff_reverse b/tests/data/device_expected_diff_reverse
new file mode 100644
index 0000000..57357d9
--- /dev/null
+++ b/tests/data/device_expected_diff_reverse
@@ -0,0 +1,32 @@
+@@ -1,28 +1,3 @@
+-00000000: 4c6f 7265 6d20 6970 7375 6d20 646f 6c6f  Lorem ipsum dolo
+-00000010: 7220 7369 7420 616d 6574 2c20 636f 6e73  r sit amet, cons
+-00000020: 6563 7465 7475 7220 6164 6970 6973 6369  ectetur adipisci
+-00000030: 6e67 2065 6c69 742c 2073 6564 2064 6f20  ng elit, sed do 
+-00000040: 6569 7573 6d6f 6420 7465 6d70 6f72 0a69  eiusmod tempor.i
+-00000050: 6e63 6964 6964 756e 7420 7574 206c 6162  ncididunt ut lab
+-00000060: 6f72 6520 6574 2064 6f6c 6f72 6520 6d61  ore et dolore ma
+-00000070: 676e 6120 616c 6971 7561 2e20 5574 2065  gna aliqua. Ut e
+-00000080: 6e69 6d20 6164 206d 696e 696d 2076 656e  nim ad minim ven
+-00000090: 6961 6d2c 2071 7569 730a 6e6f 7374 7275  iam, quis.nostru
+-000000a0: 6420 6578 6572 6369 7461 7469 6f6e 2075  d exercitation u
+-000000b0: 6c6c 616d 636f 206c 6162 6f72 6973 206e  llamco laboris n
+-000000c0: 6973 6920 7574 2061 6c69 7175 6970 2065  isi ut aliquip e
+-000000d0: 7820 6561 2063 6f6d 6d6f 646f 2063 6f6e  x ea commodo con
+-000000e0: 7365 7175 6174 2e0a 4475 6973 2061 7574  sequat..Duis aut
+-000000f0: 6520 6972 7572 6520 646f 6c6f 7220 696e  e irure dolor in
+-00000100: 2072 6570 7265 6865 6e64 6572 6974 2069   reprehenderit i
+-00000110: 6e20 766f 6c75 7074 6174 6520 7665 6c69  n voluptate veli
+-00000120: 7420 6573 7365 2063 696c 6c75 6d20 646f  t esse cillum do
+-00000130: 6c6f 7265 2065 750a 6675 6769 6174 206e  lore eu.fugiat n
+-00000140: 756c 6c61 2070 6172 6961 7475 722e 2045  ulla pariatur. E
+-00000150: 7863 6570 7465 7572 2073 696e 7420 6f63  xcepteur sint oc
+-00000160: 6361 6563 6174 2063 7570 6964 6174 6174  caecat cupidatat
+-00000170: 206e 6f6e 2070 726f 6964 656e 742c 2073   non proident, s
+-00000180: 756e 7420 696e 0a63 756c 7061 2071 7569  unt in.culpa qui
+-00000190: 206f 6666 6963 6961 2064 6573 6572 756e   officia deserun
+-000001a0: 7420 6d6f 6c6c 6974 2061 6e69 6d20 6964  t mollit anim id
+-000001b0: 2065 7374 206c 6162 6f72 756d 2e0a        est laborum..
++00000000: 6465 7669 6365 3a63 6861 7261 6374 6572  device:character
++00000010: 0a6d 616a 6f72 3a20 310a 6d69 6e6f 723a  .major: 1.minor:
++00000020: 2033 0a                                   3.

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


More information about the diffoscope mailing list