
    Yjt                     H   d dl Zd dlmc mZ d dlZd dlZd dlm	Z	 d dl
Z
d dlmZmZ d dlmZ d dlmZ d dlmZ e	rd dlmZ d dlmZ d d	lmZ d d
lmZ dZddZ e
j        d          dd            ZddZ G d d          Z G d de          Z  G d de          Z!dS )     N)TYPE_CHECKING)create_terminal_writerhookimpl)
TestReport)
algorithms)ensure_ipynb_compatibility)nodes)Config)Parser)ExitCodeiX  parserr   returnc           	      R   |                      d          }|                    dddd           |                    ddd	t          j                            t          j                    d
                     |                    ddt          d           |                    ddt          d           |                    ddt          dt          j	        
                                 dt          j	        
                                           |                    dddd           dS )z)
    Declare pytest-split's options.
    zSplit tests into groups which execution time is about the same. Run with --store-durations to store information about test execution times.z--store-durationsstore_durations
store_truez(Store durations into '--durations-path'.)destactionhelpz--durations-pathdurations_pathzsPath to the file in which durations are (to be) stored, default is .test_durations in the current working directoryz.test_durations)r   r   defaultz--splitssplitsz,The number of groups to split the tests into)r   typer   z--groupgroupz;The group of tests that should be executed (first one is 1)z--splitting-algorithmsplitting_algorithmz,Algorithm used to split the tests. Choices: duration_based_chunks)r   r   r   r   choicesz--clean-durationsclean_durationszpRemoves the test duration info for tests which are not present while running the suite with '--store-durations'.N)getgroup	addoptionospathjoingetcwdintstrr   
Algorithmsnames)r   r   s     Z/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/pytest_split/plugin.pypytest_addoptionr)      sh    OO	V E 
OO7	     
OOJ RY[[*;<<     
OO;	     
OOJ	     
OO"[J<Q<W<W<Y<Y[['%++--     
OO@          T)tryfirstconfigr
   int | ExitCode | Nonec                 @   |                      d          }|                      d          }||dS |r|t          j        d          |r|t          j        d          |dk     rt          j        d          |dk     s||k    rt          j        d|           dS )	z
    Validate options.
    r   r   Nzargument `--group` is requiredzargument `--splits` is required   z argument `--splits` must be >= 1z'argument `--group` must be >= 1 and <= )	getoptionpytest
UsageError)r,   r   r   s      r(   pytest_cmdline_mainr3   M   s    
 W%%Eh''F~%-t B%- @AAA C ABBBzz BCCCqyyEFNN R& R RSSS4r*   c                     | j         j        r4| j         j        r(| j                            t          |           d           | j         j        r*| j                            t          |           d           dS dS )z%
    Enable the plugins we need.
    pytestsplitpluginpytestsplitcachepluginN)optionr   r   pluginmanagerregisterPytestSplitPluginr   PytestSplitCachePlugin)r,   s    r(   pytest_configurer<   g   s     } V 3 V%%&7&?&?ATUUU}$ 
%%"6**,D	
 	
 	
 	
 	

 
r*   c                       e Zd ZddZdS )Baser,   r
   r   Nc                    || _         t          | j                   | _        	 t          |j        j                  5 }t          j        |                                          | _	        ddd           n# 1 swxY w Y   n# t          $ r
 i | _	        Y nw xY wt          | j	        t                    rt          | j	                  | _	        dS dS )z
        Load durations and set up a terminal writer.

        This logic is shared for both the split- and cache plugin.
        N)r,   r   writeropenr7   r   jsonloadsreadcached_durationsFileNotFoundError
isinstancelistdict)selfr,   fs      r(   __init__zBase.__init__u   s    ,T[99	'fm233 =q(,
16688(<(<%= = = = = = = = = = = = = = =  	' 	' 	'$&D!!!	' d+T22 	@$()>$?$?D!!!	@ 	@s4   A? ,A3'A? 3A77A? :A7;A? ?BBr,   r
   r   N)__name__
__module____qualname__rL    r*   r(   r>   r>   t   s.        @ @ @ @ @ @r*   r>   c                   X     e Zd Zd fdZ ed          	 	 	 	 	 	 dd
            Z xZS )r:   r,   r
   c                     t                                          |           | j        s6| j                            d          }| j                            |           d S d S )Nz
[pytest-split] No test durations found. Pytest-split will split tests evenly when no durations are found. 
[pytest-split] You can expect better results in consequent runs, when test timings have been documented.
)superrL   rE   r@   markupline)rJ   r,   message	__class__s      r(   rL   zPytestSplitPlugin.__init__   sj       $ 	&k((< G KW%%%%%	& 	&r*   T)trylastitemslist[nodes.Item]r   Nc                 ,   |j         j        }|j         j        }t          j        |j         j                 j        } |||| j                  }||dz
           }t          ||           |j	        |dd<   |j
                            |j                   | j                            | j                            d|j         j                              | j                            | j                            d| d| d|j        dd	                     dS )
