| 1 |
"""Marks for runtime capabilities several test modules gate on. |
| 2 |
|
| 3 |
Capabilities used by a single module stay private to it, as ``_NEEDS_LINK_DIR_FD`` and friends do. These span modules, |
| 4 |
so they live here and read the same ``CAPABILITIES`` probes the coverage pragmas use. Gate on a probe rather than on an |
| 5 |
interpreter or platform name: a name answers who is running, and every one of these questions is about what the runtime |
| 6 |
can do. |
| 7 |
""" |
| 8 |
|
| 9 |
from __future__ import annotations |
| 10 |
|
| 11 |
import sys |
| 12 |
from typing import TYPE_CHECKING |
| 13 |
|
| 14 |
import pytest |
| 15 |
from capabilities import CAPABILITIES |
| 16 |
|
| 17 |
if TYPE_CHECKING: |
| 18 |
from typing import Final |
| 19 |
|
| 20 |
#: The one gate here that asks who is running rather than what it can do. GraalPy's multiprocessing semaphores raise |
| 21 |
#: ``OSError: [Errno 0] Success`` from ``_wait_semaphore.acquire(False)`` when ``Event.set()`` notifies a contended |
| 22 |
#: condition, which fails whichever test happens to be coordinating processes at the time. The defect is in the |
| 23 |
#: interpreter's own ``multiprocessing/synchronize.py``, it only appears on Linux under load, and an uncontended probe |
| 24 |
#: cannot see it, so there is nothing to measure and no fix to make from here. |
| 25 |
SKIP_ON_UNRELIABLE_PROCESS_SYNC: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 26 |
sys.implementation.name == "graalpy", |
| 27 |
reason="this runtime raises OSError from multiprocessing Event.set() under contention", |
| 28 |
) |
| 29 |
|
| 30 |
NEEDS_FORK: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 31 |
not CAPABILITIES["fork"], reason="installing fork handlers needs os.register_at_fork" |
| 32 |
) |
| 33 |
|
| 34 |
NEEDS_REGISTER_AT_FORK: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 35 |
not CAPABILITIES["register-at-fork"], reason="the fork transition gate is installed through os.register_at_fork" |
| 36 |
) |
| 37 |
|
| 38 |
NEEDS_FORK1: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 39 |
not CAPABILITIES["fork1"], reason="forking a single thread needs the Solaris os.fork1" |
| 40 |
) |
| 41 |
|
| 42 |
NEEDS_FCNTL: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 43 |
not CAPABILITIES["fcntl"], reason="native flock semantics need the fcntl module" |
| 44 |
) |
| 45 |
|
| 46 |
NEEDS_SYMLINK: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 47 |
not CAPABILITIES["symlink"], reason="creating a symlink needs a privilege this runtime does not grant" |
| 48 |
) |
| 49 |
|
| 50 |
#: Windows resolves a lock's parent with abspath, so a symlinked parent stays a distinct key and never collapses. |
| 51 |
NEEDS_PARENT_SYMLINK_COLLAPSE: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 52 |
not CAPABILITIES["symlink"] or sys.platform == "win32", |
| 53 |
reason="a symlinked parent collapses into one key only where the parent is resolved with realpath", |
| 54 |
) |
| 55 |
|
| 56 |
NEEDS_FILE_MODE: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 57 |
not CAPABILITIES["file-mode"], reason="making a folder or a claim unreadable needs POSIX permission bits" |
| 58 |
) |
| 59 |
|
| 60 |
NEEDS_UNLINK_OPEN_FILE: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 61 |
not CAPABILITIES["unlink-open-file"], |
| 62 |
reason="this runtime keeps an open marker undeletable, so no peer can take it from a live holder", |
| 63 |
) |
| 64 |
|
| 65 |
NEEDS_POSIX_SIGNALS: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 66 |
not CAPABILITIES["posix-signals"], reason="liveness is probed with os.kill only where POSIX signals exist" |
| 67 |
) |
| 68 |
|
| 69 |
NEEDS_PROMPT_FINALIZATION: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 70 |
not CAPABILITIES["prompt-finalization"], |
| 71 |
reason="a dropped reference does not run __del__ on a deferred collector", |
| 72 |
) |
| 73 |
|
| 74 |
NEEDS_COLLECTED_FINALIZATION: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 75 |
not CAPABILITIES["collected-finalization"], |
| 76 |
reason="gc.collect() does not run __del__ on this runtime", |
| 77 |
) |
| 78 |
|
| 79 |
NEEDS_CLASS_COLLECTION: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 80 |
not CAPABILITIES["class-collection"], |
| 81 |
reason="gc.collect() does not reclaim classes on this runtime", |
| 82 |
) |
| 83 |
|
| 84 |
NEEDS_GENERATOR_EXCEPTION_CONTEXT: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 85 |
not CAPABILITIES["generator-exception-context"], |
| 86 |
reason="this runtime clears __context__ when an exception is thrown into a suspended frame", |
| 87 |
) |
| 88 |
|
| 89 |
NEEDS_AUDIT_EVENTS: Final[pytest.MarkDecorator] = pytest.mark.skipif( |
| 90 |
not CAPABILITIES["audit-events"], |
| 91 |
reason="this runtime never delivers audit events to an installed hook", |
| 92 |
) |
| 93 |
|
| 94 |
#: Raised from ``_GeneratorContextManagerBase.__aexit__``, so the lock's cancellation contract cannot be observed at |
| 95 |
#: all there. Not strict: the deviation depends on where the cancellation lands, so some of these tests still pass. |
| 96 |
XFAIL_WITHOUT_COROUTINE_CANCELLATION: Final[pytest.MarkDecorator] = pytest.mark.xfail( |
| 97 |
not CAPABILITIES["coroutine-cancellation"], |
| 98 |
reason="GraalPy's contextlib answers athrow() with RuntimeError instead of propagating the CancelledError", |
| 99 |
strict=False, |
| 100 |
) |
| 101 |
|
| 102 |
__all__ = [ |
| 103 |
"NEEDS_AUDIT_EVENTS", |
| 104 |
"NEEDS_CLASS_COLLECTION", |
| 105 |
"NEEDS_COLLECTED_FINALIZATION", |
| 106 |
"NEEDS_FCNTL", |
| 107 |
"NEEDS_FILE_MODE", |
| 108 |
"NEEDS_FORK", |
| 109 |
"NEEDS_FORK1", |
| 110 |
"NEEDS_GENERATOR_EXCEPTION_CONTEXT", |
| 111 |
"NEEDS_PARENT_SYMLINK_COLLAPSE", |
| 112 |
"NEEDS_POSIX_SIGNALS", |
| 113 |
"NEEDS_PROMPT_FINALIZATION", |
| 114 |
"NEEDS_REGISTER_AT_FORK", |
| 115 |
"NEEDS_SYMLINK", |
| 116 |
"NEEDS_UNLINK_OPEN_FILE", |
| 117 |
"SKIP_ON_UNRELIABLE_PROCESS_SYNC", |
| 118 |
"XFAIL_WITHOUT_COROUTINE_CANCELLATION", |
| 119 |
] |