Merge lp:~mvo/software-center/fix-dataprovider-dbus-tests into lp:software-center

Proposed by Michael Vogt on 2012-09-18
Status: Merged
Merged at revision: 3194
Proposed branch: lp:~mvo/software-center/fix-dataprovider-dbus-tests
Merge into: lp:software-center
Diff against target: 94 lines (+28/-15)
2 files modified
softwarecenter/db/dataprovider.py (+1/-1)
tests/test_dataprovider.py (+27/-14)
To merge this branch: bzr merge lp:~mvo/software-center/fix-dataprovider-dbus-tests
Reviewer Review Type Date Requested Status
Gary Lasker 2012-09-18 Pending
Review via email: mp+124895@code.launchpad.net

Description of the change

This properly isolates the dbus test for the dataprovider from the
session bus. For the upload of 5.3.14 this test was disabled to get
the upload out quickly but this branch now fixes this properly.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/db/dataprovider.py'
2--- softwarecenter/db/dataprovider.py 2012-09-17 12:42:08 +0000
3+++ softwarecenter/db/dataprovider.py 2012-09-18 11:44:21 +0000
4@@ -1,4 +1,4 @@
5-# Copyright (C) 2009 Canonical
6+# Copyright (C) 2012 Canonical
7 #
8 # Authors:
9 # Michael Vogt
10
11=== modified file 'tests/test_dataprovider.py'
12--- tests/test_dataprovider.py 2012-09-18 09:21:16 +0000
13+++ tests/test_dataprovider.py 2012-09-18 11:44:21 +0000
14@@ -1,12 +1,13 @@
15-
16+import copy
17 import dbus
18+import os
19+import subprocess
20 import time
21 import unittest
22
23 from dbus.mainloop.glib import DBusGMainLoop
24 DBusGMainLoop(set_as_default=True)
25
26-from multiprocessing import Process
27 from mock import Mock
28
29 from tests.utils import (
30@@ -19,40 +20,52 @@
31 from softwarecenter.db.application import AppDetails
32 from softwarecenter.db.dataprovider import (
33 SoftwareCenterDataProvider,
34- dbus_main,
35 DBUS_BUS_NAME,
36 DBUS_DATA_PROVIDER_IFACE,
37 DBUS_DATA_PROVIDER_PATH,
38 )
39
40
41+def start_data_provider_daemon(dbus_address):
42+ """Start the dbus data provider as a subprocess"""
43+ os.environ["DBUS_SESSION_BUS_ADDRESS"] = dbus_address
44+ testdir = os.path.dirname(__file__)
45+ basedir = os.path.abspath(os.path.join(testdir, ".."))
46+ data_provider_bin = os.path.join(basedir, "software-center-dbus")
47+ stderr = open(os.devnull, "w")
48+ # uncomment this for a flurry of debug output
49+ #stderr = None
50+ # this is more reliable than e.g. threading.Thead or multiprocess.Process
51+ p = subprocess.Popen([data_provider_bin], stderr=stderr)
52+ return p
53+
54+
55 class DbusForRealTestCase(unittest.TestCase):
56 """Test the dataprovider over a real dbus bus"""
57
58 @classmethod
59 def setUpClass(cls):
60- cls.p = Process(target=dbus_main)
61- cls.p.start()
62+ cls.dbus_daemon_proc, dbus_address = start_dbus_daemon()
63+ cls.bus = dbus.bus.BusConnection(dbus_address)
64+ cls.data_provider_proc = start_data_provider_daemon(dbus_address)
65 time.sleep(1)
66
67 @classmethod
68 def tearDownClass(cls):
69- print "down"
70- cls.p.terminate()
71- cls.p.join()
72+ kill_process(cls.data_provider_proc)
73+ kill_process(cls.dbus_daemon_proc)
74
75 def setUp(self):
76- bus = dbus.SessionBus()
77- obj = bus.get_object(bus_name=DBUS_BUS_NAME,
78+ obj = self.bus.get_object(bus_name=DBUS_BUS_NAME,
79 object_path=DBUS_DATA_PROVIDER_PATH,
80 follow_name_owner_changes=True)
81 self.proxy = dbus.Interface(object=obj,
82 dbus_interface=DBUS_DATA_PROVIDER_IFACE)
83
84- @unittest.skip("not reliable yet")
85- def test_dbus_for_real(self):
86- result = self.proxy.GetAppDetails("", "gedit")
87- self.assertEqual(result["pkgname"], "gedit")
88+ def test_dbus_on_real_bus(self):
89+ result = self.proxy.GetAppDetails("", "gimp")
90+ self.assertEqual(result["pkgname"], "gimp")
91+ self.assertEqual(result["icon"], "gimp")
92
93
94 class PropertyDictExceptionsTestCase(unittest.TestCase):

Subscribers

People subscribed via source and target branches