10000 bpo-32604: Recommit "bpo-32604: PEP 554 for use in test suite (GH-19985)" by nanjekyejoannah · Pull Request #20611 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-32604: Recommit "bpo-32604: PEP 554 for use in test suite (GH-19985)" #20611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unused exceptions, fix pep 8 formatting errors and fix _NOT_SE…
…T in recv_nowait()
  • Loading branch information
nanjekyejoannah committed May 18, 2020
commit 9577395e4c0867514974ea546aaa757bc5608735
20 changes: 12 additions & 8 deletions Lib/test/support/interpreters.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"""Subinterpreters High Level Module."""

import _xxsubinterpreters as _interpreters

# aliases:
from _xxsubinterpreters import (
ChannelError, ChannelNotFoundError,
ChannelEmptyError, ChannelNotEmptyError, NotReceivedError,
ChannelError, ChannelNotFoundError, ChannelEmptyError,
is_shareable,
)


__all__ = [
'Interpreter', 'get_current', 'get_main', 'create', 'list_all',
'SendChannel', 'RecvChannel',
'create_channel', 'list_all_channels', 'is_shareable',
'ChannelError', 'ChannelNotFoundError',
'ChannelEmptyError', 'ChannelNotEmptyError',
'NotReceivedError',
'ChannelEmptyError',
]


Expand All @@ -25,20 +25,23 @@ def create(*, isolated=True):
id = _interpreters.create(isolated=isolated)
return Interpreter(id, isolated=isolated)


def list_all():
"""
Get all existing interpreters.
"""
return [Interpreter(id) for id in
_interpreters.list_all()]


def get_current():
"""
Get the currently running interpreter.
"""
id = _interpreters.get_current()
return Interpreter(id)


def get_main():
"""
Get the main interpreter.
8000 Expand Down Expand Up @@ -100,6 +103,7 @@ def create_channel():
cid = _interpreters.channel_create()
return (RecvChannel(cid), SendChannel(cid))


def list_all_channels():
"""
Get all open channels.
Expand All @@ -108,6 +112,9 @@ def list_all_channels():
for cid in _interpreters.channel_list_all()]


_NOT_SET = object()


class RecvChannel:
"""
The RecvChannel object represents
Expand All @@ -131,22 +138,19 @@ def recv(self, *, _delay=10 / 1000): # 10 milliseconds
obj = _interpreters.channel_recv(self._id, sentinel)
return obj

def recv_nowait(self, default=None):
def recv_nowait(self, default=_NOT_SET):
"""
Like recv(), but return the default
instead of waiting.

This function is blocked by a missing low-level
implementation of channel_recv_wait().
"""
if default is None:
default = _NOT_SET
if default is _NOT_SET:
return _interpreters.channel_recv(self._id)
else:
return _interpreters.channel_recv(self._id, default)

_NOT_SET = object()

class SendChannel:
"""
8000 Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import _xxsubinterpreters as _interpreters
from test.support import interpreters


def _captured_script(script):
r, w = os.pipe()
indented = script.replace('\n', '\n ')
Expand All @@ -19,6 +20,7 @@ def _captured_script(script):
""")
return wrapped, open(r)


def clean_up_interpreters():
for interp in interpreters.list_all():
if interp.id == 0: # main
Expand All @@ -28,12 +30,14 @@ def clean_up_interpreters():
except RuntimeError:
pass # already destroyed


def _run_output(interp, request, shared=None):
script, rpipe = _captured_script(request)
with rpipe:
interp.run(script)
return rpipe.read()


@contextlib.contextmanager
def _running(interp):
r, w = os.pipe()
Expand Down Expand Up @@ -519,7 +523,6 @@ def test_send_recv_nowait_same_interpreter(self):
assert obj == orig
"""))


r, s = interpreters.create_channel()

def f():
Expand Down
23 changes: 0 additions & 23 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,6 @@ static PyObject *ChannelNotFoundError;
static PyObject *ChannelClosedError;
static PyObject *ChannelEmptyError;
static PyObject *ChannelNotEmptyError;
static PyObject *ChannelReleasedError;
static PyObject *NotReceivedError;

static int
channel_exceptions_init(PyObject *ns)
Expand Down Expand Up @@ -1205,27 +1203,6 @@ channel_exceptions_init(PyObject *ns)
return -1;
}

// An operation tried to use a released channel.
ChannelReleasedError = PyErr_NewException(
"_interpreters.ChannelReleasedError", ChannelClosedError, NULL);
if (ChannelReleasedError == NULL) {
return -1;
}
if (PyDict_SetItemString(ns, "ChannelReleasedError", ChannelReleasedError) != 0) {
return -1;
}

// An operation trying to send an object when Nothing was waiting
// to receive it
NotReceivedError = PyErr_NewException(
"_interpreters.NotReceivedError", ChannelError, NULL);
if (NotReceivedError == NULL) {
return -1;
}
if (PyDict_SetItemString(ns, "NotReceivedError", NotReceivedError) != 0) {
return -1;
}

// An operation tried to pop from an empty channel.
ChannelEmptyError = PyErr_NewException(
"_xxsubinterpreters.ChannelEmptyError", ChannelError, NULL);
Expand Down
0