Permalink
Browse files

Added application icon to Growl notifications.

- Added resource image files for successful and failing
  test results.
- Added an extra conditional--if more errors caused tests
  to fail than actual failures, display a yellow icon
  and change wording slightly.
- Changed code to be more PEP8-compliant. Namely, no line
  exceeds 80 chars in width now.
- Added .gitignore to prevent compiled Python source from
  being committed.
  • Loading branch information...
1 parent 2d542aa commit ade254f71e8fb88d2072244ff6ec841e62ae5708 @modocache modocache committed Feb 7, 2012
View
@@ -0,0 +1,3 @@
+.DS_Store
+*.pyc
+*.pyo
No changes.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,4 +1,4 @@
-from setuptools import setup
+from setuptools import setup, find_packages
setup(
name='sneazr',
@@ -15,6 +15,8 @@
'nose',
'py-Growl',
],
+ packages=find_packages(),
+ include_package_data=True,
entry_points = {
'nose.plugins.0.10': ['sneazr = sneaze:Sneazr']
}
View
@@ -1,21 +1,77 @@
from nose.plugins.base import Plugin
-from Growl import GrowlNotifier, GROWL_NOTIFICATIONS_DEFAULT
+from Growl import GrowlNotifier, GROWL_NOTIFICATIONS_DEFAULT, Image
+from pkg_resources import resource_filename
+
class Sneazr(Plugin):
+ '''
+ A Nose plugin which displays Growl notifications
+ indicating the number of (un)successful tests.
+ '''
name = 'sneazr'
-
+
def __init__(self):
- Plugin.__init__(self)
- self.notifier = GrowlNotifier(applicationName='Sneazr', notifications=GROWL_NOTIFICATIONS_DEFAULT)
+ '''Registers a Growl notifier.'''
+ super(Sneazr, self).__init__()
+ # Store resource path to icons in dict.
+ self.icon_paths = {}
+ for status in ['pass', 'error', 'fail']:
+ self.icon_paths[status] = resource_filename(
+ 'resources', 'logo_%s.png' % status
+ )
+
+ app_icon = Image.imageFromPath(
+ resource_filename('resources', 'logo.png')
+ )
+ self.notifier = GrowlNotifier(
+ applicationName='Sneazr',
+ notifications=GROWL_NOTIFICATIONS_DEFAULT,
+ applicationIcon=app_icon
+ )
self.notifier.register()
-
+
+
def finalize(self, result=None):
-
+ '''
+ Checks results of nosetests and prepares
+ notification body.
+ '''
if result.wasSuccessful():
- self.__notify('Success!', 'All tests passed successfully.')
+ self.__notify(
+ 'Success!',
+ 'All tests passed successfully.',
+ self.icon_paths['pass']
+ )
+ elif len(result.errors) > len(result.failures):
+ self.__notify(
+ 'Failure!',
+ 'Failed with %s errors and %s failures.' % (
+ len(result.errors), len(result.failures)
+ ),
+ self.icon_paths['error']
+ )
+ else:
+ self.__notify(
+ 'Failure!',
+ 'Failed with %s failures and %s errors' % (
+ len(result.failures), len(result.errors)
+ ),
+ self.icon_paths['fail']
+ )
+
+
+ def __notify(self, title, message, icon_path=None):
+ '''
+ Sends a Growl notification with the
+ given parameters.
+ '''
+ if icon_path is not None:
+ icon = Image.imageFromPath(icon_path)
else:
- self.__notify('Failure!', 'Failed with %s failures and %s errors' % (len(result.failures), len(result.errors)))
-
-
- def __notify(self, title, message):
- self.notifier.notify(GROWL_NOTIFICATIONS_DEFAULT[0], title, message)
+ icon = None
+ self.notifier.notify(
+ GROWL_NOTIFICATIONS_DEFAULT[0],
+ title,
+ message,
+ icon=icon
+ )

0 comments on commit ade254f

Please sign in to comment.