Python version of XMLUnit?

uche.ogbuji at gmail.com uche.ogbuji at gmail.com
Tue Mar 7 11:23:21 EST 2006


Kent Johnson wrote:
> I have found XMLUnit to be very helpful for testing Java and Jython code
> that generates XML. At its heart XMLUnit is an XML-aware diff - it
> parses expected and actual XML and pinpoints any differences. It is
> smart enough to ignore things like attribute order, different quoting
> and escaping styles, and insignificant whitespace.
>
> Now I am working on a CPython project and have a similar need. Is there
> any comparable tool for Python? Basically I'm looking for a tool to
> compare XML and show diffs in an intelligible fashion that is usable
> from Python unit tests (using py.test, if it matters).

One possible approach is to use c14n to in effect normalize the XML so
that you can use regular text compare.  This is not as sophisticated as
a full XML diff, but it's definitely a viable approach for testing.

For those who migh tbe interested in that approach, learn more about
c14n here:

http://www.ibm.com/developerworks/xml/library/x-c14n/

It includes a brief example using the c14n module in PyXML

http://pyxml.sourceforge.net/

I also recently checked in c14n capability for 4Suite.  It offers the
same level of coverage as PyXML's, but operates in streaming, rather
than DOM mode.

http://4suite.org/

4Suite also contains in its test suite routines (TreeCompare) for
comparing XMl and HTML while ignoring non-significant syntactic
variations.

Certainly full xmldiff is very useful.  One nice thing about LogiLabs's
app is that it  can output XUpdate, which could be used with, say
4Suite's 4XUpdate to apply a patch to another document.

--
Uche Ogbuji                               Fourthought, Inc.
http://uche.ogbuji.net                    http://fourthought.com
http://copia.ogbuji.net                   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/




More information about the Python-list mailing list