Permalink
Browse files

Raise exception if handler.list() type doesn't exist

  • Loading branch information...
1 parent f0ab902 commit d16ade326f019ae64a3860e5292bf9d7943690dc BJ Dierkes committed Jun 11, 2012
@@ -690,6 +690,10 @@ def _setup_controllers(self):
self.controller = self._resolve_handler('controller',
self._meta.base_controller)
self._meta.base_controller = self.controller
+ elif self._meta.base_controller is None:
+ if handler.registered('controller', 'base'):
+ self.controller = self._resolve_handler('controller', 'base')
+ self._meta.base_controller = self.controller
# Trump all with whats passed at the command line, and pop off the arg
if len(self.argv) > 0:
@@ -106,6 +106,10 @@ def list(handler_type):
The type of handler (i.e. 'output')
"""
+ if handler_type not in backend.handlers:
+ raise exc.CementRuntimeError("handler type '%s' does not exist!" % \
+ handler_type)
+
res = []
for label in backend.handlers[handler_type]:
if label == '__interface__':
@@ -241,6 +241,14 @@ def test_base_controller(self):
self.app.setup()
self.app.run()
+ def test_base_controller_by_name(self):
+ self.app = _t.prep(
+ argv=['my-command'],
+ base_controller=None
+ )
+ handler.register(TestBaseController)
+ self.app.setup()
+
def test_stacked_controller(self):
app = _t.prep(
argv=['my-stacked-command',],
@@ -5,6 +5,7 @@
from cement2.core import exc, backend, handler, handler, output, meta
from cement2.core import interface
from cement2 import test_helper as _t
+from cement2.lib.ext_configparser import ConfigParserConfigHandler
class BogusOutputHandler(meta.MetaMixin):
class Meta:
@@ -109,6 +110,17 @@ def test_handler_defined(self):
# and check for bogus one too
eq_(handler.defined('bogus'), False)
+ def test_handler_list(self):
+ self.app.setup()
+ handler_list = handler.list('config')
+ res = ConfigParserConfigHandler in handler_list
+ ok_(res)
+
+ @raises(exc.CementRuntimeError)
+ def test_handler_list_bogus_type(self):
+ self.app.setup()
+ handler_list = handler.list('bogus')
+
def is_defined(handler_type):
eq_(handler.defined(handler_type), True)

0 comments on commit d16ade3

Please sign in to comment.