aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_json_diff.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2013-08-30 01:16:50 +0200
committerMatěj Cepl <mcepl@redhat.com>2013-08-30 01:16:50 +0200
commit8447cc37a67fa1c08b7a3628de493722f3a2002e (patch)
treeedd5bf3a3a6ac4160b9160fe67cde3349a5d1f16 /test/test_json_diff.py
parent49ca6f39869d404f13f2ee82c7b9bc30dfd20879 (diff)
downloadjson_diff-8447cc37a67fa1c08b7a3628de493722f3a2002e.tar.gz
New bug with a failing test
Diffstat (limited to 'test/test_json_diff.py')
-rw-r--r--test/test_json_diff.py111
1 files changed, 62 insertions, 49 deletions
diff --git a/test/test_json_diff.py b/test/test_json_diff.py
index cbcc056..e567651 100644
--- a/test/test_json_diff.py
+++ b/test/test_json_diff.py
@@ -43,14 +43,14 @@ class OurTestCase(unittest.TestCase):
def _run_test_strings(self, olds, news, diffs, msg="", opts=None):
self._run_test(StringIO(olds), StringIO(news), StringIO(diffs),
- msg, opts)
+ msg, opts)
def _run_test_formatted(self, oldf, newf, difff, msg="", opts=None):
diffator = json_diff.Comparator(oldf, newf, opts)
- diff = ("\n".join([line.strip() \
- for line in unicode(\
- json_diff.HTMLFormatter(diffator.compare_dicts())).\
- split("\n")])).strip()
+ diff = ("\n".join([line.strip()
+ for line in unicode(
+ json_diff.HTMLFormatter(diffator.compare_dicts())).
+ split("\n")])).strip()
expected = ("\n".join([line.strip() for line in difff if line])).\
strip()
self.assertEqual(diff, expected, msg +
@@ -63,104 +63,117 @@ class TestBasicJSON(OurTestCase):
diffator = json_diff.Comparator({}, {})
diff = diffator.compare_dicts()
self.assertEqual(json.dumps(diff).strip(), "{}",
- "Empty objects diff.\n\nexpected = %s\n\nobserved = %s" %
- ({}, diff))
+ "Empty objs diff.\n\nexpected = %s\n\nobserved = %s" %
+ ({}, diff))
def test_null(self):
self._run_test_strings('{"a": null}', '{"a": null}',
- '{}', "Nulls")
+ '{}', "Nulls")
def test_null_to_string(self):
self._run_test_strings('{"a": null}', '{"a": "something"}',
- '{"_update": {"a": "something"}}', "Null changed to string")
+ '{"_update": {"a": "something"}}',
+ "Null changed to string")
def test_boolean(self):
self._run_test_strings('{"a": true}', '{"a": false}',
- '{"_update": {"a": false}}', "Booleans")
+ '{"_update": {"a": false}}', "Booleans")
def test_integer(self):
self._run_test_strings(u'{"a": 1}', '{"a": 2}',
- u'{"_update": {"a": 2}}', "Integers")
+ u'{"_update": {"a": 2}}', "Integers")
def test_float(self):
self._run_test_strings(u'{"a": 1.0}', '{"a": 1.1}',
- u'{"_update": {"a": 1.1}}', "Floats")
+ u'{"_update": {"a": 1.1}}', "Floats")
def test_int_to_float(self):
self._run_test_strings(u'{"a": 1}', '{"a": 1.0}',
- u'{"_update": {"a": 1.0}}', "Integer changed to float")
+ u'{"_update": {"a": 1.0}}',
+ "Integer changed to float")
def test_simple(self):
self._run_test_strings(SIMPLE_OLD, SIMPLE_NEW, SIMPLE_DIFF,
- "All-scalar objects diff.")
+ "All-scalar objects diff.")
def test_simple_formatted(self):
self._run_test_formatted(StringIO(SIMPLE_OLD), StringIO(SIMPLE_NEW),
- StringIO(SIMPLE_DIFF_HTML),
- "All-scalar objects diff (formatted).")
+ StringIO(SIMPLE_DIFF_HTML),
+ "All-scalar objects diff (formatted).")
def test_simple_array(self):
self._run_test_strings(SIMPLE_ARRAY_OLD, SIMPLE_ARRAY_NEW,
- SIMPLE_ARRAY_DIFF, "Simple array objects diff.")
+ SIMPLE_ARRAY_DIFF, "Simple array objects diff.")
def test_another_array(self):
self._run_test_strings(ARRAY_OLD, ARRAY_NEW,
- ARRAY_DIFF, "Array objects diff.")
+ ARRAY_DIFF, "Array objects diff.")
class TestHappyPath(OurTestCase):
def test_realFile(self):
self._run_test(open("test/old.json"), open("test/new.json"),
- open("test/diff.json"), "Simply nested objects (from file) diff.")
+ open("test/diff.json"),
+ "Simply nested objects (from file) diff.")
def test_nested(self):
self._run_test_strings(NESTED_OLD, NESTED_NEW, NESTED_DIFF,
- "Nested objects diff.")
+ "Nested objects diff.")
def test_nested_formatted(self):
self._run_test_formatted(open("test/old.json"), open("test/new.json"),
- codecs.open("test/nested_html_output.html", "r", "utf-8"),
- "Simply nested objects (from file) diff formatted as HTML.")
+ codecs.open("test/nested_html_output.html",
+ "r", "utf-8"),
+ "Simply nested objects (from file) " +
+ "diff formatted as HTML.")
def test_nested_excluded(self):
self._run_test_strings(NESTED_OLD, NESTED_NEW, NESTED_DIFF_EXCL,
- "Nested objects diff with exclusion.",
- OptionsClass(exc=["nome"]))
+ "Nested objects diff with exclusion.",
+ OptionsClass(exc=["nome"]))
def test_nested_included(self):
self._run_test_strings(NESTED_OLD, NESTED_NEW, NESTED_DIFF_INCL,
- "Nested objects diff.", OptionsClass(inc=["nome"]))
+ "Nested objects diff.",
+ OptionsClass(inc=["nome"]))
def test_nested_ignoring_append(self):
self._run_test_strings(NESTED_OLD, NESTED_NEW, NESTED_DIFF_IGNORING,
- "Nested objects diff.", OptionsClass(ign=True))
+ "Nested objects diff.",
+ OptionsClass(ign=True))
+
+ # bug /6cf
+ def test_large_recursive_file(self):
+ self._run_test(open("test/DMS_1121_1.json.1.out"),
+ open("test/DMS_1121_1.json.2.out"),
+ open("test/diff.json"),
+ "Simply nested objects (from file) diff.")
class TestBadPath(OurTestCase):
def test_no_JSON(self):
self.assertRaises(json_diff.BadJSONError,
- json_diff.Comparator, StringIO(NO_JSON_OLD),
- StringIO(NO_JSON_NEW)
- )
+ json_diff.Comparator, StringIO(NO_JSON_OLD),
+ StringIO(NO_JSON_NEW))
def test_bad_JSON_no_hex(self):
self.assertRaises(json_diff.BadJSONError, self._run_test_strings,
- u'{"a": 0x1}', '{"a": 2}', u'{"_update": {"a": 2}}',
- "Hex numbers not supported")
+ u'{"a": 0x1}', '{"a": 2}', u'{"_update": {"a": 2}}',
+ "Hex numbers not supported")
def test_bad_JSON_no_octal(self):
self.assertRaises(json_diff.BadJSONError, self._run_test_strings,
- u'{"a": 01}', '{"a": 2}', u'{"_update": {"a": 2}}',
- "Octal numbers not supported")
+ u'{"a": 01}', '{"a": 2}', u'{"_update": {"a": 2}}',
+ "Octal numbers not supported")
class TestPiglitData(OurTestCase):
def test_piglit_result_only(self):
self._run_test(open("test/old-testing-data.json"),
- open("test/new-testing-data.json"),
- open("test/diff-result-only-testing-data.json"),
- "Large piglit reports diff (just resume field).",
- OptionsClass(inc=["result"]))
+ open("test/new-testing-data.json"),
+ open("test/diff-result-only-testing-data.json"),
+ "Large piglit reports diff (just resume field).",
+ OptionsClass(inc=["result"]))
# def test_piglit_results(self):
# self._run_test(open("test/old-testing-data.json"),
@@ -182,9 +195,9 @@ class TestMainArgsMgmt(unittest.TestCase):
observed = save_stdout.read().lower()
self.assertEquals(observed[:len(expected)], expected,
- "testing -h usage message" +
- "\n\nexpected = %s\n\nobserved = %s" %
- (expected, observed))
+ "testing -h usage message" +
+ "\n\nexpected = %s\n\nobserved = %s" %
+ (expected, observed))
def test_args_run_same(self):
save_stdout = StringIO()
@@ -193,13 +206,13 @@ class TestMainArgsMgmt(unittest.TestCase):
locale.setlocale(locale.LC_ALL, "cs_CZ.utf8")
res = json_diff.main(["./test_json_diff.py",
- "test/old.json", "test/old.json"])
+ "test/old.json", "test/old.json"])
sys.stdout = sys.__stdout__
locale.setlocale(locale.LC_ALL, cur_loc)
self.assertEquals(res, 0, "comparing same file" +
- "\n\nexpected = %d\n\nobserved = %d" %
- (0, res))
+ "\n\nexpected = %d\n\nobserved = %d" %
+ (0, res))
def test_args_run_different(self):
save_stdout = StringIO()
@@ -208,7 +221,7 @@ class TestMainArgsMgmt(unittest.TestCase):
locale.setlocale(locale.LC_ALL, "cs_CZ.utf8")
res = json_diff.main(["./test_json_diff.py",
- "test/old.json", "test/new.json"])
+ "test/old.json", "test/new.json"])
sys.stdout = sys.__stdout__
locale.setlocale(locale.LC_ALL, cur_loc)
@@ -221,9 +234,9 @@ class TestMainArgsMgmt(unittest.TestCase):
cur_loc = locale.getlocale()
locale.setlocale(locale.LC_ALL, "cs_CZ.utf8")
- res = json_diff.main(["./test_json_diff.py",
- "-o", save_stdout.name,
- "test/old.json", "test/new.json"])
+ json_diff.main(["./test_json_diff.py",
+ "-o", save_stdout.name,
+ "test/old.json", "test/new.json"])
expected_file = open("test/diff.json")
expected = expected_file.read()
@@ -234,8 +247,8 @@ class TestMainArgsMgmt(unittest.TestCase):
locale.setlocale(locale.LC_ALL, cur_loc)
self.assertEqual(expected, observed, "non-stdout output file" +
- "\n\nexpected = %s\n\nobserved = %s" %
- (expected, observed))
+ "\n\nexpected = %s\n\nobserved = %s" %
+ (expected, observed))
add_tests_from_class = unittest.TestLoader().loadTestsFromTestCase