
    Bh                    .   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
rdd
lmZ  ej                  d       G d d             Z ej                  d       G d d             Zej                   G d d             Zg dZy)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                      e Zd ZU dZ ej
                  d d      Zded<    ej
                  d d      Zded<   dd	Z	dd
Z
y)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                     t               S Nr	        Y/var/www/html/Telegram-Engagement-Pod-/env/lib/python3.12/site-packages/_pytest/timing.py<lambda>zInstant.<lambda>#   s    DFr   F)default_factoryinitfloatr
   c                     t               S r   r   r   r   r   r   zInstant.<lambda>(   s    r   
perf_countc                ,    t        | t                     S )z1Measure the duration since `Instant` was created.)startstop)Durationr   selfs    r   elapsedzInstant.elapsed+   s    d33r   c                ^    t        j                  | j                  t        j                        S )zInstant as UTC datetime.)r   fromtimestampr
   r   utcr   s    r   as_utczInstant.as_utc/   s    %%dii>>r   N)returnr   )r&   r   )__name__
__module____qualname____doc__dataclassesfieldr
   __annotations__r   r!   r%   r   r   r   r   r      sL     $+##NOD%O *)).UJ 4?r   r   c                  8    e Zd ZU dZded<   ded<   edd       Zy)r   z2A span of time as measured by `Instant.elapsed()`.r   r   r   c                \    | j                   j                  | j                  j                  z
  S )zaElapsed time of the duration in seconds, measured using a performance counter for precise timing.)r   r   r   r   s    r   secondszDuration.seconds;   s#     yy##djj&;&;;;r   Nr&   r   )r'   r(   r)   r*   r-   propertyr0   r   r   r   r   r   4   s!    <N
M< <r   r   c                  j    e Zd ZU dZ edddddd      j                         Zded	<   dd
ZddZ	ddZ
y)
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_timec                .    | xj                   |z  c_         y r   r:   )r    r0   s     r   r   zMockTiming.sleepP   s    g%r   c                    | j                   S r   r<   r   s    r   r
   zMockTiming.timeS   s    !!!r   c                    ddl m} |j                  |d| j                         |j                  |d| j                         |j                  |d| j                         y )Nr   )timingr   r
   r   )_pytestr?   setattrr   r
   )r    monkeypatchr?   s      r   patchzMockTiming.patchV   sG    "FGTZZ8FFDII6FNDII>r   N)r0   r   r&   Noner1   )rB   r   r&   rD   )r'   r(   r)   r*   r   	timestampr:   r-   r   r
   rC   r   r   r   r4   r4   A   s;    	_ $D!RR<FFHM5H&"?r   r4   )r   r   r
   )r*   
__future__r   r+   r   r   r
   r   r   typingr   pytestr   	dataclassr   r   r4   __all__r   r   r   <module>rK      s    #         " d#? ? $?6 d#	< 	< $	< ? ? ?8 ,r   