Friday, 28 September 2007

Test notifications in gnome

I was quite impressed about rails/mac folks creating fancy test notifications by simply connecting zentest/autotest with growl. I wondered how can I get something similar in gnome. As it turns out - it's pretty straightforward - involves only 4 lines of python code and works using dbus. It uses one of the parts - NotifyService. I created a tiny script for that. It looks rather nice and integrates well (the same service is used by gajim or rhythmbox).

Here's how you invoke it: konrad@machine:~$ python ./bin/test_notifier/ pass 'Test passed' "4 tests
9 assertions
0 failures
0 errors"

konrad@machine:~$ python ./bin/test_notifier/ fail 'Test failed' "4 tests
9 assertions
2 failures
0 errors"

And the code itself (btw: forget about 4 lines - here comes error handling:>)

import sys
import dbus
from os import path, getcwd

status, title, message = sys.argv[1:]
icon_filename = {'pass': 'passed.png', 'fail': 'failed.png'}.get(status)
except Exception:
print 'Usage:\n\t\ttest_notifier [fail|pass] title message'

bus = dbus.SessionBus()
notifyService = bus.get_object("org.freedesktop.Notifications",
interface = dbus.Interface(notifyService,

icon_filename = path.join(getcwd(),

interface.Notify('test_runner', 0,
title, message,
[], {}, -1)

1 comment:

Tartley said...

This is brilliant.... let me try it out, as soon as I've moved house this weekend...