[Twisted-Python] domish.Element comparison not working
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)
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)
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
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)
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)
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
Gabriel Rossetti wrote:
[..]
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.
Thanks for your contribution! Could you create a ticket for this and attach your patch? Acceptance also relies on there being unittests, so if you could provide those as well, that would speed up the process. ralphm
Ralph Meijer wrote:
Gabriel Rossetti wrote:
[..]
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.
Thanks for your contribution! Could you create a ticket for this and attach your patch? Acceptance also relies on there being unittests, so if you could provide those as well, that would speed up the process.
ralphm
Hi Ralph, You're welcome, it's not much, but I think it's useful. I already did file a ticket, it's # 3344, I also already made unit tests. Gabriel
participants (2)
-
Gabriel Rossetti
-
Ralph Meijer