Factor storage loader into its own module
Signed-off-by: martin f. krafft <madduck@madduck.net>
diff --git a/reclass/__init__.py b/reclass/__init__.py
index 2a794e8..8bb06e1 100644
--- a/reclass/__init__.py
+++ b/reclass/__init__.py
@@ -8,7 +8,7 @@
#
from output import OutputLoader
-from storage import StorageBackendLoader
+from storage.loader import StorageBackendLoader
def get_storage(storage_type, nodes_uri, classes_uri, class_mappings):
storage_class = StorageBackendLoader(storage_type).load()
diff --git a/reclass/storage/__init__.py b/reclass/storage/__init__.py
index 8dfba0e..754c223 100644
--- a/reclass/storage/__init__.py
+++ b/reclass/storage/__init__.py
@@ -169,18 +169,5 @@
}
-class StorageBackendLoader(object):
- def __init__(self, storage_type):
- self._name = 'reclass.storage.' + storage_type
- try:
- self._module = __import__(self._name, globals(), locals(), self._name)
- except ImportError:
- raise NotImplementedError
- def load(self, attr='ExternalNodeStorage'):
- klass = getattr(self._module, attr, None)
- if klass is None:
- raise AttributeError, \
- 'Storage backend class {0} does not export "{1}"'.format(self._name, klass)
- return klass
diff --git a/reclass/storage/loader.py b/reclass/storage/loader.py
new file mode 100644
index 0000000..399e7fd
--- /dev/null
+++ b/reclass/storage/loader.py
@@ -0,0 +1,25 @@
+#
+# -*- coding: utf-8 -*-
+#
+# This file is part of reclass (http://github.com/madduck/reclass)
+#
+# Copyright © 2007–14 martin f. krafft <madduck@madduck.net>
+# Released under the terms of the Artistic Licence 2.0
+#
+
+class StorageBackendLoader(object):
+
+ def __init__(self, storage_name):
+ self._name = 'reclass.storage.' + storage_name
+ try:
+ self._module = __import__(self._name, globals(), locals(), self._name)
+ except ImportError:
+ raise NotImplementedError
+
+ def load(self, klassname='ExternalNodeStorage'):
+ klass = getattr(self._module, klassname, None)
+ if klass is None:
+ raise AttributeError('Storage backend class {0} does not export '
+ '"{1}"'.format(self._name, klassname))
+
+ return klass
diff --git a/reclass/storage/tests/test_loader.py b/reclass/storage/tests/test_loader.py
new file mode 100644
index 0000000..6bef87f
--- /dev/null
+++ b/reclass/storage/tests/test_loader.py
@@ -0,0 +1,21 @@
+#
+# -*- coding: utf-8 -*-
+#
+# This file is part of reclass (http://github.com/madduck/reclass)
+#
+# Copyright © 2007–14 martin f. krafft <madduck@madduck.net>
+# Released under the terms of the Artistic Licence 2.0
+#
+from reclass.storage.loader import StorageBackendLoader
+
+import unittest
+
+class TestLoader(unittest.TestCase):
+
+ def test_load(self):
+ loader = StorageBackendLoader('yaml_fs')
+ from reclass.storage.yaml_fs import ExternalNodeStorage as YamlFs
+ self.assertEqual(loader.load(), YamlFs)
+
+if __name__ == '__main__':
+ unittest.main()