[diffoscope] 01/01: Improve diffoscope behaviour for .changes

Jérémy Bobbio lunar at moszumanska.debian.org
Tue Aug 23 21:55:37 CEST 2016


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

lunar pushed a commit to branch master
in repository diffoscope.

commit c61f41c5128094508d6fff8b746cecc3841f6b27
Author: Satyam Zode <satyamzode at gmail.com>
Date:   Wed Aug 24 00:11:38 2016 +0530

    Improve diffoscope behaviour for .changes
    
    Being able to know details about the build process is useful
    when understanding why two different builds had not come up
    with the same output. It may highlight which aspects of the
    build environment were different.
    
    In the particular context of comparing .changes, we know
    that if all files listed are identical except the .buildinfo
    file, the differences in the .buildinfo files are irrelevant.
    
    We thus ignore .buildinfo differences if all the files
    except .buildinfo files referenced in `Files` field and all
    other fields of .changes are identical.
---
 diffoscope/comparators/debian.py                   | 12 +++++
 tests/comparators/test_debian.py                   | 63 +++++++++++++++++++++-
 ...rent_contents_and_identical_files_expected_diff |  5 ++
 ...ical_contents_and_different_files_expected_diff |  6 +++
 tests/data/test1.changes                           |  3 ++
 tests/data/test2.changes                           |  3 ++
 tests/data/{test1.changes => test3.changes}        |  3 ++
 tests/data/{test2.changes => test4.changes}        |  5 +-
 8 files changed, 97 insertions(+), 3 deletions(-)

diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index 70bf33e..66488ae 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -29,6 +29,7 @@ from diffoscope.changes import Changes
 from diffoscope.difference import Difference
 from diffoscope.comparators.utils import Container
 from diffoscope.comparators.binary import File