zU
        Collect and select the tests we want to run, and deselect the rest.
        r/   N)rZ   z1

[pytest-split] Splitting tests with algorithm: z[pytest-split] Running group /z (estimated duration: z.2fzs)
)r7   r   r   r   r&   r   valuerE   r   selectedhookpytest_deselected
deselectedr@   rV   rU   duration)rJ   r,   rZ   r   	group_idxalgogroupsr   s           r(   pytest_collection_modifyitemsz/PytestSplitPlugin.pytest_collection_modifyitems   s+    m*,	$V]%FGMfeT%:;;y1}%"5%000>aaa%%E,<%===KifmFgii 	
 	
 	

 	Kr	rrFrrZ_Zhrrrr 	
 	
 	
 	
 	
r*   )r,   r
   )r,   r
   rZ   r[   r   N)rN   rO   rP   rL   r   rg   __classcell__)rX   s   @r(   r:   r:      s        
& 
& 
& 
& 
& 
& Xd

'9
	
 
 
 
 
 
 
 
r*   r:   c                       e Zd ZdZddZdS )r;   zB
    The cache plugin writes durations to our durations file.
    r   Nc                 "   | j         j                            d          }i }|j                                        D ]o}|D ]j}t          |t                    rS|j        dk     r#|j        dv r|j        t          k    r=|j
        |vr
d||j
        <   ||j
        xx         |j        z  cc<   kp| j         j        j        rt          |          | _        n$|                                D ]\  }}|| j        |<   t!          | j         j        j        d          5 }t%          j        | j        |dd           ddd           n# 1 swxY w Y   | j                            d	| j         j        j                   }| j                            |           dS )
z
        Method is called by Pytest after the test-suite has run.
        https://github.com/pytest-dev/pytest/blob/main/src/_pytest/main.py#L308
        terminalreporterr   )teardownsetupwT   )	sort_keysindentNz*

[pytest-split] Stored test durations in )r,   r8   
get_pluginstatsvaluesrG   r   rc   when,STORE_DURATIONS_SETUP_AND_TEARDOWN_THRESHOLDnodeidr7   r   rI   rE   rZ   rA   r   rB   dumpr@   rU   rV   )	rJ   terminal_reportertest_durationstest_reportstest_reportkvrK   rW   s	            r(   pytest_sessionfinishz+PytestSplitCachePlugin.pytest_sessionfinish   s   
 !K5@@ASTT+--3::<< 	O 	OL+ O Ok:66 O"+a// #(,AAA'0FG G ! #)??=>{'9:";#5666+:NN666!O$ ;- 	-$($8$8D!!&,,.. - -1+,%a(($+$3S99 	JQId+Q$qIIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J +$$^4;;M;\^^
 
 	!!!!!s   D>>EE)r   N)rN   rO   rP   __doc__r   rQ   r*   r(   r;   r;      s2         '" '" '" '" '" '"r*   r;   )r   r   r   N)r,   r
   r   r-   rM   )"builtins@py_builtins_pytest.assertion.rewrite	assertionrewrite
@pytest_arrB   r    typingr   r1   _pytest.configr   r   _pytest.reportsr   pytest_splitr    pytest_split.ipynb_compatibilityr   _pytestr	   r
   _pytest.config.argparsingr   _pytest.mainr   rv   r)   r3   r<   r>   r:   r;   rQ   r*   r(   <module>r      s                 				              ; ; ; ; ; ; ; ; & & & & & & # # # # # # G G G G G G &%%%%%%000000%%%%%% 07 ,3 3 3 3l $    2

 

 

 

@ @ @ @ @ @ @ @.)
 )
 )
 )
 )
 )
 )
 )
X," ," ," ," ,"T ," ," ," ," ,"r*   