summaryrefslogtreecommitdiffstats
path: root/tests/util.py
diff options
context:
space:
mode:
authorJohn Dennis <jdennis@redhat.com>2011-06-15 09:05:58 -0400
committerRob Crittenden <rcritten@redhat.com>2011-06-22 01:16:31 -0400
commit4c1bfdb9198bcf831282244b6666d9776529ab37 (patch)
treec0c0acd86dc70ce106d13de578401beb8108420a /tests/util.py
parent1a7d05cc0f8c06a6f59d0db75361fa1a06189bee (diff)
downloadfreeipa-4c1bfdb9198bcf831282244b6666d9776529ab37.tar.gz
freeipa-4c1bfdb9198bcf831282244b6666d9776529ab37.tar.xz
freeipa-4c1bfdb9198bcf831282244b6666d9776529ab37.zip
assert_deepequal supports callback for equality testing
Diffstat (limited to 'tests/util.py')
-rw-r--r--tests/util.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/util.py b/tests/util.py
index 3d59f5829..48260dd7c 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -266,6 +266,10 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
"""
Recursively check for type and equality.
+ If a value in expected is callable then it will used as a callback to
+ test for equality on the got value. The callback is passed the got
+ value and returns True if equal, False otherwise.
+
If the tests fails, it will raise an ``AssertionError`` with detailed
information, including the path to the offending value. For example:
@@ -288,7 +292,7 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
expected = list(expected)
if isinstance(got, tuple):
got = list(got)
- if not (isinstance(expected, Fuzzy) or type(expected) is type(got)):
+ if not (isinstance(expected, Fuzzy) or callable(expected) or type(expected) is type(got)):
raise AssertionError(
TYPE % (doc, type(expected), type(got), expected, got, stack)
)
@@ -312,6 +316,11 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
e_sub = expected[key]
g_sub = got[key]
assert_deepequal(e_sub, g_sub, doc, stack + (key,))
+ elif callable(expected):
+ if not expected(got):
+ raise AssertionError(
+ VALUE % (doc, expected, got, stack)
+ )
elif expected != got:
raise AssertionError(
VALUE % (doc, expected, got, stack)