[PATCH 01/13] test: Uniformly canonicalize actual and expected JSON

Tomi Ollila tomi.ollila at iki.fi
Wed Jul 25 20:24:58 PDT 2012


On Wed, Jul 25 2012, Austin Clements <amdragon at MIT.EDU> wrote:

> Previously, we used a variety of ad-hoc canonicalizations for JSON
> output in the test suite, but were ultimately very sensitive to JSON
> irrelevancies such as whitespace.  This introduces a new test
> comparison function, test_expect_equal_json, that first pretty-prints
> *both* the actual and expected JSON and the compares the result.
>
> The current implementation of this simply uses Python's json.tool to
> perform pretty-printing (with a fallback to the identity function if
> parsing fails).  However, since the interface it introduces is
> semantically high-level, we could swap in other mechanisms in the
> future, such as another pretty-printer or something that does not
> re-order object keys (if we decide that we care about that).


The whole series looks good to me and was easy to read through.
The use of Python json.tool is pretty reasonable; It is shipped in
Python 2.6+ (For example perl does not ship json components by default,
making it more complicated to set up for this purpose). If that is too
"much", then we could also use tr -d '[:space:]' as an intermediate
solution (but that eats whitespace in quoted content too...)

I'll be afk for a few days then I test this... 

Tomi


More information about the notmuch mailing list