diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-10-28 14:30:53 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-10-28 14:30:53 +0200 |
commit | e10506226abbca14ebe99c987feb155f1253abec (patch) | |
tree | 5efe7ff191e68045ad6ac569eb6401e8815bfd69 /test_json_diff.py | |
parent | 81f605fb4885efbfccf615848a3f5ee6a1452025 (diff) | |
download | json_diff-e10506226abbca14ebe99c987feb155f1253abec.tar.gz |
HTML formatted output possible.
Diffstat (limited to 'test_json_diff.py')
-rw-r--r-- | test_json_diff.py | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/test_json_diff.py b/test_json_diff.py index 3a514eb..21faf70 100644 --- a/test_json_diff.py +++ b/test_json_diff.py @@ -25,13 +25,13 @@ SIMPLE_NEW = u""" SIMPLE_DIFF = u""" { - "append": { + "_append": { "d": "přidáno" }, - "remove": { + "_remove": { "a": 1 }, - "update": { + "_update": { "c": "Maruška", "b": false } @@ -60,63 +60,89 @@ NESTED_NEW = u""" NESTED_DIFF = u""" { - "append": { + "_append": { "c": 3, "daughter": { "name": "Maruška" } }, - "remove": { + "_remove": { "b": 2, "son": { "name": "Janošek" } }, - "update": { + "_update": { "a": 2 } } """ -class TestXorgAnalyze(unittest.TestCase): +class TestHappyPath(unittest.TestCase): def test_empty(self): diffator = json_diff.Comparator({}, {}) diff = diffator.compare_dicts() - self.assertEqual(json.dumps(diff).strip(), "{}", \ - "Empty objects diff.\n\nexpected = %s\n\nobserved = %s" % \ + self.assertEqual(json.dumps(diff).strip(), "{}", + "Empty objects diff.\n\nexpected = %s\n\nobserved = %s" % (str({}), str(diff))) def test_simple(self): diffator = json_diff.Comparator(StringIO(SIMPLE_OLD), StringIO(SIMPLE_NEW)) diff = diffator.compare_dicts() expected = json.loads(SIMPLE_DIFF) - self.assertEqual(diff, expected, "All-scalar objects diff." + \ - "\n\nexpected = %s\n\nobserved = %s" % \ + self.assertEqual(diff, expected, "All-scalar objects diff." + + "\n\nexpected = %s\n\nobserved = %s" % (str(expected), str(diff))) def test_realFile(self): diffator = json_diff.Comparator(open("test/old.json"), open("test/new.json")) diff = diffator.compare_dicts() expected = json.load(open("test/diff.json")) - self.assertEqual(diff, expected, "Simply nested objects (from file) diff." + \ - "\n\nexpected = %s\n\nobserved = %s" % \ + self.assertEqual(diff, expected, "Simply nested objects (from file) diff." + + "\n\nexpected = %s\n\nobserved = %s" % (str(expected), str(diff))) def test_nested(self): diffator = json_diff.Comparator(StringIO(NESTED_OLD), StringIO(NESTED_NEW)) diff = diffator.compare_dicts() expected = json.loads(NESTED_DIFF) - self.assertEqual(diff, expected, "Nested objects diff. " + \ - "\n\nexpected = %s\n\nobserved = %s" % \ + self.assertEqual(diff, expected, "Nested objects diff. " + + "\n\nexpected = %s\n\nobserved = %s" % (str(expected), str(diff))) + + def test_nested_formatted(self): + diffator = json_diff.Comparator(open("test/old.json"), open("test/new.json")) + diff = "\n".join([line.strip() \ + for line in str(json_diff.HTMLFormatter(diffator.compare_dicts())).split("\n")]) + expected = "\n".join([line.strip() for line in open("test/nested_html_output.html").readlines()]) + self.assertEqual(diff, expected, "Simply nested objects (from file) diff formatted as HTML." + + "\n\nexpected = %s\n\nobserved = %s" % + (expected, diff)) + def test_large_with_exclusions(self): - diffator = json_diff.Comparator(open("test/old-testing-data.json"), \ + diffator = json_diff.Comparator(open("test/old-testing-data.json"), open("test/new-testing-data.json"), ('command', 'time')) diff = diffator.compare_dicts() expected = json.load(open("test/diff-testing-data.json")) - self.assertEqual(diff, expected, "Large objects with exclusions diff." + \ - "\n\nexpected = %s\n\nobserved = %s" % \ + self.assertEqual(diff, expected, "Large objects with exclusions diff." + + "\n\nexpected = %s\n\nobserved = %s" % (str(expected), str(diff))) + +NO_JSON_OLD = u""" +THIS IS NOT A JSON STRING +""" + +NO_JSON_NEW = u""" +AND THIS NEITHER +""" + + +class TestSadPath(unittest.TestCase): + def test_no_JSON(self): + self.assertRaises(json_diff.BadJSONError, + json_diff.Comparator, StringIO(NO_JSON_OLD), StringIO(NO_JSON_NEW)) + + if __name__ == "__main__": unittest.main()
\ No newline at end of file |