[core/input] Skip partial events
Clicking on a separator creates partial events ("instance" missing). Ignore those events, as they crash the input processor. fixes #31
This commit is contained in:
parent
90adbfbec9
commit
75f5af4866
2 changed files with 16 additions and 1 deletions
|
@ -27,6 +27,8 @@ def read_input(inp):
|
|||
inp.has_event = True
|
||||
try:
|
||||
event = json.loads(line)
|
||||
if not "instance" in event:
|
||||
continue
|
||||
inp.callback(event)
|
||||
inp.redraw()
|
||||
except ValueError:
|
||||
|
|
|
@ -47,7 +47,20 @@ class TestI3BarInput(unittest.TestCase):
|
|||
mock_input.readline.return_value = json.dumps({
|
||||
"name": None,
|
||||
"instance": None,
|
||||
"button": None,
|
||||
"button": 1,
|
||||
})
|
||||
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("sys.stdin")
|
||||
def test_ignore_partial_event(self, mock_input, mock_select):
|
||||
mock_select.return_value = (1,2,3)
|
||||
self.input.register_callback(None, button=1, cmd=self.callback)
|
||||
mock_input.readline.return_value = json.dumps({
|
||||
"button": 1,
|
||||
})
|
||||
self.input.start()
|
||||
self.assertEquals(self.input.alive(), True)
|
||||
|
|
Loading…
Reference in a new issue