Skip to content

Commit

Permalink
Raise exception if handler.list() type doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
BJ Dierkes committed Jun 11, 2012
1 parent f0ab902 commit d16ade3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cement2/cement2/core/foundation.py
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/cement2/cement2/core/handler.py
Expand Up @@ -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__':
Expand Down
8 changes: 8 additions & 0 deletions src/cement2/tests/core/controller_tests.py
Expand Up @@ -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',],
Expand Down
12 changes: 12 additions & 0 deletions src/cement2/tests/core/handler_tests.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d16ade3

Please sign in to comment.