[Twisted-Python] domish.Element comparison not working
Gabriel Rossetti
mailing_lists at evotex.ch
Tue Jul 8 08:07:42 MDT 2008
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
More information about the Twisted-Python
mailing list