[diffoscope] 01/05: Add tests for JSON comparator.

Chris Lamb chris at chris-lamb.co.uk
Sat Aug 6 21:10:01 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 0547aa5fd555f1119d8ab88dcca6c9c0e7a5701c
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Aug 6 20:06:07 2016 +0100

    Add tests for JSON comparator.
---
 tests/comparators/test_json.py | 51 ++++++++++++++++++++++++++++++++++++++++++
 tests/data/json_expected_diff  |  5 +++++
 tests/data/test1.json          |  1 +
 tests/data/test2.json          |  1 +
 4 files changed, 58 insertions(+)

diff --git a/tests/comparators/test_json.py b/tests/comparators/test_json.py
new file mode 100644
index 0000000..e12aa34
--- /dev/null
+++ b/tests/comparators/test_json.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2016 Chris Lamb <lamby at debian.org>
+#
+# 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
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# 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 <http://www.gnu.org/licenses/>.
+
+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')
+
+ at pytest.fixture
+def json1():
+    return specialize(FilesystemFile(TEST_FILE1_PATH))
+
+ at pytest.fixture
+def json2():
+    return specialize(FilesystemFile(TEST_FILE2_PATH))
+
+def test_identification(json1):
+    assert isinstance(json1, JSONFile)
+
+def test_no_differences(json1):
+    assert json1.compare(json1) is None
+
+ at pytest.fixture
+def differences(json1, json2):
+    return json1.compare(json2).details
+
+def test_diff(differences):
+    with open(os.path.join(os.path.dirname(__file__), '../data/json_expected_diff')) as f:
+        expected_diff = f.read()
+    assert differences[0].unified_diff == expected_diff
diff --git a/tests/data/json_expected_diff b/tests/data/json_expected_diff
new file mode 100644
index 0000000..ce85fe4
--- /dev/null
+++ b/tests/data/json_expected_diff
@@ -0,0 +1,5 @@
+@@ -1,3 +1,3 @@
+ {
+-    "filename": "test1"
++    "filename": "test2"
+ }
diff --git a/tests/data/test1.json b/tests/data/test1.json
new file mode 100644
index 0000000..70b725a
--- /dev/null
+++ b/tests/data/test1.json
@@ -0,0 +1 @@
+{"filename": "test1"}
diff --git a/tests/data/test2.json b/tests/data/test2.json
new file mode 100644
index 0000000..830e3c9
--- /dev/null
+++ b/tests/data/test2.json
@@ -0,0 +1 @@
+{"filename": "test2"}

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


More information about the diffoscope mailing list