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.pluginsdir
 excluded-plugins =
 always-on = True
-enhanced = False
+enhanced = False
+# This plugin can only be enabled from a config file
+always-on = False
+plugin-path = ~/.unittest


     '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 import (
-    Plugin, loadedPlugins, addOption, addDiscoveryOption
+    Plugin, loadedPlugins, addOption, addDiscoveryOption,
+    loadPlugin
 from unittest2.config import loadConfig, getConfig


+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, ''))):
+            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
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.