[core/errors] Add custom exceptions

Add custom exceptions and add error handling to the engine's module
loading logic. I.e. when a non-existent module is loaded, an exception
is thrown now.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-04 16:23:44 +01:00
parent b6eb3ee8e6
commit 8855f1155b
4 changed files with 33 additions and 2 deletions

View file

@ -1,6 +1,7 @@
# pylint: disable=C0103,C0111
import unittest
from bumblebee.error import ModuleLoadError
from bumblebee.engine import Engine
from bumblebee.config import Config
@ -8,6 +9,7 @@ class TestEngine(unittest.TestCase):
def setUp(self):
self.engine = Engine(Config())
self.testModule = "test"
self.invalidModule = "no-such-module"
self.testModuleSpec = "bumblebee.modules.{}".format(self.testModule)
self.testModules = [
{"module": "test", "name": "a"},
@ -23,6 +25,14 @@ class TestEngine(unittest.TestCase):
module = self.engine.load_module(self.testModule)
self.assertEquals(module.__module__, self.testModuleSpec)
def test_load_invalid_module(self):
with self.assertRaises(ModuleLoadError):
self.engine.load_module(self.invalidModule)
def test_load_none(self):
with self.assertRaises(ModuleLoadError):
self.engine.load_module(None)
def test_load_modules(self):
modules = self.engine.load_modules(self.testModules)
self.assertEquals(len(modules), len(self.testModules))