Merge lp:~alecu/ubuntu-sso-client/silence-dbus-logger into lp:ubuntu-sso-client

Proposed by Alejandro J. Cura on 2012-01-06
Status: Merged
Approved by: Alejandro J. Cura on 2012-01-10
Approved revision: 828
Merged at revision: 829
Proposed branch: lp:~alecu/ubuntu-sso-client/silence-dbus-logger
Merge into: lp:ubuntu-sso-client
Diff against target: 46 lines (+22/-0)
1 file modified
ubuntu_sso/utils/tests/test_txsecrets.py (+22/-0)
To merge this branch: bzr merge lp:~alecu/ubuntu-sso-client/silence-dbus-logger
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve on 2012-01-10
Natalia Bidart 2012-01-06 Approve on 2012-01-06
Review via email: mp+87815@code.launchpad.net

Commit Message

Silence warnings printed by dbus on the test run (LP: #912920)

Description of the Change

Silence warnings printed by dbus on the test run (LP: #912920)

To post a comment you must log in.
Natalia Bidart (nataliabidart) wrote :

Awesome is little next to this branch.

review: Approve
dobey (dobey) wrote :

I wonder if we should put this in ubuntuone-dev-tools instead, inside the dbus test case there. Then it would fix the issue for all our projects, and we wouldn't have to copy this code to all of them. :)

Alejandro J. Cura (alecu) wrote :

Happy new year, nessita!

Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/utils/tests/test_txsecrets.py'
2--- ubuntu_sso/utils/tests/test_txsecrets.py 2011-11-21 15:31:53 +0000
3+++ ubuntu_sso/utils/tests/test_txsecrets.py 2012-01-06 21:07:24 +0000
4@@ -17,6 +17,7 @@
5 # with this program. If not, see <http://www.gnu.org/licenses/>.
6 """Tests for txkeyring."""
7
8+import logging
9 import uuid
10
11 import dbus.service
12@@ -389,6 +390,19 @@
13 return base + "/" + random
14
15
16+class TextFilter(logging.Filter):
17+ """Prevents the logging of messages containing a given text."""
18+
19+ def __init__(self, *args):
20+ """Initialize this filter."""
21+ super(TextFilter, self).__init__()
22+ self.filtered_strings = args
23+
24+ def filter(self, record):
25+ """See if we need to filter a given log record."""
26+ return not any(s in record.msg for s in self.filtered_strings)
27+
28+
29 class BaseTestCase(DBusTestCase):
30 """Base class for DBus tests."""
31 timeout = 10
32@@ -401,6 +415,14 @@
33 self.mock_service = self.dbus_publish(txsecrets.SECRETS_SERVICE,
34 self.secret_service_class)
35 self.secretservice = txsecrets.SecretService()
36+ self.silence_dbus_logging()
37+
38+ def silence_dbus_logging(self):
39+ """Silence the warnings printed by dbus that pollute test results."""
40+ logger = logging.getLogger('dbus.connection')
41+ logfilter = TextFilter("Unable to set arguments")
42+ logger.addFilter(logfilter)
43+ self.addCleanup(logger.removeFilter, logfilter)
44
45 def dbus_publish(self, object_path, object_class, *args, **kwargs):
46 """Create an object and publish it on the bus."""

Subscribers

People subscribed via source and target branches