a
    *ñ»jù  ã                   @  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
rpd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 )zøIndirection 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                   @  sb   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d„Z	d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  s   t ƒ S ©Nr   © r   r   ú4E:\soccer\ml_env\Lib\site-packages\_pytest/timing.pyÚ<lambda>#   ó    zInstant.<lambda>F)Údefault_factoryÚinitÚfloatr	   c                   C  s   t ƒ S r   r   r   r   r   r   r   (   r   Ú
perf_countÚDuration©Úreturnc                 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)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdataclassesÚfieldr	   Ú__annotations__r   r   r!   r   r   r   r   r      s   
	ÿr   c                   @  s4   e Zd ZU dZded< ded< ed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(   Úpropertyr)   r   r   r   r   r   4   s
   
r   c                   @  s^   e Zd ZU dZeddddddƒ ¡ Zded	< dd
dœdd„Zddœdd„Z	dd
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_timeÚNone)r)   r   c                 C  s   |  j |7  _ d S r   ©r1   )r   r)   r   r   r   r   P   s    zMockTiming.sleepr   c                 C  s   | j S r   r3   r   r   r   r   r	   S   s    zMockTiming.timer   )Úmonkeypatchr   c                 C  s@   ddl m} | |d| j¡ | |d| j¡ | |d| j¡ d S )Nr   )Útimingr   r	   r   )Z_pytestr5   Úsetattrr   r	   )r   r4   r5   r   r   r   ÚpatchV   s    zMockTiming.patchN)r"   r#   r$   r%   r   Ú	timestampr1   r(   r   r	   r7   r   r   r   r   r+   A   s
   
r+   )r   r   r	   )r%   Ú
__future__r   r&   r   r   r	   r   r   Útypingr
   Zpytestr   Ú	dataclassr   r   r+   Ú__all__r   r   r   r   Ú<module>   s"   

