changeset 3:c047cd63d175 v0.2

Better handling of everything
author Walter Cruz <walter.php@gmail.com>
date Fri, 29 Feb 2008 18:57:44 -0300
parents 3cdd7f281e28
children 927dfc9d1f8a
files nose_notify/build/lib/nose_notify/nose_notify.py nose_notify/build/lib/nose_notify/run_nose.py nose_notify/dist/nose_notify-0.2dev-py2.5.egg nose_notify/nose_notify/nose_notify.py nose_notify/nose_notify/run_nose.py
diffstat 5 files changed, 128 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/nose_notify/build/lib/nose_notify/nose_notify.py	Fri Feb 29 14:54:33 2008 -0300
+++ b/nose_notify/build/lib/nose_notify/nose_notify.py	Fri Feb 29 18:57:44 2008 -0300
@@ -3,9 +3,11 @@
 
 from StringIO import StringIO
 
+import traceback
 import pygtk
 pygtk.require('2.0')
 import pynotify
+import gtk
 from new import instancemethod
 
 def writeln(self,*args):
@@ -15,25 +17,75 @@
 
 class NoseNotifyPlugin(Plugin):
 
-    enabled = True
-    score = 1000
+    enabled = False
+    score = 2
     name = "NotifyPlugin"
     
     def __init__(self):
-        self.stdout = []
+        super(NoseNotifyPlugin, self).__init__()
         self._buf = StringIO()
         self._buf.writeln = instancemethod(writeln,self._buf,StringIO)
-    
-    def configure(self, options, conf):
+
+    def addSuccess(self, test):
+        pass
+   
+    def addError(self, test, err):
         pass
 
-    def options(self, parser, env):
+    def addFailure(self, test, err):
         pass
 
     def finalize(self, result):
-        result.stream = self._buf
-        result.printSummary(0,2)
+        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")
-        n = pynotify.Notification("Tests", self._buf.getvalue())
+        
+        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()
-        return None
\ No newline at end of file
+
+    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
+        #self._buf.write(test.shortDescription() or str(test))
+        
+    def stopTest(self, test):
+        pass
+        #self._buf.write(' ')
+
+    def configure(self, options, conf):
+        if options.with_notify:
+            self.enabled = True
+
+    def options(self, parser, env):
+        Plugin.options(self, parser, env)
+        parser.add_option("--with-notify",dest='with_notify',default=False)
\ No newline at end of file
--- a/nose_notify/build/lib/nose_notify/run_nose.py	Fri Feb 29 14:54:33 2008 -0300
+++ b/nose_notify/build/lib/nose_notify/run_nose.py	Fri Feb 29 18:57:44 2008 -0300
@@ -1,5 +1,5 @@
 import unittest
 from nose.plugins.plugintest import run
-from notify_test import NotifyPlugin
+from nose_notify import NoseNotifyPlugin
 
-run(suite=unittest.TestSuite(tests=[]),plugins=[NotifyPlugin()])
\ No newline at end of file
+run(suite=unittest.TestSuite(tests=[]),plugins=[NoseNotifyPlugin()])
\ No newline at end of file
Binary file nose_notify/dist/nose_notify-0.2dev-py2.5.egg has changed
--- a/nose_notify/nose_notify/nose_notify.py	Fri Feb 29 14:54:33 2008 -0300
+++ b/nose_notify/nose_notify/nose_notify.py	Fri Feb 29 18:57:44 2008 -0300
@@ -3,9 +3,11 @@
 
 from StringIO import StringIO
 
+import traceback
 import pygtk
 pygtk.require('2.0')
 import pynotify
+import gtk
 from new import instancemethod
 
 def writeln(self,*args):
@@ -15,25 +17,75 @@
 
 class NoseNotifyPlugin(Plugin):
 
-    enabled = True
-    score = 1000
+    enabled = False
+    score = 2
     name = "NotifyPlugin"
     
     def __init__(self):
-        self.stdout = []
+        super(NoseNotifyPlugin, self).__init__()
         self._buf = StringIO()
         self._buf.writeln = instancemethod(writeln,self._buf,StringIO)
-    
-    def configure(self, options, conf):
+
+    def addSuccess(self, test):
+        pass
+   
+    def addError(self, test, err):
         pass
 
-    def options(self, parser, env):
+    def addFailure(self, test, err):
         pass
 
     def finalize(self, result):
-        result.stream = self._buf
-        result.printSummary(0,2)
+        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")
-        n = pynotify.Notification("Tests", self._buf.getvalue())
+        
+        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()
-        return None
\ No newline at end of file
+
+    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
+        #self._buf.write(test.shortDescription() or str(test))
+        
+    def stopTest(self, test):
+        pass
+        #self._buf.write(' ')
+
+    def configure(self, options, conf):
+        if options.with_notify:
+            self.enabled = True
+
+    def options(self, parser, env):
+        Plugin.options(self, parser, env)
+        parser.add_option("--with-notify",dest='with_notify',default=False)
\ No newline at end of file
--- a/nose_notify/nose_notify/run_nose.py	Fri Feb 29 14:54:33 2008 -0300
+++ b/nose_notify/nose_notify/run_nose.py	Fri Feb 29 18:57:44 2008 -0300
@@ -1,5 +1,5 @@
 import unittest
 from nose.plugins.plugintest import run
-from notify_test import NotifyPlugin
+from nose_notify import NoseNotifyPlugin
 
-run(suite=unittest.TestSuite(tests=[]),plugins=[NotifyPlugin()])
\ No newline at end of file
+run(suite=unittest.TestSuite(tests=[]),plugins=[NoseNotifyPlugin()])
\ No newline at end of file