+from diffoscope import logger
 
 
 DOT_CHANGES_FIELDS = [
@@ -145,6 +146,17 @@ class DotChangesFile(DebControlFile):
         file._deb822 = changes
         return True
 
+    def compare(self, other, source=None):
+        differences = super().compare(other, source)
+        if differences is None:
+            return None
+        files_identical = all([x == y for x, y in zip(self.deb822.get('Files'), other.deb822.get('Files')) if not x['name'].endswith('.buildinfo')])
+        if files_identical and len(differences.details) == 1 and differences.details[0].source1 == 'Files':
+            logger.warning('Ignoring buildinfo file differences')
+            return None
+        else:
+            return differences
+
 
 class DotDscFile(DebControlFile):
     RE_FILE_EXTENSION = re.compile(r'\.dsc$')
diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index 2b08194..1c2a24a 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -37,6 +37,10 @@ except ImportError:
 
 TEST_DOT_CHANGES_FILE1_PATH = data('test1.changes')
 TEST_DOT_CHANGES_FILE2_PATH = data('test2.changes')
+TEST_DOT_CHANGES_FILE3_PATH = data('test3.changes')
+TEST_DOT_CHANGES_FILE4_PATH = data('test4.changes')
+TEST_DOT_BUILDINFO_FILE1_PATH = data('test1.buildinfo')
+TEST_DOT_BUILDINFO_FILE2_PATH = data('test2.buildinfo')
 TEST_DEB_FILE1_PATH = data('test1.deb')
 TEST_DEB_FILE2_PATH = data('test2.deb')
 
@@ -46,6 +50,7 @@ def dot_changes1(tmpdir):
     dot_changes_path = str(tmpdir.join('a/test_1.changes'))
     shutil.copy(TEST_DOT_CHANGES_FILE1_PATH, dot_changes_path)
     shutil.copy(TEST_DEB_FILE1_PATH, str(tmpdir.join('a/test_1_all.deb')))
+    shutil.copy(TEST_DOT_BUILDINFO_FILE1_PATH, str(tmpdir.join('a/test_1.buildinfo')))
     return specialize(FilesystemFile(dot_changes_path))
 
 @pytest.fixture
@@ -54,6 +59,25 @@ def dot_changes2(tmpdir):
     dot_changes_path = str(tmpdir.join('b/test_1.changes'))
     shutil.copy(TEST_DOT_CHANGES_FILE2_PATH, dot_changes_path)
     shutil.copy(TEST_DEB_FILE2_PATH, str(tmpdir.join('b/test_1_all.deb')))
+    shutil.copy(TEST_DOT_BUILDINFO_FILE2_PATH, str(tmpdir.join('b/test_2.buildinfo')))
+    return specialize(FilesystemFile(dot_changes_path))
+
+ at pytest.fixture
+def dot_changes3(tmpdir):
+    tmpdir.mkdir('c')
+    dot_changes_path = str(tmpdir.join('c/test_3.changes'))
+    shutil.copy(TEST_DOT_CHANGES_FILE3_PATH, dot_changes_path)
+    shutil.copy(TEST_DEB_FILE1_PATH, str(tmpdir.join('c/test_1_all.deb')))
+    shutil.copy(TEST_DOT_BUILDINFO_FILE2_PATH, str(tmpdir.join('c/test_2.buildinfo')))
+    return specialize(FilesystemFile(dot_changes_path))
+
+ at pytest.fixture
+def dot_changes4(tmpdir):
+    tmpdir.mkdir('d')
+    dot_changes_path = str(tmpdir.join('d/test_4.changes'))
+    shutil.copy(TEST_DOT_CHANGES_FILE4_PATH, dot_changes_path)
+    shutil.copy(TEST_DEB_FILE2_PATH, str(tmpdir.join('d/test_1_all.deb')))
+    shutil.copy(TEST_DOT_BUILDINFO_FILE1_PATH, str(tmpdir.join('d/test_2.buildinfo')))
     return specialize(FilesystemFile(dot_changes_path))
 
 def test_dot_changes_identification(dot_changes1):
@@ -96,6 +120,43 @@ def test_dot_changes_compare_non_existing(monkeypatch, dot_changes1):
     assert difference.source2 == '/nonexisting'
     assert difference.details[-1].source2 == '/dev/null'
 
+ at pytest.fixture
+def dot_changes_differences_identical_contents_and_identical_files(dot_changes1, dot_changes3):
+    difference = dot_changes1.compare(dot_changes3)
+    output_text(difference, print_func=print)
+    return difference.details
+
+ at pytest.fixture
+def dot_changes_differences_identical_contents_and_different_files(dot_changes1, dot_changes4):
+    difference = dot_changes1.compare(dot_changes4)
+    output_text(difference, print_func=print)
+    return difference.details
+
+ at pytest.fixture
+def dot_changes_differences_different_contents_and_identical_files(dot_changes2, dot_changes4):
+    difference = dot_changes4.compare(dot_changes2)
+    output_text(difference, print_func=print)
+    return difference.details
+
+def test_dot_changes_no_differences_exclude_buildinfo(dot_changes1, dot_changes3):
+    difference = dot_changes1.compare(dot_changes3)
+    assert difference is None
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+def test_dot_changes_identical_contents_and_different_files(dot_changes_differences_identical_contents_and_different_files):
+    assert dot_changes_differences_identical_contents_and_different_files[0]
+    expected_diff = open(data('dot_changes_identical_contents_and_different_files_expected_diff')).read()
+    assert dot_changes_differences_identical_contents_and_different_files[0].unified_diff == expected_diff
+
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
+def test_dot_changes_different_contents_and_identical_files(dot_changes_differences_different_contents_and_identical_files):
+    assert dot_changes_differences_different_contents_and_identical_files[0]
+    assert dot_changes_differences_different_contents_and_identical_files[1]
+    expected_diff_contents = open(data('dot_changes_description_expected_diff')).read()
+    expected_diff_files = open(data('dot_changes_different_contents_and_identical_files_expected_diff')).read()
+    assert dot_changes_differences_different_contents_and_identical_files[0].unified_diff == expected_diff_contents
+    assert dot_changes_differences_different_contents_and_identical_files[1].unified_diff == expected_diff_files
+
+
 TEST_DOT_DSC_FILE1_PATH = data('test1.dsc')
 TEST_DOT_DSC_FILE2_PATH = data('test2.dsc')
 TEST_DEB_SRC1_PATH = data('test1.debsrc.tar.gz')
@@ -151,8 +212,6 @@ def test_dot_dsc_compare_non_existing(monkeypatch, dot_dsc1):
     assert difference.source2 == '/nonexisting'
     assert difference.details[-1].source2 == '/dev/null'
 
-TEST_DOT_BUILDINFO_FILE1_PATH = data('test1.buildinfo')
-TEST_DOT_BUILDINFO_FILE2_PATH = data('test2.buildinfo')
 
 @pytest.fixture
 def dot_buildinfo1(tmpdir):
diff --git a/tests/data/dot_changes_different_contents_and_identical_files_expected_diff b/tests/data/dot_changes_different_contents_and_identical_files_expected_diff
new file mode 100644
index 0000000..6403c16
--- /dev/null
+++ b/tests/data/dot_changes_different_contents_and_identical_files_expected_diff
@@ -0,0 +1,5 @@
+@@ -1,3 +1,3 @@
+ 
+  d323c454462407fe3bfde31a74b23eba 2388 devel optional test_1_all.deb
+- 40756b7e8aae2c1fcbcac099670b6db8 3780 web optional test_2.buildinfo
++ 9972d7c394228311ba92cbcbfe2d6cd9 3765 web optional test_2.buildinfo
diff --git a/tests/data/dot_changes_identical_contents_and_different_files_expected_diff b/tests/data/dot_changes_identical_contents_and_different_files_expected_diff
new file mode 100644
index 0000000..c7cdf4c
--- /dev/null
+++ b/tests/data/dot_changes_identical_contents_and_different_files_expected_diff
@@ -0,0 +1,6 @@
+@@ -1,3 +1,3 @@
+ 
+- 660ad4713e5d8271df2e7e86bf246dc0 2262 devel optional test_1_all.deb
+- 40756b7e8aae2c1fcbcac099670b6db8 3780 web optional test_1.buildinfo
++ d323c454462407fe3bfde31a74b23eba 2388 devel optional test_1_all.deb
++ 40756b7e8aae2c1fcbcac099670b6db8 3780 web optional test_2.buildinfo
diff --git a/tests/data/test1.changes b/tests/data/test1.changes
index b32e971..624556e 100644
--- a/tests/data/test1.changes
+++ b/tests/data/test1.changes
@@ -16,7 +16,10 @@ Changes:
    * Test package.
 Checksums-Sha1:
  b21eeec5004853c4955d5b856a6546068c2d7dc9 2262 test_1_all.deb
+ e1cafb5f8db51f4ec477807d105b1e3cccf9a767 3780 test_1.buildinfo
 Checksums-Sha256:
  d2b2ea8b9cf8ef645a328cdb882586ee465e141fc66a2dbe1ad29b29ac1e7920 2262 test_1_all.deb
+ 167d989223978a45a69af30dcd488baa00aec2045b66d0f74d7f03b08fd22365 3780 test_1.buildinfo
 Files:
  660ad4713e5d8271df2e7e86bf246dc0 2262 devel optional test_1_all.deb
+ 40756b7e8aae2c1fcbcac099670b6db8 3780 web optional test_1.buildinfo
diff --git a/tests/data/test2.changes b/tests/data/test2.changes
index 3e33d3a..c5f9245 100644
--- a/tests/data/test2.changes
+++ b/tests/data/test2.changes
@@ -16,7 +16,10 @@ Changes:
    * Test package.
 Checksums-Sha1:
  70982664db2015334bff6441b429d7e3c58dbecb 2388 test_1_all.deb
+ 91d2cc6aadddb4a24b0c2f8f24d558ce0e07f9cd 3765 test_2.buildinfo
 Checksums-Sha256:
  2f2e45ee3a5fdacd9b30133ec728121588bf9b97af3b947b3882b2b28a0555da 2388 test_1_all.deb
+ 917d8b5c3ade2bde26fe2b7476481537f32a0c07f10e5e44c0ca7a02c8bfa9d8 3765 test_2.buildinfo
 Files:
  d323c454462407fe3bfde31a74b23eba 2388 devel optional test_1_all.deb
+ 9972d7c394228311ba92cbcbfe2d6cd9 3765 web optional test_2.buildinfo
diff --git a/tests/data/test1.changes b/tests/data/test3.changes
similarity index 73%
copy from tests/data/test1.changes
copy to tests/data/test3.changes
index b32e971..45da718 100644
--- a/tests/data/test1.changes
+++ b/tests/data/test3.changes
@@ -16,7 +16,10 @@ Changes:
    * Test package.
 Checksums-Sha1:
  b21eeec5004853c4955d5b856a6546068c2d7dc9 2262 test_1_all.deb
+ 91d2cc6aadddb4a24b0c2f8f24d558ce0e07f9cd 3765 test_2.buildinfo
 Checksums-Sha256:
  d2b2ea8b9cf8ef645a328cdb882586ee465e141fc66a2dbe1ad29b29ac1e7920 2262 test_1_all.deb
+ 917d8b5c3ade2bde26fe2b7476481537f32a0c07f10e5e44c0ca7a02c8bfa9d8 3765 test_2.buildinfo
 Files:
  660ad4713e5d8271df2e7e86bf246dc0 2262 devel optional test_1_all.deb
+ 9972d7c394228311ba92cbcbfe2d6cd9 3765 web optional test_2.buildinfo
diff --git a/tests/data/test2.changes b/tests/data/test4.changes
similarity index 69%
copy from tests/data/test2.changes
copy to tests/data/test4.changes
index 3e33d3a..e3486fc 100644
--- a/tests/data/test2.changes
+++ b/tests/data/test4.changes
@@ -9,14 +9,17 @@ Urgency: low
 Maintainer: Someone Else <user at example.org>
 Changed-By: Someone Else <user at example.org>
 Description:
- test - just a simple test package
+ test - just a test package
 Changes:
  test (1) unstable; urgency=low
  .
    * Test package.
 Checksums-Sha1:
  70982664db2015334bff6441b429d7e3c58dbecb 2388 test_1_all.deb
+ e1cafb5f8db51f4ec477807d105b1e3cccf9a767 3780 test_2.buildinfo
 Checksums-Sha256:
  2f2e45ee3a5fdacd9b30133ec728121588bf9b97af3b947b3882b2b28a0555da 2388 test_1_all.deb
+ 167d989223978a45a69af30dcd488baa00aec2045b66d0f74d7f03b08fd22365 3780 test_2.buildinfo
 Files:
  d323c454462407fe3bfde31a74b23eba 2388 devel optional test_1_all.deb
+ 40756b7e8aae2c1fcbcac099670b6db8 3780 web optional test_2.buildinfo

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


More information about the diffoscope mailing list