summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-12-07 16:13:16 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2012-12-07 16:13:16 +0000
commitbf5dcce04b9063c9482def3041dd80b79d47f5b7 (patch)
tree82078c932b069304da6f41f0b989879b73367a65
parent55930f39965c9d9ba356aaba4a24fe4f687a5d3d (diff)
tests: don't crash in verbose mode on unicode in stanzas
We have this hack that sets __repr__ on domish.Element to call its toXml() method, which ends up being used by the verbose logging code when it dumps all of an event's attributes. Unfortunately, this blows up if a stanza contains non-ASCII characters, because repr() tries to convert unicode to str using .encode('ascii'). This made running jingle/test-send-file in verbose mode fail, because the file being sent by the test has a non-ASCII filename. The fix is to make the __repr__ hack escape non-ASCII characters using the unicode-escape codec.
-rw-r--r--tests/twisted/gabbletest.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/tests/twisted/gabbletest.py b/tests/twisted/gabbletest.py
index 4baf924ef..8cc7d24f3 100644
--- a/tests/twisted/gabbletest.py
+++ b/tests/twisted/gabbletest.py
@@ -555,11 +555,19 @@ def disconnect_conn(q, conn, stream, expected_before=[], expected_after=[]):
return before_events[:-2], after_events[:-1]
+def element_repr(element):
+ """__repr__ cannot safely return non-ASCII: see
+ <http://bugs.python.org/issue5876>. So we print non-ASCII characters as
+ \uXXXX escapes in debug output
+
+ """
+ return element.toXml().encode('unicode-escape')
+
def exec_test_deferred(fun, params, protocol=None, timeout=None,
authenticator=None, num_instances=1,
do_connect=True):
# hack to ease debugging
- domish.Element.__repr__ = domish.Element.toXml
+ domish.Element.__repr__ = element_repr
colourer = None
if sys.stdout.isatty() or 'CHECK_FORCE_COLOR' in os.environ: