File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -266,13 +266,11 @@ def _verify(self):
266266 Verify that an uinput device exists and is readable and writable
267267 by the current process.
268268 """
269-
270269 try :
271270 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'
276274 raise UInputError (msg .format (self .devnode ))
277275
278276 if not os .access (self .devnode , os .W_OK ):
Original file line number Diff line number Diff line change 11# encoding: utf-8
2+ import os
23import stat
34from select import select
45from unittest .mock import patch
@@ -119,6 +120,18 @@ def test_write(c):
119120
120121
121122@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' ):
124137 uinput .UInput (** c )
You can’t perform that action at this time.
0 commit comments