File tree 2 files changed +18
-7
lines changed
2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -266,13 +266,11 @@ def _verify(self):
266
266
Verify that an uinput device exists and is readable and writable
267
267
by the current process.
268
268
"""
269
-
270
269
try :
271
270
m = os .stat (self .devnode )[stat .ST_MODE ]
272
- if not stat .S_ISCHR (m ):
273
- raise OSError
274
- except (IndexError , OSError ):
275
- msg = '"{}" does not exist or is not a character device file ' "- verify that the uinput module is loaded"
271
+ assert stat .S_ISCHR (m )
272
+ except (IndexError , OSError , AssertionError ):
273
+ msg = '"{}" does not exist or is not a character device file - verify that the uinput module is loaded'
276
274
raise UInputError (msg .format (self .devnode ))
277
275
278
276
if not os .access (self .devnode , os .W_OK ):
Original file line number Diff line number Diff line change 1
1
# encoding: utf-8
2
+ import os
2
3
import stat
3
4
from select import select
4
5
from unittest .mock import patch
@@ -119,6 +120,18 @@ def test_write(c):
119
120
120
121
121
122
@patch .object (stat , 'S_ISCHR' , return_value = False )
122
- def test_not_a_character_device (c ):
123
- with pytest .raises (UInputError ):
123
+ def test_not_a_character_device (ischr_mock , c ):
124
+ with pytest .raises (UInputError , match = 'not a character device file' ):
125
+ uinput .UInput (** c )
126
+
127
+ @patch .object (stat , 'S_ISCHR' , return_value = True )
128
+ @patch .object (os , 'stat' , side_effect = OSError ())
129
+ def test_not_a_character_device_2 (stat_mock , ischr_mock , c ):
130
+ with pytest .raises (UInputError , match = 'not a character device file' ):
131
+ uinput .UInput (** c )
132
+
133
+ @patch .object (stat , 'S_ISCHR' , return_value = True )
134
+ @patch .object (os , 'stat' , return_value = [])
135
+ def test_not_a_character_device_3 (stat_mock , ischr_mock , c ):
136
+ with pytest .raises (UInputError , match = 'not a character device file' ):
124
137
uinput .UInput (** c )
You can’t perform that action at this time.
0 commit comments