Skip to content

Commit d78e2db

Browse files
committed
Update test
1 parent 427587f commit d78e2db

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

Lib/test/test_winapi.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -163,32 +163,29 @@ def test_event_source_registration(self):
163163
handle = _winapi.RegisterEventSource(None, source_name)
164164
self.assertNotEqual(handle, _winapi.INVALID_HANDLE_VALUE)
165165

166-
# Test ReportEvent with the registered event source
167-
try:
168-
# Test with strings and raw data
169-
test_strings = ["Test message 1", "Test message 2"]
170-
test_data = b"test raw data"
171-
_winapi.ReportEvent(handle, 4, 1, 1002, test_strings, test_data)
172-
173-
# Test with empty strings list
174-
# _winapi.ReportEvent(handle, 2, 0, 1003, [], None) # TODO
175-
finally:
176-
_winapi.DeregisterEventSource(handle)
177-
178-
with self.assertRaises(OSError):
166+
with self.assertRaisesRegex(OSError, '[WinError 87]'):
179167
_winapi.RegisterEventSource(None, "")
180168

181-
with self.assertRaises(OSError):
169+
with self.assertRaisesRegex(OSError, '[WinError 6]'):
182170
_winapi.DeregisterEventSource(_winapi.INVALID_HANDLE_VALUE)
183171

184-
# Test ReportEvent with invalid handle
185-
with self.assertRaises(OSError):
172+
def test_report_event(self):
173+
source_name = "PythonTestEventSource"
174+
175+
handle = _winapi.RegisterEventSource(None, source_name)
176+
self.assertNotEqual(handle, _winapi.INVALID_HANDLE_VALUE)
177+
self.addCleanup(_winapi.DeregisterEventSource, handle)
178+
179+
# Test with strings and raw data
180+
test_strings = ["Test message 1", "Test message 2"]
181+
test_data = b"test raw data"
182+
_winapi.ReportEvent(handle, 4, 1, 1002, test_strings, test_data)
183+
184+
# Test with empty strings list
185+
_winapi.ReportEvent(handle, 2, 0, 1003, [], b'')
186+
187+
with self.assertRaisesRegex(OSError, '[WinError 6]'):
186188
_winapi.ReportEvent(_winapi.INVALID_HANDLE_VALUE, 1, 0, 1001, [], test_data)
187189

188-
# Test ReportEvent with invalid string types
189-
handle2 = _winapi.RegisterEventSource(None, "PythonTestEventSource2")
190-
try:
191-
with self.assertRaises(TypeError):
192-
_winapi.ReportEvent(handle2, 1, 0, 1001, ["string", 123], test_data)
193-
finally:
194-
_winapi.DeregisterEventSource(handle2)
190+
with self.assertRaisesRegex(TypeError, 'All strings must be unicode'):
191+
_winapi.ReportEvent(handle, 1, 0, 1001, ["string", 123], test_data)

Modules/_winapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3052,7 +3052,7 @@ static PyObject *
30523052
_winapi_ReportEvent_impl(PyObject *module, HANDLE handle, int event_type,
30533053
int event_category, int event_id, PyObject *strings,
30543054
Py_buffer *raw_data)
3055-
/*[clinic end generated code: output=9066f114cdfdf5f2 input=fc37cfe1816d02d7]*/
3055+
/*[clinic end generated code: output=9066f114cdfdf5f2 input=fade978a0b25e611]*/
30563056
{
30573057
BOOL success;
30583058
LPCWSTR *string_array = NULL;

Modules/clinic/_winapi.c.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)