Skip to content

Commit c1d1f16

Browse files
committed
fix WASI tests
1 parent 87379b1 commit c1d1f16

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

Lib/test/test_logging.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,14 +3952,23 @@ def test_config_queue_handler(self):
39523952
msg = str(ctx.exception)
39533953
self.assertEqual(msg, "Unable to configure handler 'ah'")
39543954

3955+
def _apply_simple_queue_listener_configuration(self, qspec):
3956+
self.apply_config({
3957+
"version": 1,
3958+
"handlers": {
3959+
"queue_listener": {
3960+
"class": "logging.handlers.QueueHandler",
3961+
"queue": qspec,
3962+
},
3963+
},
3964+
})
3965+
39553966
@threading_helper.requires_working_threading()
39563967
@support.requires_subprocess()
39573968
@patch("multiprocessing.Manager")
39583969
def test_config_queue_handler_does_not_create_multiprocessing_manager(self, manager):
39593970
# gh-120868, gh-121723, gh-124653
39603971

3961-
import multiprocessing
3962-
39633972
for qspec in [
39643973
{"()": "queue.Queue", "maxsize": -1},
39653974
queue.Queue(),
@@ -3972,52 +3981,41 @@ def test_config_queue_handler_does_not_create_multiprocessing_manager(self, mana
39723981
# check that the queue object correctly implements the API.
39733982
CustomQueueFakeProtocol(),
39743983
MinimalQueueProtocol(),
3975-
# multiprocessing.Queue() is a valid queue for the logging module
3976-
# but multiprocessing.SimpleQueue() is NOT valid because it lacks
3977-
# the 'put_nowait' method needed by the logging queue handler.
3978-
multiprocessing.Queue(),
39793984
]:
39803985
with self.subTest(qspec=qspec):
3981-
self.apply_config(
3982-
{
3983-
"version": 1,
3984-
"handlers": {
3985-
"queue_listener": {
3986-
"class": "logging.handlers.QueueHandler",
3987-
"queue": qspec,
3988-
},
3989-
},
3990-
}
3991-
)
3986+
self._apply_simple_queue_listener_configuration(qspec)
39923987
manager.assert_not_called()
39933988

39943989
@patch("multiprocessing.Manager")
39953990
def test_config_queue_handler_invalid_config_does_not_create_multiprocessing_manager(self, manager):
39963991
# gh-120868, gh-121723, gh-124653
39973992

3993+
for qspec in [object(), CustomQueueWrongProtocol()]:
3994+
with self.subTest(qspec=qspec), self.assertRaises(ValueError):
3995+
self._apply_simple_queue_listener_configuration(qspec)
3996+
manager.assert_not_called()
3997+
3998+
@skip_if_tsan_fork
3999+
@support.requires_subprocess()
4000+
@unittest.skipUnless(support.Py_DEBUG, "requires a debug build for testing"
4001+
" assertions in multiprocessing")
4002+
def test_config_reject_simple_queue_handler_multiprocessing_context(self):
4003+
# multiprocessing.SimpleQueue does not implement 'put_nowait'
4004+
# and thus cannot be used as a queue-like object (gh-124653)
4005+
39984006
import multiprocessing
39994007

4000-
for qspec in [
4001-
object(),
4002-
CustomQueueWrongProtocol(),
4003-
# multiprocessing.SimpleQueue does not implement the 'put_nowait'
4004-
# method and thus cannot be used as a queue-like object here.
4005-
multiprocessing.SimpleQueue(),
4006-
]:
4007-
with self.subTest(qspec=qspec):
4008+
if support.MS_WINDOWS:
4009+
start_methods = ['spawn']
4010+
else:
4011+
start_methods = ['spawn', 'fork', 'forkserver']
4012+
4013+
for start_method in start_methods:
4014+
with self.subTest(start_method=start_method):
4015+
ctx = multiprocessing.get_context(start_method)
4016+
qspec = ctx.SimpleQueue()
40084017
with self.assertRaises(ValueError):
4009-
self.apply_config(
4010-
{
4011-
"version": 1,
4012-
"handlers": {
4013-
"queue_listener": {
4014-
"class": "logging.handlers.QueueHandler",
4015-
"queue": qspec,
4016-
},
4017-
},
4018-
}
4019-
)
4020-
manager.assert_not_called()
4018+
self._apply_simple_queue_listener_configuration(qspec)
40214019

40224020
@skip_if_tsan_fork
40234021
@support.requires_subprocess()

0 commit comments

Comments
 (0)