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