Mercurial > nose_notify
view nose_notify/nose_notify/nose_notify.py @ 4:927dfc9d1f8a v0.2 tip
Adding license and making the command line switch work
author | Walter Cruz <walter.php@gmail.com> |
---|---|
date | Mon, 03 Mar 2008 11:28:54 -0300 |
parents | c047cd63d175 |
children |
line wrap: on
line source
# Copyright (C) 2008 by Walter Cruz # walter.php@gmail.com # # 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; either version 2 of the License, or # (at your option) any later version. # # 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., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Public License can be found at http://www.gnu.org/copyleft/gpl.html import sys from nose.plugins.base import Plugin from StringIO import StringIO import traceback import pygtk pygtk.require('2.0') import pynotify import gtk from new import instancemethod def writeln(self,*args): for i in args: self.write(i) self.write("\n") class NoseNotifyPlugin(Plugin): enabled = False score = 2 name = "NotifyPlugin" def __init__(self): super(NoseNotifyPlugin, self).__init__() self._buf = StringIO() self._buf.writeln = instancemethod(writeln,self._buf,StringIO) def addSuccess(self, test): pass def addError(self, test, err): pass def addFailure(self, test, err): pass def finalize(self, result): self._buf.write("Ran %d test%s" %(result.testsRun, result.testsRun != 1 and "s" or "")) self._buf.writeln() if not result.wasSuccessful(): self._buf.write('FAILED ( failures=%d errors=%d)'%(len(result.failures),len(result.errors))) else: self._buf.write('OK') pynotify.init("Basics") message = 'messagebox_info' if not result.wasSuccessful(): if result.failures > 0: message = 'messagebox_warning' if result.errors > 0: message = 'messagebox_critical' n = pynotify.Notification("Tests", self._buf.getvalue(),message) n.set_urgency('critical') icon = gtk.StatusIcon() icon.set_from_icon_name('dialog-error') n.attach_to_status_icon(icon) else: n = pynotify.Notification("Tests", self._buf.getvalue(),message) n.show() def formatErr(self, err): exctype, value, tb = err return ''.join(traceback.format_exception(exctype, value, tb)) def setOutputStream(self, stream): self.stream = self._buf return None def startContext(self, ctx): pass def stopContext(self, ctx): pass def startTest(self, test): pass def stopTest(self, test): pass def configure(self, options, conf): if options.with_notify: self.enabled = True return def options(self, parser, env): Plugin.options(self, parser, env) parser.add_option("--with-notify", action='store_true', dest='with_notify', default = False, help= 'Use gnome notify' )