From 75f5af4866b23628f4d90e641b461535784d33af Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sun, 11 Dec 2016 13:43:34 +0100 Subject: [PATCH] [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 --- bumblebee/input.py | 2 ++ tests/test_i3barinput.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bumblebee/input.py b/bumblebee/input.py index ba41362..7dea7d2 100644 --- a/bumblebee/input.py +++ b/bumblebee/input.py @@ -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: diff --git a/tests/test_i3barinput.py b/tests/test_i3barinput.py index e2758d6..abe972f 100644 --- a/tests/test_i3barinput.py +++ b/tests/test_i3barinput.py @@ -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)