2016-12-04 18:10:04 +01:00
|
|
|
# pylint: disable=C0103,C0111,W0613
|
2016-12-04 12:53:18 +01:00
|
|
|
|
2016-12-10 19:08:29 +01:00
|
|
|
import json
|
2016-12-09 22:28:04 +01:00
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
|
2016-12-04 17:45:42 +01:00
|
|
|
from bumblebee.output import Widget
|
|
|
|
|
|
|
|
def assertWidgetAttributes(test, widget):
|
|
|
|
test.assertTrue(isinstance(widget, Widget))
|
|
|
|
test.assertTrue(hasattr(widget, "full_text"))
|
|
|
|
|
2016-12-09 22:28:04 +01:00
|
|
|
def assertPopen(output, cmd):
|
|
|
|
res = shlex.split(cmd)
|
2016-12-10 15:36:18 +01:00
|
|
|
output.assert_any_call(res,
|
2016-12-09 22:28:04 +01:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT
|
|
|
|
)
|
|
|
|
|
2016-12-10 19:08:29 +01:00
|
|
|
def assertStateContains(test, module, state):
|
|
|
|
for widget in module.widgets():
|
|
|
|
widget.link_module(module)
|
|
|
|
module.update(module.widgets())
|
|
|
|
test.assertTrue(state in module.widgets()[0].state())
|
|
|
|
|
2016-12-11 08:01:16 +01:00
|
|
|
def assertMouseEvent(mock_input, mock_output, mock_select, engine, module, button, cmd, instance_id=None):
|
2016-12-10 19:08:29 +01:00
|
|
|
mock_input.readline.return_value = json.dumps({
|
2016-12-11 08:01:16 +01:00
|
|
|
"name": module.id if module else "test",
|
2016-12-10 19:08:29 +01:00
|
|
|
"button": button,
|
2016-12-11 08:01:16 +01:00
|
|
|
"instance": instance_id
|
2016-12-10 19:08:29 +01:00
|
|
|
})
|
2016-12-11 08:01:16 +01:00
|
|
|
mock_select.return_value = (1, 2, 3)
|
2016-12-10 19:08:29 +01:00
|
|
|
engine.input.start()
|
|
|
|
engine.input.stop()
|
|
|
|
mock_input.readline.assert_any_call()
|
2016-12-11 08:01:16 +01:00
|
|
|
if cmd:
|
|
|
|
assertPopen(mock_output, cmd)
|
2016-12-10 19:08:29 +01:00
|
|
|
|
2016-12-09 19:29:16 +01:00
|
|
|
class MockInput(object):
|
2016-12-15 19:41:50 +01:00
|
|
|
def __init__(self):
|
|
|
|
self._callbacks = {}
|
2016-12-09 19:29:16 +01:00
|
|
|
def start(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
2016-12-15 19:41:50 +01:00
|
|
|
def get_callback(self, uid):
|
|
|
|
return self._callbacks.get(uid, None)
|
|
|
|
|
2016-12-09 19:29:16 +01:00
|
|
|
def register_callback(self, obj, button, cmd):
|
2016-12-15 19:41:50 +01:00
|
|
|
if not obj:
|
|
|
|
return
|
|
|
|
self._callbacks[obj.id] = {
|
|
|
|
"button": button,
|
|
|
|
"command": cmd,
|
|
|
|
}
|
2016-12-09 19:29:16 +01:00
|
|
|
|
2016-12-09 07:27:01 +01:00
|
|
|
class MockEngine(object):
|
2016-12-09 19:29:16 +01:00
|
|
|
def __init__(self):
|
|
|
|
self.input = MockInput()
|
2016-12-09 07:27:01 +01:00
|
|
|
|
2016-12-10 07:47:24 +01:00
|
|
|
class MockConfig(object):
|
2016-12-10 08:09:13 +01:00
|
|
|
def __init__(self):
|
|
|
|
self._data = {}
|
|
|
|
|
2016-12-10 07:47:24 +01:00
|
|
|
def get(self, name, default):
|
2016-12-10 08:09:13 +01:00
|
|
|
if name in self._data:
|
|
|
|
return self._data[name]
|
2016-12-10 07:47:24 +01:00
|
|
|
return default
|
|
|
|
|
2016-12-10 08:09:13 +01:00
|
|
|
def set(self, name, value):
|
|
|
|
self._data[name] = value
|
|
|
|
|
2016-12-04 17:45:42 +01:00
|
|
|
class MockOutput(object):
|
|
|
|
def start(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
pass
|
|
|
|
|
2016-12-09 19:29:16 +01:00
|
|
|
def draw(self, widget, engine, module):
|
2016-12-04 17:45:42 +01:00
|
|
|
engine.stop()
|
|
|
|
|
2016-12-08 12:44:52 +01:00
|
|
|
def begin(self):
|
|
|
|
pass
|
|
|
|
|
2016-12-04 17:45:42 +01:00
|
|
|
def flush(self):
|
|
|
|
pass
|
|
|
|
|
2016-12-08 12:44:52 +01:00
|
|
|
def end(self):
|
|
|
|
pass
|
|
|
|
|
2016-12-09 19:29:16 +01:00
|
|
|
class MockModule(object):
|
|
|
|
def __init__(self, engine=None, config=None):
|
|
|
|
self.id = None
|
|
|
|
|
2016-12-09 13:32:22 +01:00
|
|
|
class MockWidget(Widget):
|
2016-12-04 12:53:18 +01:00
|
|
|
def __init__(self, text):
|
2016-12-09 16:33:29 +01:00
|
|
|
super(MockWidget, self).__init__(text)
|
2016-12-04 12:53:18 +01:00
|
|
|
self._text = text
|
2016-12-09 11:49:59 +01:00
|
|
|
self.module = None
|
2016-12-10 11:25:02 +01:00
|
|
|
self.attr_state = ["state-default"]
|
2016-12-09 19:29:16 +01:00
|
|
|
self.id = "none"
|
2016-12-09 13:32:22 +01:00
|
|
|
|
|
|
|
def state(self):
|
|
|
|
return self.attr_state
|
2016-12-04 12:53:18 +01:00
|
|
|
|
2016-12-08 08:44:54 +01:00
|
|
|
def update(self, widgets):
|
|
|
|
pass
|
|
|
|
|
2016-12-04 17:45:42 +01:00
|
|
|
def full_text(self):
|
2016-12-04 12:53:18 +01:00
|
|
|
return self._text
|
|
|
|
|
2016-12-08 11:31:20 +01:00
|
|
|
class MockTheme(object):
|
|
|
|
def __init__(self):
|
2016-12-09 11:42:02 +01:00
|
|
|
self.attr_prefix = None
|
|
|
|
self.attr_suffix = None
|
|
|
|
self.attr_fg = None
|
|
|
|
self.attr_bg = None
|
2016-12-09 12:55:16 +01:00
|
|
|
self.attr_separator = None
|
|
|
|
self.attr_separator_block_width = 0
|
2016-12-09 08:58:45 +01:00
|
|
|
|
2016-12-09 13:06:08 +01:00
|
|
|
def padding(self, widget):
|
|
|
|
return ""
|
|
|
|
|
2016-12-09 12:28:39 +01:00
|
|
|
def reset(self):
|
|
|
|
pass
|
|
|
|
|
2016-12-09 12:55:16 +01:00
|
|
|
def separator_block_width(self, widget):
|
|
|
|
return self.attr_separator_block_width
|
|
|
|
|
|
|
|
def separator(self, widget):
|
|
|
|
return self.attr_separator
|
|
|
|
|
2016-12-09 13:06:08 +01:00
|
|
|
def prefix(self, widget, default=None):
|
2016-12-09 11:42:02 +01:00
|
|
|
return self.attr_prefix
|
2016-12-08 11:31:20 +01:00
|
|
|
|
2016-12-09 13:06:08 +01:00
|
|
|
def suffix(self, widget, default=None):
|
2016-12-09 11:42:02 +01:00
|
|
|
return self.attr_suffix
|
2016-12-08 11:31:20 +01:00
|
|
|
|
2016-12-09 08:58:45 +01:00
|
|
|
def fg(self, widget):
|
2016-12-09 11:42:02 +01:00
|
|
|
return self.attr_fg
|
2016-12-09 08:58:45 +01:00
|
|
|
|
|
|
|
def bg(self, widget):
|
2016-12-09 11:42:02 +01:00
|
|
|
return self.attr_bg
|
2016-12-09 08:58:45 +01:00
|
|
|
|
2016-12-04 12:53:18 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|