1#
2# diffoscope: in-depth comparison of files, archives, and directories
3#
4# Copyright © 2016-2017, 2020 Chris Lamb <lamby@debian.org>
5#
6# diffoscope is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# diffoscope is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
18
19import pytest
20
21from diffoscope.comparators.json import JSONFile
22
23from ..utils.data import load_fixture, get_data
24from ..utils.nonexisting import assert_non_existing
25
26
27json1 = load_fixture("test1.json")
28json2 = load_fixture("test2.json")
29json3a = load_fixture("order1a.json")
30json3b = load_fixture("order1b.json")
31invalid_json = load_fixture("test_invalid.json")
32
33
34def test_identification(json1):
35    assert isinstance(json1, JSONFile)
36
37
38def test_invalid(invalid_json):
39    assert not isinstance(invalid_json, JSONFile)
40
41
42def test_no_differences(json1):
43    assert json1.compare(json1) is None
44
45
46@pytest.fixture
47def differences(json1, json2):
48    return json1.compare(json2).details
49
50
51def test_diff(differences):
52    expected_diff = get_data("json_expected_diff")
53
54    assert differences[0].unified_diff == expected_diff
55
56
57def test_compare_non_existing(monkeypatch, json1):
58    assert_non_existing(monkeypatch, json1)
59
60
61def test_ordering_differences(json3a, json3b):
62    diff = json3a.compare(json3b)
63    assert diff.details[0]._comments == ["ordering differences only"]
64    assert diff.details[0].unified_diff == get_data("order1.diff")
65