a
    xd5                     @   s4  d dl Z d dlZd dlmZ d dlmZ d dlmZ G dd deZ	e	ddd	Z
e	d
dd	Ze	ddd	Ze	ddd	Ze	ddd	Ze	ddd	Ze	dddZe	dddZe	dddZe	dddZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZd%d& ZG d'd( d(eZG d)d* d*ZG d+d, d,ZdS )-    N)JSONEncoder)BooleanExpression)read_test_timesc                       sL   e Zd ZdZg Zedd Zi Z fddZdd Z	dd	 Z
d
d Z  ZS )
ResultCodezTest result codes.c                   C   s   t jS N)r   
_all_codes r   r   Q/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lit/Test.py	all_codes   s    zResultCode.all_codesc                    s2   | j |}|d u r.tt| |  | j |< }|S r   )
_instancesgetsuperr   __new__)clsnamelabel	isFailureres	__class__r   r	   r      s    zResultCode.__new__c                 C   s   | j | j| jfS r   )r   r   r   selfr   r   r	   __getnewargs__   s    zResultCode.__getnewargs__c                 C   s"   || _ || _|| _tj|  d S r   )r   r   r   r   r   append)r   r   r   r   r   r   r	   __init__!   s    zResultCode.__init__c                 C   s   d| j j| j| jff S )Nz%s%r)r   __name__r   r   r   r   r   r	   __repr__'   s    
zResultCode.__repr__)r   
__module____qualname____doc__r   staticmethodr
   r   r   r   r   r   __classcell__r   r   r   r	   r   
   s   
