aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/plugin.py
diff options
context:
space:
mode:
authorAaron Bentley <abentley@panoramicfeedback.com>2005-03-11 21:49:42 +0000
committerAaron Bentley <abentley@panoramicfeedback.com>2005-03-11 21:49:42 +0000
commit71597577918f8d8206256293a7c985bc800a1363 (patch)
tree114799cc2b992f63c3b3bc12ed7526e9a7a145dd /libbe/plugin.py
parent6d32caa83004a2b3571754ddde5a389bac38423d (diff)
downloadbugseverywhere-71597577918f8d8206256293a7c985bc800a1363.tar.gz
Added unit testing framework
Diffstat (limited to 'libbe/plugin.py')
-rw-r--r--libbe/plugin.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/libbe/plugin.py b/libbe/plugin.py
index 2dedac4..5f0fa4d 100644
--- a/libbe/plugin.py
+++ b/libbe/plugin.py
@@ -9,7 +9,13 @@ def my_import(mod_name):
return module
def iter_plugins(prefix):
- modfiles = os.listdir(os.path.join(sys.path[0], prefix))
+ """
+ >>> "list" in [n for n,m in iter_plugins("becommands")]
+ True
+ >>> "plugin" in [n for n,m in iter_plugins("libbe")]
+ True
+ """
+ modfiles = os.listdir(os.path.join(plugin_path, prefix))
modfiles.sort()
for modfile in modfiles:
if modfile.endswith(".py") and modfile != "__init__.py":
@@ -17,9 +23,26 @@ def iter_plugins(prefix):
def get_plugin(prefix, name):
+ """
+ >>> get_plugin("becommands", "asdf") is None
+ True
+ >>> get_plugin("becommands", "list")
+ <module 'becommands.list' from '/home/abentley/be/becommands/list.pyc'>
+ """
dirprefix = '/'.join(prefix.split('.'))
- command_path = os.path.join(sys.path[0], dirprefix, name+".py")
+ command_path = os.path.join(plugin_path, dirprefix, name+".py")
if os.path.isfile(command_path):
return my_import(prefix + "." + name)
return None
-
+
+plugin_path = sys.path[0]
+while not os.path.isfile(os.path.join(plugin_path, "libbe/plugin.py")):
+ plugin_path = os.path.realpath(os.path.dirname(plugin_path))
+if plugin_path not in sys.path:
+ sys.path.append(plugin_path)
+def _test():
+ import doctest
+ doctest.testmod()
+
+if __name__ == "__main__":
+ _test()