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

Rob Crittenden rcritten at redhat.com
Wed Jun 22 21:06:53 UTC 2011


John Dennis wrote:
> 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.
>
>
>

Ack, pushed to master and ipa-2-0




More information about the Freeipa-devel mailing list