r   EXCLUDEDZExcludedFSKIPPEDZSkippedUNSUPPORTEDZUnsupportedPASSZPassed	FLAKYPASSzPassed With RetryXFAILzExpectedly Failed
UNRESOLVEDZ
UnresolvedTTIMEOUTz	Timed OutFAILZFailedXPASSzUnexpectedly Passedc                   @   s   e Zd Zdd Zdd ZdS )MetricValuec                 C   s   t ddS )z
        format() -> str

        Convert this metric to a string suitable for displaying as part of the
        console output.
        abstract methodNRuntimeErrorr   r   r   r	   format=   s    zMetricValue.formatc                 C   s   t ddS )z
        todata() -> json-serializable data

        Convert this metric to content suitable for serializing in the JSON test
        output.
        r-   Nr.   r   r   r   r	   todataF   s    zMetricValue.todataN)r   r   r   r0   r1   r   r   r   r	   r,   <   s   	r,   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )IntMetricValuec                 C   s
   || _ d S r   valuer   r4   r   r   r	   r   P   s    zIntMetricValue.__init__c                 C   s
   t | jS r   )strr4   r   r   r   r	   r0   S   s    zIntMetricValue.formatc                 C   s   | j S r   r3   r   r   r   r	   r1   V   s    zIntMetricValue.todataNr   r   r   r   r0   r1   r   r   r   r	   r2   O   s   r2   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )RealMetricValuec                 C   s
   || _ d S r   r3   r5   r   r   r	   r   Z   s    zRealMetricValue.__init__c                 C   s
   d| j  S )Nz%.4fr3   r   r   r   r	   r0   ]   s    zRealMetricValue.formatc                 C   s   | j S r   r3   r   r   r   r	   r1   `   s    zRealMetricValue.todataNr7   r   r   r   r	   r8   Y   s   r8   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	JSONMetricValuez
        JSONMetricValue is used for types that are representable in the output
        but that are otherwise uninterpreted.
    c                 C   s4   zt  }|| W n ty(    Y n0 || _d S r   )r   encode	TypeErrorr4   )r   r4   er   r   r	   r   h   s    zJSONMetricValue.__init__c                 C   s   t ddd}|| jS )N   T)indent	sort_keys)r   r:   r4   r   r<   r   r   r	   r0   s   s    zJSONMetricValue.formatc                 C   s   | j S r   r3   r   r   r   r	   r1   w   s    zJSONMetricValue.todataN)r   r   r   r   r   r0   r1   r   r   r   r	   r9   c   s   r9   c                 C   sj   t | tr| S t | tr t| S t | tr2t| S zt | trHt| W S W n ty\   Y n0 t| S d S r   )	
isinstancer,   intr2   floatr8   long	NameErrorr9   r3   r   r   r	   toMetricValuez   s    



rF   c                   @   s*   e Zd ZdZd
ddZdd Zdd	 ZdS )Resultz8Wrapper for the results of executing an individual test. Nc                 C   s.   || _ || _|| _d | _d | _i | _i | _d S r   )codeoutputelapsedstartpidmetricsmicroResults)r   rI   rJ   rK   r   r   r	   r      s    zResult.__init__c                 C   s>   || j v rtd|f t|ts0td|f || j |< dS )a(  
        addMetric(name, value)

        Attach a test metric to the test result, with the given name and list of
        values. It is an error to attempt to attach the metrics with the same
        name multiple times.

        Each value must be an instance of a MetricValue subclass.
        z&result already includes metrics for %rzunexpected metric value: %rN)rN   
ValueErrorrA   r,   r;   )r   r   r4   r   r   r	   	addMetric   s    


zResult.addMetricc                 C   s>   || j v rtd|f t|ts0td|f || j |< dS )a3  
        addMicroResult(microResult)

        Attach a micro-test result to the test result, with the given name and
        result.  It is an error to attempt to attach a micro-test with the
        same name multiple times.

        Each micro-test result must be an instance of the Result class.
        z*Result already includes microResult for %rzunexpected MicroResult value %rN)rO   rP   rA   rG   r;   )r   r   ZmicroResultr   r   r	   addMicroResult   s    


zResult.addMicroResult)rH   N)r   r   r   r   r   rQ   rR   r   r   r   r	   rG      s   
rG   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )		TestSuitezuTestSuite - Information on a group of tests.

    A test suite groups together a set of logically related tests.
    c                 C   s&   || _ || _|| _|| _t| | _d S r   )r   source_root	exec_rootconfigr   
test_times)r   r   rT   rU   rV   r   r   r	   r      s
    zTestSuite.__init__c                 C   s   t jj| jg|R  S r   )ospathjoinrT   r   
componentsr   r   r	   getSourcePath   s    zTestSuite.getSourcePathc                 C   s   t jj| jg|R  S r   )rX   rY   rZ   rU   r[   r   r   r	   getExecPath   s    zTestSuite.getExecPathN)r   r   r   r   r   r]   r^   r   r   r   r	   rS      s   	rS   c                   @   sz   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )Testz-Test - Information on a single test instance.Nc                 C   s   || _ || _|| _|| _|| _g | _d| _g | _g | _t	|dd| _
d | _d| _d| _|jrd||jv r|jd| }t|| _|dk | _d S )NFZtest_retry_attemptsr   g        /)suitepath_in_suiterV   	file_pathgtest_json_filexfails	xfail_notrequiresunsupportedgetattrZallowed_retriesresultZprevious_failureZprevious_elapsedrW   rZ   abs)r   ra   rb   rV   rc   rd   timer   r   r	   r      s"    
zTest.__init__c              
   C   s   | j d u sJ dt|ts$J dz|  }W n4 tyd } zt|_t||_W Y d }~n0d }~0 0 |r|jt	u r|t
|_n|jtu rt|_|| _ d S )Nzresult already setzunexpected result type)rj   rA   rG   isExpectedToFailrP   r(   rI   r6   rJ   r%   r+   r*   r'   )r   rj   Zexpected_to_failerrr   r   r	   	setResult  s     

zTest.setResultc                 C   s   | j s
J | j jjS r   )rj   rI   r   r   r   r   r	   r     s    
zTest.isFailurec                 C   s   | j jjd d| j S )Nz :: r`   )ra   rV   r   rZ   rb   r   r   r   r	   getFullName"  s    zTest.getFullNamec                 C   s   | j r| j S |  S r   )rc   r]   r   r   r   r	   getFilePath%  s    zTest.getFilePathc                 C   s   | j | jS r   )ra   r]   rb   r   r   r   r	   r]   *  s    zTest.getSourcePathc                 C   s   | j | jS r   )ra   r^   rb   r   r   r   r	   r^   -  s    zTest.getExecPathc                 C   s~   | j r
dS | jj}| jD ]`}|dkr* dS zt||r@W  dS W q tyv } ztdt| W Y d}~qd}~0 0 qdS )a[  
        isExpectedToFail() -> bool

        Check whether this test is expected to fail in the current
        configuration. This check relies on the test xfails property which by
        some test formats may not be computed until the test has first been
        executed.
        Throws ValueError if an XFAIL line has a syntax error.
        F*TzError in XFAIL list:
%sN)rf   rV   available_featuresre   r   evaluaterP   r6   )r   featuresitemr<   r   r   r	   rm   0  s    
(zTest.isExpectedToFailc                    s@    j jsdS   rdS  fdd j jD } |s<dS dS )a  
        isWithinFeatureLimits() -> bool

        A test is within the feature limits set by run_only_tests if
        1. the test's requirements ARE satisfied by the available features
        2. the test's requirements ARE NOT satisfied after the limiting
           features are removed from the available features

        Throws ValueError if a REQUIRES line has a syntax error.
        TFc                    s   g | ]}| j jvr|qS r   )rV   limit_to_features).0fr   r   r	   
<listcomp>c  s   z.Test.isWithinFeatureLimits.<locals>.<listcomp>)rV   rw   getMissingRequiredFeaturesrs   "getMissingRequiredFeaturesFromList)r   ZfeaturesMinusLimitsr   r   r	   isWithinFeatureLimitsO  s    
zTest.isWithinFeatureLimitsc              
      sP   z fdd| j D W S  tyJ } ztdt| W Y d }~n
d }~0 0 d S )Nc                    s   g | ]}t | s|qS r   r   rt   rx   rv   ru   r   r	   rz   l  s   z;Test.getMissingRequiredFeaturesFromList.<locals>.<listcomp>zError in REQUIRES list:
%s)rg   rP   r6   )r   ru   r<   r   r   r	   r|   j  s    z'Test.getMissingRequiredFeaturesFromListc                 C   s   | j j}| |S )z
        getMissingRequiredFeatures() -> list of strings

        Returns a list of features from REQUIRES that are not satisfied."
        Throws ValueError if a REQUIRES line has a syntax error.
        )rV   rs   r|   )r   ru   r   r   r	   r{   q  s    zTest.getMissingRequiredFeaturesc              
      sX   | j j z fdd| jD W S  tyR } ztdt| W Y d}~n
d}~0 0 dS )z
        getUnsupportedFeatures() -> list of strings

        Returns a list of features from UNSUPPORTED that are present
        in the test configuration's features.
        Throws ValueError if an UNSUPPORTED line has a syntax error.
        c                    s   g | ]}t | r|qS r   r~   r   r   r   r	   rz     s   z/Test.getUnsupportedFeatures.<locals>.<listcomp>zError in UNSUPPORTED list:
%sN)rV   rs   rh   rP   r6   r@   r   r   r	   getUnsupportedFeatures|  s
    	zTest.getUnsupportedFeaturesc                    sd   ddl }|jj|  dd d}tj fdd|D }tjdd |D }ttt	j
|}|S )	z
        getUsedFeatures() -> list of strings

        Returns a list of all features appearing in XFAIL, UNSUPPORTED and
        REQUIRES annotations for this test.
        r   NF)Zrequire_script)zUNSUPPORTED:z	REQUIRES:zXFAIL:c                 3   s   | ]} | pg V  qd S r   r   )rx   kparsedr   r	   	<genexpr>  s   z'Test.getUsedFeatures.<locals>.<genexpr>c                 s   s    | ]}|d krt |V  qdS )rr   N)r   tokenize)rx   exprr   r   r	   r     s   )Zlit.TestRunnerZ
TestRunnerZ_parseKeywordsr]   	itertoolschainfrom_iterablesetfilterr   ZisMatchExpression)r   ZlitZfeature_keywordsZboolean_expressionstokensZmatchExpressionsr   r   r	   getUsedFeatures  s    zTest.getUsedFeatures)NN)r   r   r   r   r   ro   r   rp   rq   r]   r^   rm   r}   r|   r{   r   r   r   r   r   r	   r_      s   
-r_   )r   rX   jsonr   Zlit.BooleanExpressionr   Zlit.TestTimesr   objectr   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r2   r8   r9   rF   rG   rS   r_   r   r   r   r	   <module>   s.   #

6