From 55ecf051ec011970b1df11c5556f7fed2b6ea9ae Mon Sep 17 00:00:00 2001 From: selston Date: Mon, 7 Apr 2014 13:34:24 -0500 Subject: [PATCH 1/3] fix bug in parameter name --- README.md | 5 +++++ jsoncompare/jsoncompare.py | 2 +- jsoncompare/test/test_jsoncompare.py | 12 +++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d2bdd29..e10fa52 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,11 @@ pip install jsoncompare * Additional complexity comes in when your json array's order doesn't matter. * For example, you might have a set in Java that you are going to send over the wire as json. It may be represented as a json array but in actuality, you don't care about the order. +## Recent Changes +# Version Comments +# 0.1.1 Orginal Version +# 0.1.2 Adds support for "contains" + ##Examples ```python from jsoncompare import jsoncompare diff --git a/jsoncompare/jsoncompare.py b/jsoncompare/jsoncompare.py index cd777b2..afb3353 100644 --- a/jsoncompare/jsoncompare.py +++ b/jsoncompare/jsoncompare.py @@ -154,7 +154,7 @@ def are_same(original_a, original_b, ignore_list_order_recursively=False, ignore return _are_same(a, b, ignore_value_of_keys) -def contains(expected_original, actual_orginal, ignore_list_order_recursively=False, ignore_value_of_keys=[]): +def contains(expected_original, actual_original, ignore_list_order_recursively=False, ignore_value_of_keys=[]): if ignore_list_order_recursively: actual = _bottom_up_sort(actual_original) expected = _bottom_up_sort(expected_original) diff --git a/jsoncompare/test/test_jsoncompare.py b/jsoncompare/test/test_jsoncompare.py index ccf53c3..490f496 100755 --- a/jsoncompare/test/test_jsoncompare.py +++ b/jsoncompare/test/test_jsoncompare.py @@ -262,9 +262,11 @@ def test_contains_same_size(self): {"wtf1": "omg1"} ] self.assertTrue(jsoncompare.contains(expected, actual)[0]) + #same, error_message = jsoncompare.contains(expected, actual) + #assert same, error_message # Test two json that are same size but values do not match - def test_contains_same_size(self): + def test_contains_same_size2(self): actual = [ {"wtf": "omg"}, {"wtf1": "omg1"} @@ -278,7 +280,7 @@ def test_contains_same_size(self): #assert same, error_message # Test two json that are same size but keys do not match - def test_contains_same_size(self): + def test_contains_same_size3(self): actual = [ {"wtf": "omg"}, {"wtf1": "omg1"} @@ -288,8 +290,8 @@ def test_contains_same_size(self): {"wtf999": "omg1"} ] self.assertFalse(jsoncompare.contains(expected, actual)[0]) - #same, error_message = jsoncompare.contains(expected, actual) - #assert same, error_message + same, error_message = jsoncompare.contains(expected, actual) + assert same, error_message # Test two json where Actual is larger - it can (potentialy) contain all of the expected attributes def test_contains_actual_bigger(self): @@ -304,7 +306,7 @@ def test_contains_actual_bigger(self): ] self.assertTrue(jsoncompare.contains(expected, actual)[0]) - # Test two josn where Actual is smaller - it can NOT contain all of expected attributes + # Test two json where Actual is smaller - it can NOT contain all of expected attributes def test_contains_actual_smaller(self): actual = [ {"wtf": "omg"}, From caebf7b303a44589996ed152670ec5488729ad36 Mon Sep 17 00:00:00 2001 From: selston Date: Mon, 7 Apr 2014 14:12:03 -0500 Subject: [PATCH 2/3] contineu bug fix and added another test with sort order --- jsoncompare/jsoncompare.py | 2 +- jsoncompare/test/test_jsoncompare.py | 20 ++++++++++++++++---- setup.py | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/jsoncompare/jsoncompare.py b/jsoncompare/jsoncompare.py index afb3353..9a2357f 100644 --- a/jsoncompare/jsoncompare.py +++ b/jsoncompare/jsoncompare.py @@ -159,7 +159,7 @@ def contains(expected_original, actual_original, ignore_list_order_recursively=F actual = _bottom_up_sort(actual_original) expected = _bottom_up_sort(expected_original) else: - actual = actual_orginal + actual = actual_original expected = expected_original return _are_same(expected, actual, ignore_value_of_keys, True) diff --git a/jsoncompare/test/test_jsoncompare.py b/jsoncompare/test/test_jsoncompare.py index 490f496..541ddfb 100755 --- a/jsoncompare/test/test_jsoncompare.py +++ b/jsoncompare/test/test_jsoncompare.py @@ -265,8 +265,20 @@ def test_contains_same_size(self): #same, error_message = jsoncompare.contains(expected, actual) #assert same, error_message - # Test two json that are same size but values do not match + # Test two json that are same size and keys/values match with ignore_order def test_contains_same_size2(self): + actual = [ + {"wtf": "omg"}, + {"wtf1": "omg1"} + ] + expected = [ + {"wtf": "omg"}, + {"wtf1": "omg1"} + ] + self.assertTrue(jsoncompare.contains(expected, actual, True)[0]) + + # Test two json that are same size but values do not match + def test_contains_same_size3(self): actual = [ {"wtf": "omg"}, {"wtf1": "omg1"} @@ -280,7 +292,7 @@ def test_contains_same_size2(self): #assert same, error_message # Test two json that are same size but keys do not match - def test_contains_same_size3(self): + def test_contains_same_size4(self): actual = [ {"wtf": "omg"}, {"wtf1": "omg1"} @@ -290,8 +302,8 @@ def test_contains_same_size3(self): {"wtf999": "omg1"} ] self.assertFalse(jsoncompare.contains(expected, actual)[0]) - same, error_message = jsoncompare.contains(expected, actual) - assert same, error_message + #same, error_message = jsoncompare.contains(expected, actual) + #assert same, error_message # Test two json where Actual is larger - it can (potentialy) contain all of the expected attributes def test_contains_actual_bigger(self): diff --git a/setup.py b/setup.py index 893a60c..1905bfb 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def read_readme(fname): setup( name = 'jsoncompare', - version = '0.1.1', + version = '0.1.2', description = 'Json comparison tool', author = 'Daniel Myers', author_email = 'dmandroid88@gmail.com', From 4f0e3c3bc2a9cd0258d0aca043e429064d8d7691 Mon Sep 17 00:00:00 2001 From: selston Date: Mon, 7 Apr 2014 14:15:34 -0500 Subject: [PATCH 3/3] fix format of readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e10fa52..f45c45b 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ pip install jsoncompare * For example, you might have a set in Java that you are going to send over the wire as json. It may be represented as a json array but in actuality, you don't care about the order. ## Recent Changes -# Version Comments -# 0.1.1 Orginal Version -# 0.1.2 Adds support for "contains" + Version Comments + 0.1.1 Orginal Version + 0.1.2 Adds support for "contains" ##Examples ```python