HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/langsmith/__pycache__/pytest_plugin.cpython-310.pyc
o

���gc2�@sdZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlZddlm
ZddlmZe�e�Zdd�Zd	d
�Zej�d�rJdd
�Zndd�Zejdd�dd��Zejdd��ZGdd�d�Zdd�Zde de!de fdd�Z"de de!de fd d!�Z#dS)"zLangSmith Pytest hooks.�N)�defaultdict)�Lock)�utils)�testcCsDz|�dd�}|jddddd�Wd	Sty!t�d�Yd	Sw)
zaSet a boolean flag for LangSmith output.

    Skip if --langsmith-output is already defined.
    �	langsmith�	LangSmith�--langsmith-output�
store_trueFz'Use LangSmith output (requires 'rich').)�action�default�helpzCLangSmith output flag cannot be added because it's already defined.N)�getgroup�	addoption�
ValueError�logger�warning)�parser�group�r�B/usr/local/lib/python3.10/dist-packages/langsmith/pytest_plugin.py�pytest_addoptions�
��rcsft�fdd�dD��r/t�fdd�dD��s��dd�t�fdd�d	D��s1��dd
�dSdSdS)zHandle output arguments.c3��|]}|�vVqdS�Nr)�.0�opt��argsrr�	<genexpr>*��z&_handle_output_args.<locals>.<genexpr>)rc3rrr�r�arrrr,r)�-qqrr!c3rrrrrrrr/r)�-sz--capture=nor"N)�any�insertrrrr�_handle_output_args(s�r%z7.cCst|�dS)zCCall immediately after command line options are parsed (pytest v7).N�r%)�configrrrr�pytest_cmdline_preparse5�r(cCst|�dS)zHandle args in pytest v8+.Nr&rrrr�pytest_load_initial_conftests;r)r*T)�hookwrapperccs��|�d�}|rF|r
|jni}|j}tdi|��|�|_t|dd�}|durFd|jvrF||jd<t|j�|jjd|jj	|jj
|jjd�|_dVdS)zEApply LangSmith tracking to tests marked with @pytest.mark.langsmith.r�_requestN�request)r-)�argnames�initialnames�
names_closure�name2fixturedefsr)�get_closest_marker�kwargs�obj�ls_test�getattr�funcargs�type�_fixtureinfor.r/r0r1)�item�markerr3�
original_func�request_objrrr�pytest_runtest_call@s �


�
r>cCs|�d�rdSdS)z7Remove the short test-status character outputs ("./F").r)�r?r?N)�	getoption)�reportr'rrr�pytest_report_teststatusXs
�rBc@s^eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	de
fdd�Zdd�Zdd�Z
dS)�LangSmithPluginz'Plugin for rendering LangSmith results.cCspddlm}ddlm}tt�|_i|_i|_t	�|_
|�|_||��|jdd�|_
|j
��|j
j�d�dS)zInitialize.r)�Console)�Live�
)�console�refresh_per_secondzCollecting tests...N)�rich.consolerD�	rich.liverEr�list�test_suites�test_suite_urls�process_statusr�status_lockrG�generate_tables�live�start�print)�selfrDrErrr�__init__ds
�
zLangSmithPlugin.__init__cCs&t�|_|jD]	}|j�|j�qdS)zHCall after collection phase is completed and session.items is populated.N)�set�collected_nodeids�items�add�nodeid)rT�sessionr:rrr�pytest_collection_finishvs
�z(LangSmithPlugin.pytest_collection_finishcCs|j|�|�dS)z&Group a test case with its test suite.N)rL�append)rT�
test_suite�
process_idrrr�add_process_to_test_suite|�z)LangSmithPlugin.add_process_to_test_suitecCs|js
|jj�d�|j�h|j�|i�}|�d�r)i|�di��|�d��|d<|�d�r=i|�di��|�d��|d<|�d�rQi|�di��|�d��|d<|�d�rei|�di��|�d��|d<i|�|�|j|<Wd�n1sxwY|j�|���dS)zUpdate test results.zRunning tests...�feedback�inputs�reference_outputs�outputsN)	rNrQrGrSrO�get�pop�updaterP)rTr_�status�current_statusrrr�update_process_status�s>

��

��

��

���z%LangSmithPlugin.update_process_statuscCs|�|ddi�dS)z/Initialize live display when first test starts.ri�runningN)rk)rTrZrrr�pytest_runtest_logstart�raz'LangSmithPlugin.pytest_runtest_logstartcCs<ddlm}g}|jD]}|�|�}|�|�q||�}|S)u�Generate a collection of tables—one per suite.

        Returns a 'Group' object so it can be rendered simultaneously by Rich Live.
        r)�Group)rIrnrL�_generate_tabler])rTrn�tables�
suite_name�tablerrrrrP�s

zLangSmithPlugin.generate_tablesrqcsjddlm}�j|}d|�d�j|�d�}||dd�}|�d�|�d	�|�d
�|�d�|�d�|�d
�|�d�td�}td�}t��}g}	tt�}
�fdd�|D�}|�	�D]G\}}
|
�
d|�|
�
d|�}|	�|�|
�
di��	�D]\}}t|t
ttf�r�|
|�|�q|tt|d�d��|�}tt|
�
dd��|�}q_tdd�|��D��}tdd�|��D��}||r�|||}|dkr�dnd}d|�d |d!�d"|�d �}nd#}|	r�t|	�t|	�d�d�}nd$}|
r�d%�d&d�|
�	�D��}nd'}t|t|��}�jj||d(�t�d)��|�	�D]�\}}
d*ddd+d,��
|
�
dd�d-�}|
�
d|�|
�
d|�}d%��fd.d�|
�
di��	�D��}t�|
�
d/i��}t�|
�
d0i��}t�|
�
d1i��}|�tt|��d2�t|�d2�t|�d2�t|�d2��d3�d|�d |
�
dd��d"|�d �||d�d���q|�d4d4d4d4d4d4d4�|�d5d4d4d4|||�|S)6zGenerate results table.r)�TablezTest Suite: [bold]z$[/bold]
LangSmith URL: [bright_cyan]z[/bright_cyan]�left)�title�
title_justify�Test�InputszRef outputs�Outputs�Status�Feedback�Durationri�durationcsi|]}|�j|�qSr)rN)r�pid)rTrr�
<dictcomp>�sz3LangSmithPlugin._generate_table.<locals>.<dictcomp>�end_time�
start_timerbz.2f�s�queuedcs��|]
}|�d�dkVqdS)ri�passedN�rf�rr�rrrr���z2LangSmithPlugin._generate_table.<locals>.<genexpr>csr�)ri�failedNr�r�rrrr�r���green�red�[�]z.0%z[/z
Passed: --z--s�
css.�|]\}}|�dt|�t|���VqdS)�: N)�sum�len�r�k�vrrrr�s�
�z--���yellow�cyan)rlr�r��skipped�whitec3s<�|]\}}t|�d��dt|t�rt|�n|��VqdS)��max_lenr�N)�_abbreviate�
isinstance�bool�intr�)�max_dynamic_col_widthrrr�s
�&�
�rcrdrer�Nr?z[bold]Averages[/bold])�
rich.tablersrLrM�
add_columnr��timerrKrXrfr]r��floatr�r��maxr��values�joinrG�width�json�dumps�add_row�_abbreviate_test_name�strr�)rTrqrs�process_idsrurr�
max_status�max_duration�now�	durations�numeric_feedbacks�suite_statusesr~rir}r�r��passed_count�failed_count�rate�color�aggregate_status�aggregate_duration�aggregate_feedback�status_colorrbrcrdrer)r�rTrro�s�
�







�

�
���


�
�
�
zLangSmithPlugin._generate_tablecCs*d|j_|j�d�}|rdd�|_dSdS)z9Disable warning reporting and show no warnings in output.Fzwarnings-pluginc_sdSrr)rr3rrr�<lambda>sz2LangSmithPlugin.pytest_configure.<locals>.<lambda>N)�option�showwarnings�
pluginmanager�
get_plugin�warning_summary)rTr'�reporterrrr�pytest_configures
�z LangSmithPlugin.pytest_configurecCs|j��|jj�d�dS)z3Stop Rich Live rendering at the end of the session.z
Finishing up...N)rQ�stoprGrS)rTr[rrr�pytest_sessionfinish!s
z$LangSmithPlugin.pytest_sessionfinishN)�__name__�
__module__�__qualname__�__doc__rUr\r`rkrmrPr�ror�r�rrrrrCasf
rCcCsz|�dd�|�d�r;tj�d�sd}t|��tj�d�r#d}t|��t	�
�r-d}t|��|j�t
�d	�d
|j_dSdS)z Register the 'langsmith' marker.�markersz/langsmith: mark test to be tracked in LangSmithr�richzoMust have 'rich' installed to use --langsmith-output. Please install with: `pip install -U 'langsmith[pytest]'`�PYTEST_XDIST_TESTRUNUIDzq--langsmith-output not supported with pytest-xdist. Please remove the '--langsmith-output' option or '-n' option.z�--langsmith-output not supported when env varLANGSMITH_TEST_TRACKING='false'. Please remove the'--langsmith-output' option or enable test tracking.�langsmith_output_pluginFN)�addinivalue_liner@�	importlib�util�	find_specr�os�environrf�ls_utils�test_tracking_is_disabledr��registerrCr�r�)r'�msgrrrr�'s&�
����r��xr��returncCs$t|�|kr|d|d�dS|S)N��...)r�)r�r�rrrr�Fsr��	test_namecCsnt|�|kr5|�d�\}}td|�|kr d||dd�S|td|�}d||d�d|S|S)Nz::z.py::r�r�z...::)r��split)r�r��filer�file_lenrrrr�Msr�)$r��importlib.utilr�r��loggingr�r��collectionsr�	threadingr�pytestrrr��langsmith.testing._internalrr5�	getLoggerr�rrr%�__version__�
startswithr(r*�hookimplr>rBrCr�r�r�r�r�rrrr�<module>s4




G