I want to unittest a function that outputs data in XML format. A direct string comparison would not work obviously, because the order of the elements and the amount of whitespace do not matter.
Asked
Active
Viewed 46 times
0
-
3Then you would have to test that the XML parses to the correct values. – jonrsharpe Mar 31 '15 at 17:27
-
What have you tried so far? What, specifically, do you want to test? That data was written? That correct values are genrated? Both? Is the XML generated and/or written using another tool or is it all done by hand by you? There is nowhere near enough information to answer this question. – TheBlackCat Mar 31 '15 at 17:35
-
The main objective is to test whether whether the output has the correct tree structure. There seems to be the package `XML-unittest`. Has anyone experience with it? – Thomas Schreiter Mar 31 '15 at 17:43
-
It looks like [`assertXMLEquivalentOutputs`](http://python-xmlunittest.readthedocs.org/en/latest/xmlunittest.html#xmlunittest.XmlTestMixin.assertXmlEquivalentOutputs) does exactly what you want. You might also want to look at the [source code](https://github.com/Exirel/python-xmlunittest/blob/master/xmlunittest.py#L216); it mentions using lxml's [LXMLOutputChecker](http://lxml.de/3.3/api/lxml.doctestcompare.LXMLOutputChecker-class.html). – unutbu Mar 31 '15 at 18:19
-
I'm going to close this as a duplicate of http://stackoverflow.com/q/321795/190597; @ThS: If you test XML-unittest and find it solves your problem, you might want to add it as an answer there. – unutbu Mar 31 '15 at 18:21
-
@unutbu: I found that `lxml` and `xpath` provide exactly the functionality that compares elements of the XML tree, which I want to do (Also, I now realize how ambigiously and the original post was worded. Can I downvote my own post? ;) – Thomas Schreiter Apr 15 '15 at 16:20