Skip to content

Commit

Permalink
Merge pull request ChannelIQ#5 from selston69/master
Browse files Browse the repository at this point in the history
Fix bug in paramter name and added test to catch both branches
  • Loading branch information
dandroid88 committed Apr 7, 2014
2 parents 7a9afec + 4f0e3c3 commit 009bb3d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions jsoncompare/jsoncompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ 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)
else:
actual = actual_orginal
actual = actual_original
expected = expected_original
return _are_same(expected, actual, ignore_value_of_keys, True)

Expand Down
20 changes: 17 additions & 3 deletions jsoncompare/test/test_jsoncompare.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,23 @@ 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 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_size(self):
def test_contains_same_size3(self):
actual = [
{"wtf": "omg"},
{"wtf1": "omg1"}
Expand All @@ -278,7 +292,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_size4(self):
actual = [
{"wtf": "omg"},
{"wtf1": "omg1"}
Expand All @@ -304,7 +318,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"},
Expand Down

0 comments on commit 009bb3d

Please sign in to comment.