Commits

Anonymous committed af9c8d3

Fixed initPlugins() to handle the system plugins directory correctly,
with proper testing.

Comments (0)

Files changed (2)

smart/__init__.py

     from smart import plugins
     from smart import backends
     pluginsdir = os.path.dirname(plugins.__file__)
-    entries = os.listdir(pluginsdir)
-    if os.path.isdir(PLUGINSDIR):
-        entries.extend(os.listdir(PLUGINSDIR))
     for entry in os.listdir(pluginsdir):
         if entry != "__init__.py" and entry.endswith(".py"):
             __import__("smart.plugins."+entry[:-3])
                 initpath = os.path.join(entrypath, "__init__.py")
                 if os.path.isfile(initpath):
                     __import__("smart.plugins."+entry)
+    if os.path.isdir(PLUGINSDIR):
+        for entry in os.listdir(PLUGINSDIR):
+            entrypath = os.path.join(PLUGINSDIR, entry)
+            execfile(entrypath)
     backendsdir = os.path.dirname(backends.__file__)
     for entry in os.listdir(backendsdir):
         entrypath = os.path.join(backendsdir, entry)

tests/initialization.py

+import sys
+
+from tests.mocker import MockerTestCase
+
+from smart import initPlugins
+
+
+class InitPluginsTest(MockerTestCase):
+
+    def setUp(self):
+        from smart import const
+        self.old_plugins_dir = const.PLUGINSDIR
+        self.plugins_dir = self.makeDir()
+        const.PLUGINSDIR = self.plugins_dir
+
+    def tearDown(self):
+        from smart import const
+        const.PLUGINSDIR = self.old_plugins_dir
+
+    def test_plugins_dir_is_used(self):
+        self.makeFile("import sys; sys.test_worked = True",
+                      basename="plugin.py", dirname=self.plugins_dir)
+        initPlugins()
+        self.assertEquals(getattr(sys, "test_worked", False), True)
+        del sys.test_worked
+