Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update input device checks #81

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions ovos_utils/device_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self) -> None:
if not find_executable("libinput") and not find_executable("xinput"):
LOG.warning("Could not find libinput, input device detection will be inaccurate")

# ToDo: add support for discovring the input device based of a connected
# ToDo: add support for discovering the input device based of a connected
# monitors, currently linux only supports input listing directly from the
# system
def _build_linput_devices_list(self):
Expand Down Expand Up @@ -138,8 +138,3 @@ def can_use_touch_mouse():

def can_use_keyboard():
return InputDeviceHelper().can_use_keyboard()


if __name__ == "__main__":

can_use_touch_mouse()
63 changes: 63 additions & 0 deletions test/unittests/test_device_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import unittest
from unittest import mock
from unittest.mock import Mock


class TestDeviceInput(unittest.TestCase):
def test_input_device_helper(self):
# TODO
pass

@mock.patch('distutils.spawn.find_executable')
def test_can_use_touch_mouse(self, find_exec):
from ovos_utils.device_input import InputDeviceHelper
find_exec.return_value = True
dev_input = InputDeviceHelper()

dev_input._build_linput_devices_list = Mock()
dev_input._build_xinput_devices_list = Mock()

dev_input.libinput_devices_list = [{'Device': 'Mock',
'Capabilities': ['mouse']},
{'Device': "Mock 1",
'Capabilities': ['touch']}
]
self.assertTrue(dev_input.can_use_touch_mouse())

dev_input.libinput_devices_list.pop()
self.assertTrue(dev_input.can_use_touch_mouse())
dev_input.libinput_devices_list.pop()
self.assertFalse(dev_input.can_use_touch_mouse())
dev_input.xinput_devices_list = [{'Device': 'xinput',
'Capabilities': ['tablet']
}]
self.assertTrue(dev_input.can_use_touch_mouse())
dev_input.xinput_devices_list.pop()
self.assertFalse(dev_input.can_use_touch_mouse())

@mock.patch('distutils.spawn.find_executable')
def test_can_use_keyboard(self, find_exec):
from ovos_utils.device_input import InputDeviceHelper
find_exec.return_value = True
dev_input = InputDeviceHelper()

dev_input._build_linput_devices_list = Mock()
dev_input._build_xinput_devices_list = Mock()

dev_input.libinput_devices_list = [{'Device': 'Mock',
'Capabilities': ['keyboard']},
{'Device': "Mock 1",
'Capabilities': ['touch']}
]
self.assertTrue(dev_input.can_use_keyboard())

dev_input.libinput_devices_list.pop()
self.assertTrue(dev_input.can_use_keyboard())
dev_input.libinput_devices_list.pop()
self.assertFalse(dev_input.can_use_keyboard())
dev_input.xinput_devices_list = [{'Device': 'xinput',
'Capabilities': ['keyboard']
}]
self.assertTrue(dev_input.can_use_keyboard())
dev_input.xinput_devices_list.pop()
self.assertFalse(dev_input.can_use_keyboard())