summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2012-11-24 07:49:02 -0600
committerDenis Kenzior <denkenz@gmail.com>2012-11-28 10:31:14 -0600
commit2eaacefbe03f002d4a8826ade1b17eb8faf82d7b (patch)
tree2ba8ae69896cb7ed855f229f15f2cb26a09f4a0a /test
parent5afd6e1f5d71a4471d09762194d9710c2b9a7f51 (diff)
downloadofono-2eaacefbe03f002d4a8826ade1b17eb8faf82d7b.tar.bz2
test: Use pretty-printing from monitor-ofono
Diffstat (limited to 'test')
-rwxr-xr-xtest/test-stk-menu50
1 files changed, 49 insertions, 1 deletions
diff --git a/test/test-stk-menu b/test/test-stk-menu
index 8578be1d..ae6dbcb4 100755
--- a/test/test-stk-menu
+++ b/test/test-stk-menu
@@ -297,8 +297,56 @@ class StkAgent(dbus.service.Object):
else:
return False
+_dbus2py = {
+ dbus.String : unicode,
+ dbus.UInt32 : int,
+ dbus.Int32 : int,
+ dbus.Int16 : int,
+ dbus.UInt16 : int,
+ dbus.UInt64 : int,
+ dbus.Int64 : int,
+ dbus.Byte : int,
+ dbus.Boolean : bool,
+ dbus.ByteArray : str,
+ dbus.ObjectPath : str
+ }
+
+def dbus2py(d):
+ t = type(d)
+ if t in _dbus2py:
+ return _dbus2py[t](d)
+ if t is dbus.Dictionary:
+ return dict([(dbus2py(k), dbus2py(v)) for k, v in d.items()])
+ if t is dbus.Array and d.signature == "y":
+ return "".join([chr(b) for b in d])
+ if t is dbus.Array or t is list:
+ return [dbus2py(v) for v in d]
+ if t is dbus.Struct or t is tuple:
+ return tuple([dbus2py(v) for v in d])
+ return d
+
+def pretty(d):
+ d = dbus2py(d)
+ t = type(d)
+
+ if t in (dict, tuple, list) and len(d) > 0:
+ if t is dict:
+ d = ", ".join(["%s = %s" % (k, pretty(v))
+ for k, v in d.items()])
+ return "{ %s }" % d
+
+ d = " ".join([pretty(e) for e in d])
+
+ if t is tuple:
+ return "( %s )" % d
+
+ if t is str:
+ return "%s" % d
+
+ return str(d)
+
def property_changed(name, value):
- print "SimToolKit property: %s changed to '%s'" % (name, value)
+ print "SimToolKit property: %s changed to '%s'" % (name, pretty(value))
if __name__ == '__main__':
if len(sys.argv) == 2: