o
    Ye                     @  sZ   d dl mZ d dlmZ d dlmZmZ ddlmZ edd
dZ	dddZ
dddZdS )    )annotations)	Generator)AbstractContextManagercontextmanager   )_coreexpectedboolreturnGenerator[None, None, None]c                 c  s    d}t  }|j}|j}z(dV  | r!|j|ks|j|kr!tdW | s2|j|ks.|j|kr4tddS dS | sF|j|ksB|j|krFtdw )z5Check if checkpoints are executed in a block of code.TNz'assert_checkpoints block did not yield!z$assert_no_checkpoints block yielded!)r   Zcurrent_taskZ_cancel_pointsZ_schedule_pointsAssertionError)r   __tracebackhide__ZtaskZorig_cancelZorig_schedule r   =usr/lib/python3.10/site-packages/trio/testing/_checkpoints.py_assert_yields_or_not	   s&   
r   AbstractContextManager[None]c                  C  s   d} t dS )a  Use as a context manager to check that the code inside the ``with``
    block either exits with an exception or executes at least one
    :ref:`checkpoint <checkpoints>`.

    Raises:
      AssertionError: if no checkpoint was executed.

    Example:
      Check that :func:`trio.sleep` is a checkpoint, even if it doesn't
      block::

         with trio.testing.assert_checkpoints():
             await trio.sleep(0)

    Tr   r   r   r   r   assert_checkpoints      r   c                  C  s   d} t dS )a  Use as a context manager to check that the code inside the ``with``
    block does not execute any :ref:`checkpoints <checkpoints>`.

    Raises:
      AssertionError: if a checkpoint was executed.

    Example:
      Synchronous code never contains any checkpoints, but we can double-check
      that::

         send_channel, receive_channel = trio.open_memory_channel(10)
         with trio.testing.assert_no_checkpoints():
             send_channel.send_nowait(None)

    TFr   r   r   r   r   assert_no_checkpoints1   r   r   N)r   r	   r
   r   )r
   r   )
__future__r   collections.abcr   
contextlibr   r    r   r   r   r   r   r   r   r   <module>   s    
