Anonymous avatar Anonymous committed 02d2d3b

Adding loadPlugin to the list of names exported by unittest2.
Adding the plugins-dir plugin.

Comments (0)

Files changed (3)

     unittest2.plugins.timed
     unittest2.plugins.counttests
     unittest2.plugins.logchannels
+    unittest2.plugins.pluginsdir
 
 excluded-plugins =
     foo.bar.baz
 
 [count]
 always-on = True
-enhanced = False
+enhanced = False
+
+[plugins-dir]
+# This plugin can only be enabled from a config file
+always-on = False
+plugin-path = ~/.unittest

unittest2/__init__.py

     'FunctionTestCase', 'main', 'defaultTestLoader', 'SkipTest', 'skip', 
     'skipIf', 'skipUnless', 'expectedFailure', 'TextTestResult', '__version__',
     'collector', 'setRunner', 'message', 'Plugin', 'loadedPlugins', 'addOption',
-    'addDiscoveryOption', 'loadConfig', 'getConfig'
+    'addDiscoveryOption', 'loadConfig', 'getConfig', 'loadPlugin'
 ]
 
 __version__ = '0.6.0 alpha (plugins branch)'
 
 
 from unittest2.events import (
-    Plugin, loadedPlugins, addOption, addDiscoveryOption
+    Plugin, loadedPlugins, addOption, addDiscoveryOption,
+    loadPlugin
 )
 
 from unittest2.config import loadConfig, getConfig

unittest2/plugins/pluginsdir.py

+import os
+import sys
+from unittest2 import getConfig, loadPlugin
+
+defaultPath = '~/.unittest'
+
+config = getConfig('plugins-dir')
+thePath = config.get('path', defaultPath)
+excludedPlugins = getConfig('unittest')['excluded-plugins']
+
+on = config.as_bool('always-on', default=False)
+
+def loadPlugins(thePath):
+    if not os.path.isdir(thePath):
+        return
+    sys.path.append(thePath)
+    for entry in os.listdir(thePath):
+        fullPath = os.path.join(thePath, entry)
+        if entry.lower().endswith('.py') and os.path.isfile(fullPath):
+            name = entry[:-3]
+            if name in excludedPlugins:
+                continue
+            loadPlugin(name)
+        elif (os.path.isdir(fullPath) and 
+              os.path.isfile(os.path.join(fullPath, '__init__.py'))):
+            if entry not in excludedPlugins:
+                loadPlugin(entry)
+
+if on:
+    loadPlugins(os.path.expanduser(thePath))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.