Skip to content
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
8 changes: 3 additions & 5 deletions evdev/uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,11 @@ def _verify(self):
Verify that an uinput device exists and is readable and writable
by the current process.
"""

try:
m = os.stat(self.devnode)[stat.ST_MODE]
if not stat.S_ISCHR(m):
raise OSError
except (IndexError, OSError):
msg = '"{}" does not exist or is not a character device file ' "- verify that the uinput module is loaded"
assert stat.S_ISCHR(m)
except (IndexError, OSError, AssertionError):
msg = '"{}" does not exist or is not a character device file - verify that the uinput module is loaded'
raise UInputError(msg.format(self.devnode))

if not os.access(self.devnode, os.W_OK):
Expand Down
17 changes: 15 additions & 2 deletions tests/test_uinput.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
import os
import stat
from select import select
from unittest.mock import patch
Expand Down Expand Up @@ -119,6 +120,18 @@ def test_write(c):


@patch.object(stat, 'S_ISCHR', return_value=False)
def test_not_a_character_device(c):
with pytest.raises(UInputError):
def test_not_a_character_device(ischr_mock, c):
with pytest.raises(UInputError, match='not a character device file'):
uinput.UInput(**c)

@patch.object(stat, 'S_ISCHR', return_value=True)
@patch.object(os, 'stat', side_effect=OSError())
def test_not_a_character_device_2(stat_mock, ischr_mock, c):
with pytest.raises(UInputError, match='not a character device file'):
uinput.UInput(**c)

@patch.object(stat, 'S_ISCHR', return_value=True)
@patch.object(os, 'stat', return_value=[])
def test_not_a_character_device_3(stat_mock, ischr_mock, c):
with pytest.raises(UInputError, match='not a character device file'):
uinput.UInput(**c)
Loading