o
    
i                      @   s   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 e
ejdd  d Zdd Zdd	 Zd
d Zdd Zdd ZdddZdS )    )print_functionN)PY3   z/datac                 C   sj   t | ts| g} g }| D ]&}t |tst|}t|D ]}|| }t |tjr1t|dr1|| qq|S )Nunittest)	
isinstancelistdictvarssortedtypesFunctionTypehasattrappend)collections	functions
collectionkeyvalue r   Z/home/ubuntu/.local/lib/python3.10/site-packages/srsly/tests/ruamel_yaml/test_appliance.pyfind_test_functions   s   


r   c                 C   sp   i }t | D ](}t jt j| |r/t j|\}}|tr"dndr&q||g 	| qt
| }|S )Nz-py2z-py3)oslistdirpathisfilejoinsplitextendswithr   
setdefaultr   r
   items)	directory	filenamesfilenamebaseextr   r   r   find_test_filenames    s   r%   c                 C   s   t jdd}|jddddtjv dd |jd	dd
d |jdddd |jdddd || } | j}| jr:| jgng }| j}dtjv rN|	tjd 
  dtjv r]|	tjd 
  |||| fS ) a   run the yaml tests. By default
    all functions on all appropriate test_files are run. Functions have
    unittest attributes that determine the required extensions to filenames
    that need to be available in order to run that test. E.g.


    python test_yaml.py test_constructor_types

    python test_yaml.py --verbose test_tokens spec-02-05


    The presence of an extension in the .skip attribute of a function
    disables the test for that function.)usagez	--verbosez-v
store_trueYAML_TEST_VERBOSEzset verbosity output)actiondefaulthelpz--list-functionszHlist all functions with required file extensions for test files
        )r*   r,   function?zrestrict function to run)nargsr,   r!   *zbasename of filename set, extensions (.code, .data) have to
        be a superset of those in the unittest attribute of the selected
        functionYAML_TEST_FUNCTIONSYAML_TEST_FILENAMES)argparseArgumentParseradd_argumentr   environ
parse_argsverboser-   r!   extendsplit)argsparserr8   include_functionsinclude_filenamesr   r   r   parse_arguments,   s<   


r?   c              
   C   s   t r| j}nt| dr| j}n| j}|r'tjd tjd|d|f  z	| |d|i W n8 t	yh } z,t
 }t|trDd}nd}|rQtjdtjd	 ntj|d
  tj  W Y d }~nd }~ww d}d }|sutjd tj  ||||fS )Nunittest_nameL===========================================================================
z
%s(%s)...
, r8   FAILUREERROR   )limitfiler   SUCCESS.)r   __name__r   r@   	func_namesysstdoutwriter   	Exceptionexc_infor   AssertionError	traceback	print_excflush)r-   r!   r8   nameexcinfokindr   r   r   executej   s6   



rY   c              
   C   s  | r
|s
t jd t| }d}d}| D ]\}}}}|dkrq|dkr'|d7 }|dkr/|d7 }t jd t jd|d	||f  |dkrQtj|d
t ji n1t jd tj|d t jd t jd|d j  t jd |d j	D ]
}	t
j
|	t jd qw|D ][}
t jd t jd|
  trt|
ddd}| }W d    n1 sw   Y  nt|
d}| }W d    n1 sw   Y  t j| |r|d dkrt jd qqt jd t jd|  d}|rt jd|  d}|r
t jd|  d}|S )N
r   rH   rC   rE   rD   rA   z%s(%s): %s
rB   rG   z#Traceback (most recent call last):
r   )rG   z%s: see below
zL~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
)streamzL---------------------------------------------------------------------------
z%s:
rreplace)errorsrbz
TESTS: %s
zFAILURES: %s
zERRORS: %s
)rL   rM   rN   lenr   rR   print_exceptionprint_tbrJ   r;   pprintr   openread)resultsr8   totalfailuresr^   rU   r!   rX   rW   argr"   fpdataret_valr   r   r   display   s`   

rn   c              
   C   s   t | }tt}t|\}}}}|jr(td |D ]}td|j|j qd S g }	|D ]]}
|r6|
j|vr6q,|
jr~|D ]A\}}|rF||vrFq;g }|
jD ]}||vrS n)|	t
jt||  qKt|
dg }|D ]}||v rp nqht|
||}|		| q;q,t|
g |}|		| q,t|	|dS )Nztest functions:z  {:30s} {}skip)r8   )r   r%   DATAr?   list_functionsprintformatrJ   r   r   r   r   r   getattrrY   rn   )r   r;   test_functionstest_filenamesr=   r>   r8   afrg   r-   r#   extsr!   r$   	skip_extsskip_extresultr   r   r   run   sB   

r}   )N)
__future__r   rL   r   r   rR   rd   r3   srsly.ruamel_yaml.compatr   __file__rsplitseprp   r   r%   r?   rY   rn   r}   r   r   r   r   <module>   s    >!0