Rev 3: Allow assigning a bus to Activity, and test it does not crash for trivial operations with no service running. in file:///home/robertc/source/baz/plugins/dbus/trunk/

Robert Collins robertc at robertcollins.net
Tue Feb 6 04:16:36 GMT 2007


------------------------------------------------------------
revno: 3
revision-id: robertc at robertcollins.net-20070206041636-nfxqkxb7jrmgndx0
parent: robertc at robertcollins.net-20070206034833-4nqg6ul9waqgnup8
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Tue 2007-02-06 15:16:36 +1100
message:
  Allow assigning a bus to Activity, and test it does not crash for trivial operations with no service running.
added:
  tests/test_activity.py         test_activity.py-20070206035206-bnhzvtm6m6hpgylz-1
modified:
  TODO                           todo-20070206032729-2b5teqiwctqrfgei-3
  activity.py                    activity.py-20070206034725-q208d0jtkshwu0fx-1
  tests/__init__.py              __init__.py-20070206032729-2b5teqiwctqrfgei-7
=== added file 'tests/test_activity.py'
--- a/tests/test_activity.py	1970-01-01 00:00:00 +0000
+++ b/tests/test_activity.py	2007-02-06 04:16:36 +0000
@@ -0,0 +1,46 @@
+# bzr-dbus: dbus support for bzr/bzrlib.
+# Copyright (C) 2007 Canonical Limited.
+#   Author: Robert Collins.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+# 
+
+"""Tests for the dbus activity service."""
+
+import dbus
+
+from bzrlib.tests import TestCaseWithMemoryTransport
+
+from bzrlib.plugins.dbus import activity
+
+
+class TestActivity(TestCaseWithMemoryTransport):
+
+    def setUp(self):
+        TestCaseWithMemoryTransport.setUp(self)
+        # AFAIK this creates a private dbus session so we dont spam 
+        # the users desktop!
+        self.bus = dbus.StarterBus()
+        
+    def test_advertise_branch_no_service_running(self):
+        # should not error: just call it
+        activity.Activity(bus=self.bus).advertise_branch(self.make_branch('.'))
+
+    def test_constructor(self):
+        """The constructor should setup a good working environment."""
+        obj = activity.Activity()
+        # dbus uses a singleton approach for SessionBus, and we dont know if
+        # it has __eq__ or if it would be reliable, so we use object identity.
+        self.assertTrue(obj.bus is dbus.SessionBus(),
+            "%r is not %r" % (obj.bus, dbus.SessionBus()))

=== modified file 'TODO'
--- a/TODO	2007-02-06 03:48:33 +0000
+++ b/TODO	2007-02-06 04:16:36 +0000
@@ -1,6 +1,12 @@
 Plans for dbus and bzr
 ----------------------
 
+ * advertise_branch sends the message 'announce_revision' when the service is
+   running
+ * announce_revision when recieved sends the revision to all activity 
+   subscribers
+ * can subscribe to activity
+ * simple subscriber that sits in a corner and shows revisions
  * dbus service to act as the broadcast point for revisions
  * bzr server integration to republish tip revisions from file:/// to public
    URLs when one is available.

=== modified file 'activity.py'
--- a/activity.py	2007-02-06 03:48:33 +0000
+++ b/activity.py	2007-02-06 04:16:36 +0000
@@ -22,10 +22,24 @@
 about bzr activity: See the class for more detail.
 """
 
+import dbus
+
 
 class Activity(object):
     """bzrlib object activity tracking."""
 
+    def __init__(self, bus=None):
+        """Create an Activity object.
+
+        :param bus: A dbus Bus object. By default this will be set to
+            bus.SessionBus(). If you need a private bus or a system bus,
+            supply this parameter.
+        """
+        if bus is None:
+            self.bus = dbus.SessionBus()
+        else:
+            self.bus = bus
+
     def advertise_branch(self, branch):
         """Advertise branch to dbus.
 

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2007-02-06 03:30:59 +0000
+++ b/tests/__init__.py	2007-02-06 04:16:36 +0000
@@ -25,6 +25,7 @@
 
 def test_suite():
     module_names = [
+        'bzrlib.plugins.dbus.tests.test_activity',
         'bzrlib.plugins.dbus.tests.test_hook',
         ]
     loader = TestLoader()



More information about the bazaar-commits mailing list