o
    ^i                     @  s   d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	Z	ddl
mZ e	jddd	Ze	jdddZe	jdddZe	jdddZe	jdddZdS )z%Fixtures for use with jupyter events.    )annotationsN)AnyCallable)EventLoggerreturnio.StringIOc                   C  s   t  S )zA stream for capture events.)ioStringIO r
   r
   W/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/jupyter_events/pytest_plugin.pyjp_event_sink   s   r   logging.Handlerc                 C  s
   t | S )zGA logging handler that captures any events emitted by the event handler)loggingStreamHandler)r   r
   r
   r   jp_event_handler   s   
r   Callable[..., list[str] | None]c                   s   d fdd}|S )z3Reads list of events since last time it was called.r   list[str] | Nonec                    sH         } | rdd | dD nd }d d |S )Nc                 S  s   g | ]}t |qS r
   )jsonloads).0itemr
   r
   r   
<listcomp>#   s    z9jp_read_emitted_events.<locals>._read.<locals>.<listcomp>
r   )flushgetvaluestripsplittruncateseek)	event_bufoutputr   r   r
   r   _read    s   

z%jp_read_emitted_events.<locals>._readN)r   r   r
   )r   r   r"   r
   r!   r   jp_read_emitted_events   s   	r#   	list[Any]c                   C  s   g S )zA list of schema references.

    Each item should be one of the following:
    - string of serialized JSON/YAML content representing a schema
    - a pathlib.Path object pointing to a schema file on disk
    - a dictionary with the schema data.
    r
   r
   r
   r
   r   jp_event_schemas,   s   	r%   r   c                 C  s*   t  }|D ]}|| q|j| d |S )z(A pre-configured event logger for tests.)handler)r   register_event_schemaregister_handler)r   r%   loggerschemar
   r
   r   jp_event_logger8   s
   r+   )r   r   )r   r   r   r   )r   r   r   r   r   r   )r   r$   )r   r   r%   r$   r   r   )__doc__
__future__r   r   r   r   typingr   r   pytestjupyter_eventsr   fixturer   r   r#   r%   r+   r
   r
   r
   r   <module>   s$    