Python version of XMLUnit?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kent Johnson

    #1

    Python version of XMLUnit?

    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).

    Thanks,
    Kent

    unit testing, test driven development, xml, xmlunit, junit, nunit

  • Benjamin Niemann

    #2
    Re: Python version of XMLUnit?

    Kent Johnson wrote:
    [color=blue]
    > 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).[/color]



    You'd still have to integrate this into your test framework though...

    And I'll have a look at XMLUnit - seem's like something I could use for my
    current project ;)

    --
    Benjamin Niemann
    Email: pink at odahoda dot de
    WWW: http://www.odahoda.de/

    Comment

    • Kent Johnson

      #3
      Re: Python version of XMLUnit?

      Benjamin Niemann wrote:[color=blue]
      > http://www.logilab.org/projects/xmldiff
      >
      > You'd still have to integrate this into your test framework though...[/color]

      Thanks, that looks promising.[color=blue]
      >
      > And I'll have a look at XMLUnit - seem's like something I could use for my
      > current project ;)[/color]

      XMLUnit is *very* useful. For example here is a typical assertion error:
      [different] Expected attribute value '1500' but was '150' - comparing
      <HotspotModelIt em height="1500".. .> at
      /PageItem[1]/HotspotModelIte m[1]/@height to <HotspotModelIt em
      height="150"... > at /PageItem[1]/HotspotModelIte m[1]/@height

      Notice how it shows you exactly the error including XPath expressions to
      the node containing the error!

      In Jython I use unittest, not JUnit, so instead of subclassing
      XMLTestCase I call the static methods of XLMAssert from my test cases.

      Kent

      Comment

      • uche.ogbuji@gmail.com

        #4
        Re: Python version of XMLUnit?

        Kent Johnson wrote:[color=blue]
        > 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).[/color]

        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:



        It includes a brief example using the c14n module in PyXML



        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.



        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/

        Comment

        Working...