Commit 1b121ea4 authored by Chris Lamb's avatar Chris Lamb 💬

Optionally compare JSON files using Python jsondiff module. (Closes: #888112)

parent de1abeae
......@@ -52,6 +52,7 @@ Build-Depends:
python3-distro <!nocheck>,
python3-docutils,
python3-guestfs <!nocheck>,
python3-jsondiff <!nocheck>,
python3-libarchive-c,
python3-magic,
python3-progressbar <!nocheck>,
......
......@@ -64,6 +64,7 @@ override_dh_python3:
--recommends=binwalk \
--recommends=defusedxml \
--recommends=guestfs \
--recommends=jsondiff \
--recommends=progressbar \
--recommends=python-debian \
--recommends=rpm-python \
......
......@@ -24,6 +24,11 @@ from diffoscope.difference import Difference
from .utils.file import File
try:
import jsondiff
except ImportError: # noqa
jsondiff = None
class JSONFile(File):
@classmethod
......@@ -59,6 +64,19 @@ class JSONFile(File):
)
if difference:
if jsondiff is not None:
a = getattr(self, 'parsed', {})
b = getattr(other, 'parsed', {})
diff = {repr(x): y for x, y in jsondiff.diff(a, b).items()}
difference.add_comment("Similarity: {}%".format(
jsondiff.similarity(a, b),
))
difference.add_comment("Differences: {}".format(
json.dumps(diff, indent=2, sort_keys=True),
))
return [difference]
difference = Difference.from_text(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment