Skip to content

Instantly share code, notes, and snippets.

@satyamz
Created August 21, 2016 17:06
Show Gist options
  • Save satyamz/c561f9d1ceafefce608a2c282a22f51d to your computer and use it in GitHub Desktop.
Save satyamz/c561f9d1ceafefce608a2c282a22f51d to your computer and use it in GitHub Desktop.
From d74f65cd06492ee5edca2f38e1ee1ad52ca33ddd Mon Sep 17 00:00:00 2001
From: Satyam Zode <[email protected]>
Date: Sun, 21 Aug 2016 22:34:39 +0530
Subject: [PATCH] Improve behaviour of diffoscope while comparing .changes
files
compare() method returns differences which includes `.buildinfo`
differences by default.
One would want to ignore `.buildinfo` differences if all files in
`Files` as well as all other fields of `.changes` files are same.
So now we are overriding compare() method and working on the result.
Now we have following improved behaviour of diffoscope:
- Ignore `.buildinfo` difference, if all the files in `Files` are
same and all other fields of `.changes` files are also same.
- Do not ignore `.buildinfo` difference, if any field of `.changes`
files differ.
---
diffoscope/comparators/debian.py | 10 ++++
tests/comparators/test_debian.py | 64 +++++++++++++++++++++-
...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/test3.changes | 25 +++++++++
tests/data/test4.changes | 25 +++++++++
8 files changed, 139 insertions(+), 2 deletions(-)
create mode 100644 tests/data/dot_changes_different_contents_and_identical_files_expected_diff
create mode 100644 tests/data/dot_changes_identical_contents_and_different_files_expected_diff
create mode 100644 tests/data/test3.changes
create mode 100644 tests/data/test4.changes
diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index 9c12f3d..4e5d5d6 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -147,6 +147,16 @@ 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 differences 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 86e70c2..8837aae 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -33,8 +33,12 @@ from diffoscope.presenters.text import output_text
TEST_DOT_CHANGES_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.changes')
TEST_DOT_CHANGES_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.changes')
+TEST_DOT_CHANGES_FILE3_PATH = os.path.join(os.path.dirname(__file__), '../data/test3.changes')
+TEST_DOT_CHANGES_FILE4_PATH = os.path.join(os.path.dirname(__file__), '../data/test4.changes')
TEST_DEB_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.deb')
TEST_DEB_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.deb')
+TEST_DOT_BUILDINFO_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.buildinfo')
+TEST_DOT_BUILDINFO_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.buildinfo')
@pytest.fixture
def dot_changes1(tmpdir):
@@ -42,6 +46,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
@@ -50,6 +55,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))
+
[email protected]
+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))
+
[email protected]
+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):
@@ -92,6 +116,44 @@ def test_dot_changes_compare_non_existing(monkeypatch, dot_changes1):
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
[email protected]
+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
+
[email protected]
+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
+
[email protected]
+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
+
[email protected](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(os.path.join(os.path.dirname(__file__), '../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
+
[email protected](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(os.path.join(os.path.dirname(__file__), '../data/dot_changes_description_expected_diff')).read()
+ expected_diff_files = open(os.path.join(os.path.dirname(__file__), '../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 = os.path.join(os.path.dirname(__file__), '../data/test1.dsc')
TEST_DOT_DSC_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.dsc')
TEST_DEB_SRC1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.debsrc.tar.gz')
@@ -147,8 +209,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 = os.path.join(os.path.dirname(__file__), '../data/test1.buildinfo')
-TEST_DOT_BUILDINFO_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../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/test3.changes b/tests/data/test3.changes
new file mode 100644
index 0000000..45da718
--- /dev/null
+++ b/tests/data/test3.changes
@@ -0,0 +1,25 @@
+Format: 1.8
+Date: Sat, 04 Apr 2015 18:30:48 +0200
+Source: test
+Binary: test
+Architecture: source all
+Version: 1
+Distribution: unstable
+Urgency: low
+Maintainer: Someone Else <[email protected]>
+Changed-By: Someone Else <[email protected]>
+Description:
+ test - just a test package
+Changes:
+ test (1) unstable; urgency=low
+ .
+ * 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/test4.changes b/tests/data/test4.changes
new file mode 100644
index 0000000..e3486fc
--- /dev/null
+++ b/tests/data/test4.changes
@@ -0,0 +1,25 @@
+Format: 1.8
+Date: Sat, 04 Apr 2015 18:30:48 +0200
+Source: test
+Binary: test
+Architecture: source all
+Version: 1
+Distribution: unstable
+Urgency: low
+Maintainer: Someone Else <[email protected]>
+Changed-By: Someone Else <[email protected]>
+Description:
+ 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
--
2.1.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment