[Twisted-Python] domish.Element comparison not working

Gabriel Rossetti mailing_lists at evotex.ch
Tue Jul 8 09:41:27 MDT 2008


Gabriel Rossetti wrote:
> Hello everyone,
>
> I need to compare two domish.Element objects in a unit test using 
> trial. I can't compare the string xml (using .toXml()) because 
> sometimes the attributes are not in the same order, and since it's a 
> string it uses normal string comparison and you see the problem, but I 
> can't use direct comparison either, so what should I use? If you look 
> at the example below you will see what I mean :
>
> >>> from twisted.words.xish import domish
> >>> root = domish.Element(('', 'test'))
> >>> s = domish.Element(('', 'feed'), attribs={'name':'myname'})
> >>> s.addContent("toto")
> 'toto'
> >>> root.addChild(s)
> <twisted.words.xish.domish.Element object at 0x848390c>
> >>> root.toXml()
> u"<test><feed name='myname'>toto</feed></test>"
> >>>
> >>> root2 = domish.Element(('', 'test'))
> >>> s = domish.Element(('', 'feed'), attribs={'name':'myname'})
> >>> s.addContent("toto")
> 'toto'
> >>> root2.addChild(s)
> <twisted.words.xish.domish.Element object at 0x84a342c>
> >>> root2.toXml()
> u"<test><feed name='myname'>toto</feed></test>"
> >>>
> >>> root == root2
> False
>
> As you see, root and root2 are equal in the sense that they contain 
> the same xml structure, same identifiers and the same values, but the 
> "==" comparison says they are false. Am i doing something wrong or is 
> the comparison just not implemented for those objects?
>
> Thank you,
> Gabriel
>
>
I went and looked and domish.Element has no __eq_(_) and __ne__() 
methods, here's a patch adding them, could someone review them and add 
them to the trunk? I made it against the trunk.

Thank you,
Gabriel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: domish.py.patch
Type: text/x-diff
Size: 1771 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20080708/3116dade/attachment-0002.patch>


More information about the Twisted-Python mailing list