forked from steemit/steem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
386d543
commit 94bc1f9
Showing
1 changed file
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
def isSubDict(response, pattern): | ||
def dict_contain(response, pattern): | ||
for key in pattern.keys(): | ||
if (not key in response) or (pattern[key] != response[key]): | ||
return False | ||
return True | ||
|
||
COMPARATORS = { 'json_compare': isSubDict } | ||
def list_contain(response, pattern): | ||
for item in pattern: | ||
if item not in response: | ||
return False | ||
return True | ||
|
||
def contain(response, pattern): | ||
if type(response) != type(pattern): | ||
return False | ||
|
||
if type(response) == 'dict': | ||
return dict_contain(response, pattern) | ||
if type(response) == 'list': | ||
return list_contain(response, pattern) | ||
if type(response) == 'str': | ||
return pattern in response | ||
# all other types | ||
return pattern == response | ||
|
||
COMPARATORS = { 'json_compare': contain } |