[tests] Added engine and module tests

Added those two unit tests together, as they are tightly linked together
anyhow.
This commit is contained in:
Tobi-wan Kenobi 2017-03-04 13:44:51 +01:00
parent f65ab6bcae
commit 64523119af
3 changed files with 234 additions and 0 deletions

View file

@ -4,6 +4,8 @@ import mock
import shlex
import subprocess
from bumblebee.output import Widget
class MockPopen(object):
def __init__(self, module):
self._patch = mock.patch("{}.subprocess.Popen".format(module))
@ -24,4 +26,64 @@ class MockPopen(object):
def cleanup(self):
self._patch.stop()
class MockInput(object):
def __init__(self):
self._callbacks = {}
def start(self):
pass
def stop(self):
pass
def get_callback(self, uid):
return self._callbacks.get(uid, None)
def register_callback(self, obj, button, cmd):
if not obj:
return
self._callbacks[obj.id] = {
"button": button,
"command": cmd,
}
class MockOutput(object):
def start(self):
pass
def stop(self):
pass
def draw(self, widget, engine, module):
engine.stop()
def begin(self):
pass
def flush(self):
pass
def end(self):
pass
class MockEngine(object):
def __init__(self):
self.input = MockInput()
class MockWidget(Widget):
def __init__(self, text):
super(MockWidget, self).__init__(text)
self._text = text
self.module = None
self.attr_state = ["state-default"]
self.id = "none"
def state(self):
return self.attr_state
def update(self, widgets):
pass
def full_text(self):
return self._text
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4