__repr__ hack for domish.Element doesn't work because assert uses str()
@wjt
Submitted by Will Thompson Assigned to Telepathy bugs list
Description
servicetest.py contains the following:
# hack to ease debugging
domish.Element.__repr__ = domish.Element.toXml
The intention is that code like:
assert element['foo'] == bar, element
should produce the stringified xml of element when the assertion fails. This does not in fact work, as assert uses str() not repr().
Overriding str in the same way yields bizarro exceptions:
Traceback (most recent call last): File "/build/buildd/python2.4-2.4.5/Modules/pyexpat.c", line 639, in EndElement
File "/usr/lib/python2.4/site-packages/twisted/words/xish/domish.py", line 780, in _onEndElement
self.ElementEvent(self.currElem)
File "/usr/lib/python2.4/site-packages/twisted/words/xish/xmlstream.py", line 106, in onElement
self.dispatch(element)
File "/usr/lib/python2.4/site-packages/twisted/words/xish/utility.py", line 316, in dispatch
callbacklist.callback(obj)
--- <exception caught here>
---
File "/usr/lib/python2.4/site-packages/twisted/words/xish/utility.py", line 106, in callback
methodwrapper(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/twisted/words/xish/utility.py", line 27, in call
self.method(*nargs, **nkwargs)
File "/home/will/src/Telepathy/telepathy-gabble/tests/twisted/gabbletest.py", line 75, in secondIq
assert map(str, username) == [self.username]
exceptions.AssertionError:
Traceback (most recent call last):
File "/home/will/src/Telepathy/telepathy-gabble/tests/twisted/gabbletest.py", line 316, in exec_test_deferred
fun(queue, bus, conn, stream)
File "./muc/test-muc.py", line 16, in test
q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
File "/home/will/src/Telepathy/telepathy-gabble/tests/twisted/servicetest.py", line 217, in expect
event = self.wait()
File "/home/will/src/Telepathy/telepathy-gabble/tests/twisted/servicetest.py", line 286, in wait
raise TimeoutError
TimeoutError