[Freeipa-devel] [PATCH 25/25] assert_deepequal supports callback for equality

John Dennis jdennis at redhat.com
Wed Jun 15 15:39:52 UTC 2011


The unit test framework recursively checks for equality between the
"expected" and "got". When it finds a non-container object it checks for
equality between the expected and got objects. However sometimes a
simple equality test is insufficient. This can happen when two values
are equivalent but not equal. For example the two values might be
encoded differently, hence the encoded values differ, but when decoded
they are identical.

To support these special cases one can now insert callable object to
the expected container. When assert_deepequal sees a callable it does
not test for equality, rather it calls the callable passing it the got
object. The callable returns True if the got value is expected. This can
simply be done with a lambda expression with a closure on the expected
value, for example:

expected = {
      dn=lambda got: DN(got) == privilege1_dn
}

In this case the "got" dn value is passed to the function which converts
it to a DN object which can be compared with privilege1_dn, a local DN
object, privilege1_dn is bound by closure. The equality callback is
necessary because DN's can be encoded differently.

-- 
John Dennis <jdennis at redhat.com>

Looking to carve out IT costs?
www.redhat.com/carveoutcosts/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0025-assert_deepequal-supports-callback-for-equality-test.patch
Type: text/x-patch
Size: 1959 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20110615/8d5dc0a6/attachment.bin>


More information about the Freeipa-devel mailing list