Permalink
Browse files

Working start on mocking out dbus for testing.

  • Loading branch information...
mackstann committed Feb 10, 2011
1 parent d19db83 commit 0a4eb51ecd54ac6f0b8c631bdc0c9c9705499723
Showing with 49 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. 0 mock/__init__.py
  3. +43 −0 mock/dbus.py
  4. +5 −0 mpris-remote
View
@@ -0,0 +1 @@
+*.pyc
View
No changes.
View
@@ -0,0 +1,43 @@
+_current_player_name = None
+_method_calls = []
+
+def start_mocking(player_name):
+ global _current_player_name
+ _current_player_name = player_name
+
+class MockFailure(Exception):
+ pass
+
+class _ProxyObject(object):
+ def __init__(self, path):
+ self.path = path
+
+class SessionBus(object):
+ def __init__(self):
+ if _current_player_name is None:
+ raise MockFailure("start_mocking() was not called.")
+
+ def get_object(self, bus_name, object_path):
+ if bus_name != 'org.mpris.' + _current_player_name:
+ raise MockFailure("requested player name is wrong")
+ if object_path not in ('/', '/Player', '/TrackList'):
+ raise MockFailure("requested object path is wrong")
+ return _ProxyObject(object_path)
+
+ def list_names(self):
+ return ['org.mpris.' + _current_player_name]
+
+class Interface(object):
+ def __init__(self, obj, dbus_interface):
+ if dbus_interface != 'org.freedesktop.MediaPlayer':
+ raise MockFailure("dbus_interface is wrong")
+ self.obj = obj
+
+ def __getattr__(self, methodname):
+ def recorder(*args):
+ _method_calls.append((self.obj.path, methodname) + args)
+ return recorder
+
+class exceptions(object):
+ class DBusException(Exception):
+ pass
View
@@ -86,7 +86,10 @@ NOTES:
starts them at one. (track "1/2" being the last track would make no sense.)
"""
+#import sys
+#sys.path.insert(0, './mock')
import os, sys, re, time, urllib2, dbus
+#dbus.start_mocking('foo')
org_mpris_re = re.compile('^org\.mpris\.([^.]+)$')
@@ -531,4 +534,6 @@ if __name__ == '__main__':
except KeyboardInterrupt:
raise SystemExit(2)
+ #print dbus._method_calls
+

0 comments on commit 0a4eb51

Please sign in to comment.