2016-12-09 11:57:13 +01:00
|
|
|
# pylint: disable=C0103,C0111,W0703,W0212
|
2016-12-04 17:45:42 +01:00
|
|
|
|
2016-12-04 08:37:01 +01:00
|
|
|
import unittest
|
|
|
|
|
2016-12-04 16:23:44 +01:00
|
|
|
from bumblebee.error import ModuleLoadError
|
2016-12-04 08:37:01 +01:00
|
|
|
from bumblebee.engine import Engine
|
2016-12-04 11:09:10 +01:00
|
|
|
from bumblebee.config import Config
|
2016-12-04 08:37:01 +01:00
|
|
|
|
2016-12-04 17:45:42 +01:00
|
|
|
from tests.util import MockOutput
|
|
|
|
|
2016-12-04 08:37:01 +01:00
|
|
|
class TestEngine(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2016-12-04 17:45:42 +01:00
|
|
|
self.engine = Engine(config=Config(), output=MockOutput())
|
2016-12-09 07:57:21 +01:00
|
|
|
self.singleWidgetModule = [{"module": "test", "name": "a"}]
|
2016-12-04 11:09:10 +01:00
|
|
|
self.testModule = "test"
|
2016-12-04 16:23:44 +01:00
|
|
|
self.invalidModule = "no-such-module"
|
2016-12-04 11:09:10 +01:00
|
|
|
self.testModuleSpec = "bumblebee.modules.{}".format(self.testModule)
|
|
|
|
self.testModules = [
|
2016-12-04 12:26:20 +01:00
|
|
|
{"module": "test", "name": "a"},
|
|
|
|
{"module": "test", "name": "b"},
|
2016-12-04 11:09:10 +01:00
|
|
|
]
|
2016-12-04 08:37:01 +01:00
|
|
|
|
|
|
|
def test_stop(self):
|
|
|
|
self.assertTrue(self.engine.running())
|
|
|
|
self.engine.stop()
|
|
|
|
self.assertFalse(self.engine.running())
|
2016-12-04 11:09:10 +01:00
|
|
|
|
|
|
|
def test_load_module(self):
|
2016-12-09 11:49:59 +01:00
|
|
|
module = self.engine._load_module(self.testModule)
|
2016-12-04 11:09:10 +01:00
|
|
|
self.assertEquals(module.__module__, self.testModuleSpec)
|
|
|
|
|
2016-12-04 16:23:44 +01:00
|
|
|
def test_load_invalid_module(self):
|
|
|
|
with self.assertRaises(ModuleLoadError):
|
2016-12-09 11:49:59 +01:00
|
|
|
self.engine._load_module(self.invalidModule)
|
2016-12-04 16:23:44 +01:00
|
|
|
|
|
|
|
def test_load_none(self):
|
|
|
|
with self.assertRaises(ModuleLoadError):
|
2016-12-09 11:49:59 +01:00
|
|
|
self.engine._load_module(None)
|
2016-12-04 16:23:44 +01:00
|
|
|
|
2016-12-04 11:09:10 +01:00
|
|
|
def test_load_modules(self):
|
|
|
|
modules = self.engine.load_modules(self.testModules)
|
|
|
|
self.assertEquals(len(modules), len(self.testModules))
|
|
|
|
self.assertEquals(
|
2016-12-04 12:26:20 +01:00
|
|
|
[module.__module__ for module in modules],
|
|
|
|
[self.testModuleSpec for module in modules]
|
2016-12-04 11:09:10 +01:00
|
|
|
)
|
|
|
|
|
2016-12-04 17:45:42 +01:00
|
|
|
def test_run(self):
|
|
|
|
self.engine.load_modules(self.singleWidgetModule)
|
|
|
|
try:
|
|
|
|
self.engine.run()
|
|
|
|
except Exception as e:
|
|
|
|
self.fail(e)
|
|
|
|
|
2016-12-04 11:09:10 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|