[Telepathy-commits] [telepathy-gabble/master] gabbletest.py: factor out colouring code
Dafydd Harries
dafydd.harries at collabora.co.uk
Tue Aug 19 10:52:24 PDT 2008
20080506210405-c9803-c74a393e2a8458bba3698ef93244bdca680fcd95.gz
---
tests/twisted/gabbletest.py | 45 ++++++++++++++++++++++--------------------
1 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/tests/twisted/gabbletest.py b/tests/twisted/gabbletest.py
index 1d009c7..b94bfbd 100644
--- a/tests/twisted/gabbletest.py
+++ b/tests/twisted/gabbletest.py
@@ -260,6 +260,29 @@ def go(params=None, authenticator=None, protocol=None, start=None):
reactor.run()
+def install_colourer():
+ def red(s):
+ return '\x1b[31m%s\x1b[0m' % s
+
+ def green(s):
+ return '\x1b[32m%s\x1b[0m' % s
+
+ patterns = {
+ 'handled': green,
+ 'not handled': red,
+ }
+
+ class Colourer:
+ def __init__(self, fh, patterns):
+ self.fh = fh
+ self.patterns = patterns
+
+ def write(self, s):
+ f = self.patterns.get(s, lambda x: x)
+ self.fh.write(f(s))
+
+ sys.stdout = Colourer(sys.stdout, patterns)
+
def exec_test(fun, params=None, protocol=None, timeout=None):
queue = servicetest.IteratingEventQueue(timeout)
@@ -273,27 +296,7 @@ def exec_test(fun, params=None, protocol=None, timeout=None):
domish.Element.__repr__ = domish.Element.toXml
if sys.stdout.isatty():
- def red(s):
- return '\x1b[31m%s\x1b[0m' % s
-
- def green(s):
- return '\x1b[32m%s\x1b[0m' % s
-
- patterns = {
- 'handled': green,
- 'not handled': red,
- }
-
- class Colourer:
- def __init__(self, fh, patterns):
- self.fh = fh
- self.patterns = patterns
-
- def write(self, s):
- f = self.patterns.get(s, lambda x: x)
- self.fh.write(f(s))
-
- sys.stdout = Colourer(sys.stdout, patterns)
+ install_colourer()
try:
fun(queue, bus, conn, stream)
--
1.5.6.3
More information about the Telepathy-commits
mailing list