Skip to content

Commit

Permalink
improve 'contain' comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
mkochanowicz committed Jan 10, 2018
1 parent 386d543 commit 94bc1f9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions python_scripts/tests/api_tests/comparator_contain.py
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 }

0 comments on commit 94bc1f9

Please sign in to comment.