[core/input] Move from select to epoll
Use epoll instead of select in order to be able to use level-triggered semantics and not get stuck on the first event.
This commit is contained in:
parent
31f9154be2
commit
f6be25bc73
11 changed files with 67 additions and 48 deletions
|
@ -7,7 +7,7 @@ import mock
|
|||
|
||||
import bumblebee.input
|
||||
from bumblebee.input import I3BarInput
|
||||
from tests.util import MockWidget, MockModule, assertPopen, assertMouseEvent
|
||||
from tests.util import MockWidget, MockModule, assertPopen, assertMouseEvent, MockEpoll
|
||||
|
||||
class TestI3BarInput(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -21,29 +21,30 @@ class TestI3BarInput(unittest.TestCase):
|
|||
def callback(self, event):
|
||||
self._called += 1
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_basic_read_event(self, mock_input, mock_select):
|
||||
mock_select.return_value = (1,2,3)
|
||||
mock_input.readline.return_value = ""
|
||||
mock_input.readline.return_value = "somedata"
|
||||
mock_input.fileno.return_value = 1
|
||||
mock_select.return_value = MockEpoll()
|
||||
self.input.start()
|
||||
self.input.stop()
|
||||
mock_input.readline.assert_any_call()
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_ignore_invalid_data(self, mock_input, mock_select):
|
||||
mock_select.return_value = (1,2,3)
|
||||
mock_select.return_value = MockEpoll()
|
||||
mock_input.readline.return_value = "garbage"
|
||||
self.input.start()
|
||||
self.assertEquals(self.input.alive(), True)
|
||||
self.assertEquals(self.input.stop(), True)
|
||||
mock_input.readline.assert_any_call()
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_ignore_invalid_event(self, mock_input, mock_select):
|
||||
mock_select.return_value = (1,2,3)
|
||||
mock_select.return_value = MockEpoll()
|
||||
mock_input.readline.return_value = json.dumps({
|
||||
"name": None,
|
||||
"instance": None,
|
||||
|
@ -54,10 +55,10 @@ class TestI3BarInput(unittest.TestCase):
|
|||
self.assertEquals(self.input.stop(), True)
|
||||
mock_input.readline.assert_any_call()
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_ignore_partial_event(self, mock_input, mock_select):
|
||||
mock_select.return_value = (1,2,3)
|
||||
mock_select.return_value = MockEpoll()
|
||||
self.input.register_callback(None, button=1, cmd=self.callback)
|
||||
mock_input.readline.return_value = json.dumps({
|
||||
"button": 1,
|
||||
|
@ -67,7 +68,7 @@ class TestI3BarInput(unittest.TestCase):
|
|||
self.assertEquals(self.input.stop(), True)
|
||||
mock_input.readline.assert_any_call()
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_global_callback(self, mock_input, mock_select):
|
||||
self.input.register_callback(None, button=1, cmd=self.callback)
|
||||
|
@ -75,7 +76,7 @@ class TestI3BarInput(unittest.TestCase):
|
|||
bumblebee.input.LEFT_MOUSE, None, "someinstance")
|
||||
self.assertTrue(self._called > 0)
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_remove_global_callback(self, mock_input, mock_select):
|
||||
self.input.register_callback(None, button=1, cmd=self.callback)
|
||||
|
@ -84,7 +85,7 @@ class TestI3BarInput(unittest.TestCase):
|
|||
bumblebee.input.LEFT_MOUSE, None, "someinstance")
|
||||
self.assertTrue(self._called == 0)
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_global_callback_button_missmatch(self, mock_input, mock_select):
|
||||
self.input.register_callback(self.anyModule, button=1, cmd=self.callback)
|
||||
|
@ -92,7 +93,7 @@ class TestI3BarInput(unittest.TestCase):
|
|||
bumblebee.input.RIGHT_MOUSE, None, "someinstance")
|
||||
self.assertTrue(self._called == 0)
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_module_callback(self, mock_input, mock_select):
|
||||
self.input.register_callback(self.anyModule, button=1, cmd=self.callback)
|
||||
|
@ -100,7 +101,7 @@ class TestI3BarInput(unittest.TestCase):
|
|||
bumblebee.input.LEFT_MOUSE, None)
|
||||
self.assertTrue(self._called > 0)
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_remove_module_callback(self, mock_input, mock_select):
|
||||
self.input.register_callback(self.anyModule, button=1, cmd=self.callback)
|
||||
|
@ -109,7 +110,7 @@ class TestI3BarInput(unittest.TestCase):
|
|||
bumblebee.input.LEFT_MOUSE, None, self.anyWidget.id)
|
||||
self.assertTrue(self._called == 0)
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_widget_callback(self, mock_input, mock_select):
|
||||
self.input.register_callback(self.anyWidget, button=1, cmd=self.callback)
|
||||
|
@ -117,7 +118,7 @@ class TestI3BarInput(unittest.TestCase):
|
|||
bumblebee.input.LEFT_MOUSE, None, self.anyWidget.id)
|
||||
self.assertTrue(self._called > 0)
|
||||
|
||||
@mock.patch("select.select")
|
||||
@mock.patch("select.epoll")
|
||||
@mock.patch("subprocess.Popen")
|
||||
@mock.patch("sys.stdin")
|
||||
def test_widget_cmd_callback(self, mock_input, mock_output, mock_select):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue