@@ -161,13 +161,16 @@ def test_event_source_registration(self):
161161 source_name = "PythonTestEventSource"
162162
163163 handle = _winapi .RegisterEventSource (None , source_name )
164+ self .addCleanup (_winapi .DeregisterEventSource , handle )
164165 self .assertNotEqual (handle , _winapi .INVALID_HANDLE_VALUE )
165166
166- with self .assertRaisesRegex (OSError , '[WinError 87]' ) :
167+ with self .assertRaises (OSError ) as cm :
167168 _winapi .RegisterEventSource (None , "" )
169+ self .assertEqual (cm .exception .winerror , 87 )
168170
169- with self .assertRaisesRegex (OSError , '[WinError 6]' ) :
171+ with self .assertRaises (OSError ) as cm :
170172 _winapi .DeregisterEventSource (_winapi .INVALID_HANDLE_VALUE )
173+ self .assertEqual (cm .exception .winerror , 6 )
171174
172175 def test_report_event (self ):
173176 source_name = "PythonTestEventSource"
@@ -176,15 +179,15 @@ def test_report_event(self):
176179 self .assertNotEqual (handle , _winapi .INVALID_HANDLE_VALUE )
177180 self .addCleanup (_winapi .DeregisterEventSource , handle )
178181
179- # Test with strings and raw data
180- test_strings = ["Test message 1" , "Test message 2" ]
181- test_data = b"test raw data"
182182 _winapi .ReportEvent (handle , _winapi .EVENTLOG_SUCCESS , 1 , 1002 ,
183- test_strings , test_data )
183+ "Test message 1" )
184+
185+ with self .assertRaises (TypeError ):
186+ _winapi .ReportEvent (handle , _winapi .EVENTLOG_SUCCESS , 1 , 1002 , 42 )
184187
185- # Test with empty strings list
186- _winapi .ReportEvent (handle , _winapi .EVENTLOG_AUDIT_FAILURE , 2 , 1003 , [] )
188+ with self . assertRaises ( TypeError ):
189+ _winapi .ReportEvent (handle , _winapi .EVENTLOG_SUCCESS , 1 , 1002 , None )
187190
188- with self .assertRaisesRegex ( TypeError , 'expected a list of strings, not int' ):
189- _winapi .ReportEvent (handle , _winapi .EVENTLOG_ERROR_TYPE , 0 , 1001 ,
190- [ "string" , 123 ] )
191+ with self .assertRaises ( ValueError ):
192+ _winapi .ReportEvent (handle , _winapi .EVENTLOG_SUCCESS , 1 , 1002 ,
193+ "Test message \0 with embedded null character" )
0 commit comments