U
    œËúgW  ã                   @  sx   d dl mZ d dlmZmZ d dlmZ ddlmZ erDd dl	m
Z
 eddd	œd
d„ƒZddœdd„Zddœdd„ZdS )é    )Úannotations)ÚAbstractContextManagerÚcontextmanager)ÚTYPE_CHECKINGé   )Ú_core)Ú	GeneratorÚboolzGenerator[(None, None, None)])ÚexpectedÚreturnc                 c  sj   d}t  ¡ }|j}|j}z*dV  | r@|j|ks8|j|kr@tdƒ‚W 5 | sd|j|ks\|j|krdtdƒ‚X dS )z5Check if checkpoints are executed in a block of code.Tz$assert_no_checkpoints block yielded!Nz'assert_checkpoints block did not yield!)r   Zcurrent_taskZ_cancel_pointsZ_schedule_pointsÚAssertionError)r
   Ú__tracebackhide__ZtaskZorig_cancelZorig_schedule© r   ú=/tmp/pip-unpacked-wheel-ks04xdmi/trio/testing/_checkpoints.pyÚ_assert_yields_or_not   s$    ÿÿÿÿr   zAbstractContextManager[None])r   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    s    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_checkpoints4   s    r   N)Ú
__future__r   Ú
contextlibr   r   Útypingr   Ú r   Úcollections.abcr   r   r   r   r   r   r   r   Ú<module>   s   