-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for sub-interpreter support
These are flaky as they use internal CPython packages, but that will do until the "interpreters" module is made eventually official. Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import contextlib | ||
from typing import Iterable, Tuple, no_type_check | ||
|
||
import pytest | ||
|
||
import crc32c | ||
|
||
try: | ||
from test.support.interpreters import Interpreter # type: ignore | ||
from test.support.interpreters import create, queues | ||
except ImportError: | ||
pytest.skip("No sub-interpreter support", allow_module_level=True) | ||
|
||
|
||
@pytest.fixture(name="interpreter") | ||
def interpreter_fixture() -> Iterable[Interpreter]: | ||
interpreter = create() | ||
with contextlib.closing(interpreter): | ||
yield interpreter | ||
|
||
|
||
def test_crc32c_can_be_loaded(interpreter: Interpreter) -> None: | ||
interpreter.exec("import crc32c") | ||
# all good, no exception raised | ||
|
||
|
||
@pytest.mark.calculates_crc32c | ||
def test_crc32c_can_run(interpreter: Interpreter) -> None: | ||
|
||
queue = queues.create() | ||
VALUE = b"test" | ||
interpreter.prepare_main(queue_id=queue.id, value_in=VALUE) | ||
|
||
@no_type_check | ||
def crc32c_in_subinterpreter() -> None: | ||
from test.support.interpreters.queues import Queue # type: ignore | ||
|
||
import crc32c | ||
|
||
queue = Queue(queue_id) | ||
value_out = crc32c.crc32c(value_in) | ||
queue.put(value_out) | ||
|
||
thread = interpreter.call_in_thread(crc32c_in_subinterpreter) | ||
result = queue.get(timeout=5) | ||
thread.join() | ||
assert result == crc32c.crc32c(VALUE) |