o
    h                     @  s   d Z ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	l	m
Z
 e
r8dd
lmZ ejddG dd dZejddG dd dZejG dd dZg dZdS )zIndirection for time functions.

We intentionally grab some "time" functions internally to avoid tests mocking "time" to affect
pytest runtime information (issue #185).

Fixture "mock_timing" also interacts with this module for pytest's own tests.
    )annotationsN)datetime)timezoneperf_counter)sleeptime)TYPE_CHECKING)MonkeyPatchT)frozenc                   @  sZ   e Zd ZU dZejdd ddZded< ejdd ddZded	< dddZ	dddZ
dS )Instantz
    Represents an instant in time, used to both get the timestamp value and to measure
    the duration of a time span.

    Inspired by Rust's `std::time::Instant`.
    c                   C     t  S Nr    r   r   O/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/timing.py<lambda>#       zInstant.<lambda>F)default_factoryinitfloatr	   c                   C  r   r   r   r   r   r   r   r   (   r   
perf_countreturnDurationc                 C  s   t | t dS )z1Measure the duration since `Instant` was created.)startstop)r   r   selfr   r   r   elapsed+   s   zInstant.elapsedr   c                 C  s   t | jtjS )zInstant as UTC datetime.)r   fromtimestampr	   r   utcr   r   r   r   as_utc/   s   zInstant.as_utcN)r   r   )r   r   )__name__
__module____qualname____doc__dataclassesfieldr	   __annotations__r   r   r!   r   r   r   r   r      s   
 	
r   c                   @  s0   e Zd ZU dZded< ded< ed
ddZd	S )r   z2A span of time as measured by `Instant.elapsed()`.r   r   r   r   r   c                 C  s   | j j| jj S )zaElapsed time of the duration in seconds, measured using a performance counter for precise timing.)r   r   r   r   r   r   r   seconds;   s   zDuration.secondsNr   r   )r"   r#   r$   r%   r(   propertyr)   r   r   r   r   r   4   s   
 r   c                   @  sN   e Zd ZU dZedddddd Zded	< dddZdddZ	dddZ
dS )
MockTiminga  Mocks _pytest.timing with a known object that can be used to control timing in tests
    deterministically.

    pytest itself should always use functions from `_pytest.timing` instead of `time` directly.

    This then allows us more control over time during testing, if testing code also
    uses `_pytest.timing` functions.

    Time is static, and only advances through `sleep` calls, thus tests might sleep over large
    numbers and obtain accurate time() calls at the end, making tests reliable and instant.i              2   r   _current_timer)   r   Nonec                 C  s   |  j |7  _ d S r   r2   )r   r)   r   r   r   r   P   s   zMockTiming.sleepc                 C  s   | j S r   r4   r   r   r   r   r	   S   s   zMockTiming.timemonkeypatchr   c                 C  s@   ddl m} ||d| j ||d| j ||d| j d S )Nr   )timingr   r	   r   )_pytestr6   setattrr   r	   )r   r5   r6   r   r   r   patchV   s   zMockTiming.patchN)r)   r   r   r3   r*   )r5   r   r   r3   )r"   r#   r$   r%   r   	timestampr2   r(   r   r	   r9   r   r   r   r   r,   A   s   
 

r,   )r   r   r	   )r%   
__future__r   r&   r   r   r	   r   r   typingr
   pytestr   	dataclassr   r   r,   __all__r   r   r   r   <module>   s$    

