2016-12-10 07:47:24 +01:00
|
|
|
# pylint: disable=C0103,C0111
|
|
|
|
|
|
|
|
import json
|
|
|
|
import unittest
|
|
|
|
import mock
|
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
from bumblebee.input import I3BarInput
|
|
|
|
from bumblebee.modules.cmus import Module
|
2016-12-17 07:43:38 +01:00
|
|
|
from tests.util import MockEngine, MockConfig, assertPopen, MockEpoll
|
2016-12-10 07:47:24 +01:00
|
|
|
|
|
|
|
class TestCmusModule(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.engine = MockEngine()
|
2016-12-10 08:37:04 +01:00
|
|
|
self.engine.input = I3BarInput()
|
|
|
|
self.engine.input.need_event = True
|
2016-12-10 07:47:24 +01:00
|
|
|
self.module = Module(engine=self.engine, config={"config": MockConfig()})
|
|
|
|
|
|
|
|
@mock.patch("subprocess.Popen")
|
|
|
|
def test_read_song(self, mock_output):
|
|
|
|
rv = mock.Mock()
|
|
|
|
rv.configure_mock(**{
|
|
|
|
"communicate.return_value": ("out", None)
|
|
|
|
})
|
|
|
|
mock_output.return_value = rv
|
|
|
|
self.module.update(self.module.widgets())
|
|
|
|
assertPopen(mock_output, "cmus-remote -Q")
|
|
|
|
|
|
|
|
def test_widgets(self):
|
|
|
|
self.assertTrue(len(self.module.widgets()), 5)
|
|
|
|
|
2016-12-17 07:43:38 +01:00
|
|
|
@mock.patch("select.epoll")
|
2016-12-10 08:37:04 +01:00
|
|
|
@mock.patch("subprocess.Popen")
|
|
|
|
@mock.patch("sys.stdin")
|
2016-12-10 13:45:54 +01:00
|
|
|
def test_interaction(self, mock_input, mock_output, mock_select):
|
2016-12-10 08:37:04 +01:00
|
|
|
events = [
|
|
|
|
{"widget": "cmus.shuffle", "action": "cmus-remote -S"},
|
|
|
|
{"widget": "cmus.repeat", "action": "cmus-remote -R"},
|
|
|
|
{"widget": "cmus.next", "action": "cmus-remote -n"},
|
|
|
|
{"widget": "cmus.prev", "action": "cmus-remote -r"},
|
|
|
|
{"widget": "cmus.main", "action": "cmus-remote -u"},
|
|
|
|
]
|
|
|
|
|
2016-12-17 07:43:38 +01:00
|
|
|
mock_input.fileno.return_value = 1
|
|
|
|
mock_select.return_value = MockEpoll()
|
2016-12-10 13:45:54 +01:00
|
|
|
|
2016-12-10 08:37:04 +01:00
|
|
|
for event in events:
|
|
|
|
mock_input.readline.return_value = json.dumps({
|
|
|
|
"name": self.module.id,
|
|
|
|
"button": bumblebee.input.LEFT_MOUSE,
|
|
|
|
"instance": self.module.widget(event["widget"]).id
|
|
|
|
})
|
|
|
|
self.engine.input.start()
|
|
|
|
self.engine.input.stop()
|
|
|
|
mock_input.readline.assert_any_call()
|
|
|
|
assertPopen(mock_output, event["action"])
|
|
|
|
|
2016-12-10 07:47:24 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|