Commit 0547aa5f authored by Chris Lamb's avatar Chris Lamb 💬

Add tests for JSON comparator.

parent d72c1f48
# -*- coding: utf-8 -*-
# diffoscope: in-depth comparison of files, archives, and directories
# Copyright © 2016 Chris Lamb <>
# 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
# 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 <>.
import os
import pytest
from diffoscope.comparators import specialize
from diffoscope.comparators.json import JSONFile
from diffoscope.comparators.binary import FilesystemFile
TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.json')
TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.json')
def json1():
return specialize(FilesystemFile(TEST_FILE1_PATH))
def json2():
return specialize(FilesystemFile(TEST_FILE2_PATH))
def test_identification(json1):
assert isinstance(json1, JSONFile)
def test_no_differences(json1):
assert is None
def differences(json1, json2):
def test_diff(differences):
with open(os.path.join(os.path.dirname(__file__), '../data/json_expected_diff')) as f:
expected_diff =
assert differences[0].unified_diff == expected_diff
@@ -1,3 +1,3 @@
- "filename": "test1"
+ "filename": "test2"
{"filename": "test1"}
{"filename": "test2"}
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