[diffoscope] 05/05: Correct behaviour of JSON comparator when file does not exist.

Chris Lamb chris at chris-lamb.co.uk
Sun Aug 21 00:51:07 CEST 2016


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

lamby pushed a commit to branch master
in repository diffoscope.

commit 58ecca1abc6524cc9cce03b869980e7d79e107f0
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Aug 20 23:45:44 2016 +0100

    Correct behaviour of JSON comparator when file does not exist.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/comparators/json.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/diffoscope/comparators/json.py b/diffoscope/comparators/json.py
index b89cdea..d16a762 100644
--- a/diffoscope/comparators/json.py
+++ b/diffoscope/comparators/json.py
@@ -41,9 +41,11 @@ class JSONFile(File):
         return True
 
     def compare_details(self, other, source=None):
-        return [Difference.from_text(
-            json.dumps(self.parsed, indent=4, sort_keys=True),
-            json.dumps(other.parsed, indent=4, sort_keys=True),
-            self.path,
-            other.path,
-        )]
+        return [Difference.from_text(self.dumps(self), self.dumps(other),
+            self.path, other.path)]
+
+    @staticmethod
+    def dumps(file):
+        if not hasattr(file, 'parsed'):
+            return ""
+        return json.dumps(file.parsed, indent=4, sort_keys=True)

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


More information about the diffoscope mailing list