a
    �Ï?e~  ã                   @  s4  d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ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mZ dd
lmZ ddlZer´ddlZddlmZ ddlZe d¡Z dd„ Z!eG dd„ dƒƒZ"eG dd„ dƒƒZ#eG dd„ dƒƒZ$edd�G dd„ dƒƒZ%dd„ Z&dS )z=
Python representations of the JSON Schema Test Suite tests.
é    )Úannotations)ÚIterableÚMapping)Úsuppress)Úpartial)ÚPath)ÚTYPE_CHECKINGÚAnyN)ÚfieldÚfrozen)ÚRegistry)Ú_VALIDATORSz[\W\- ]+c                  C  sB   t j d¡} | d urt| ƒS ttjƒjjd } |  ¡ s>tdƒ‚| S )NZJSON_SCHEMA_TEST_SUITEÚjsonzŸCan't find the JSON-Schema-Test-Suite directory. Set the 'JSON_SCHEMA_TEST_SUITE' environment variable or run the tests from alongside a checkout of the suite.)	ÚosÚenvironÚgetr   Ú
jsonschemaÚ__file__ÚparentÚis_dirÚ
ValueError)Úroot© r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jsonschema/tests/_suite.pyÚ_find_suite   s    þr   c                   @  sV   e Zd ZU eed�Zded< edd�Zded< dd	„ Zd
dœdd„Z	ddœdd„Z
dS )ÚSuite)Úfactoryr   Ú_rootF)Úinitú%referencing.jsonschema.SchemaRegistryÚ_remotesc                 C  s    | j  dd¡}tjt|ƒdg}t |¡ d¡}t 	|¡}d}d}t
ƒ  |tjjj| |¡d�f|tjjj| |¡d�fg¡j| ¡ tjjd�}t | d	|¡ d S )
NÚbinÚjsonschema_suiteÚremotesúutf-8z?http://localhost:1234/locationIndependentIdentifierPre2019.jsonz>http://localhost:1234/locationIndependentIdentifierDraft4.json)Úcontents)Zdefault_specificationr    )r   ÚjoinpathÚsysÚ
executableÚstrÚ
subprocessÚcheck_outputÚdecoder   Úloadsr   Zwith_resourcesÚreferencingr   ZDRAFT7Zcreate_resourceÚpopZDRAFT4Zwith_contentsÚitemsZDRAFT202012ÚobjectÚ__setattr__)Úselfr"   Úargvr#   Ú	resourcesÚliZli4Úregistryr   r   r   Ú__attrs_post_init__7   s.    
ÿþÿþùÿïzSuite.__attrs_post_init__úpyperf.Runner©Úrunnerc                 C  s,   t  ¡ D ]\}}| j|d�j||d� qd S )N)Úname)r;   Ú	Validator)r   r0   ÚversionÚ	benchmark)r3   r;   r<   r=   r   r   r   r?   V   s
    þzSuite.benchmarkÚVersion©Úreturnc                 C  s   t || jd | | jd�S )NÚtests)r<   Úpathr#   )r@   r   r    ©r3   r<   r   r   r   r>   ]   s
    ýzSuite.versionN)Ú__name__Ú
__module__Ú__qualname__r
   r   r   Ú__annotations__r    r8   r?   r>   r   r   r   r   r   1   s
   
r   c                   @  sr   e Zd ZU ded< ded< ded< dd„ Zd	d
œdd„Zd	d
œdd„Zdd	dœdd„Zdd„ Zdd	dœdd„Z	dS )r@   r   Ú_pathr   r    r)   r<   c                 K  s"   |   ¡ D ]}|jf i |¤Ž qd S ©N)Úcasesr?   )r3   ÚkwargsÚcaser   r   r   r?   m   s    zVersion.benchmarkzIterable[_Case]rA   c                 C  s   | j | j d¡d�S )Nz*.json©Úpaths©Ú	_cases_inrJ   Úglob©r3   r   r   r   rL   q   s    zVersion.casesc                 C  s   | j | j d¡d�S )Nzoptional/format/*.jsonrO   rQ   rT   r   r   r   Úformat_casest   s    zVersion.format_cases)r<   rB   c                 C  s   | j | jd |› d� gd�S )NÚoptionalz.jsonrO   )rR   rJ   rE   r   r   r   Úoptional_cases_ofw   s    zVersion.optional_cases_ofc                   s~   ˆ   dd| j ¡  dd¡ ¡}dd„ ‡ fdd„|D ƒD ƒ}t|tjf|ƒ}ttƒ� t	ƒ |_
W d   ƒ n1 sp0    Y  |S )	Nr<   ZTestú-Ú c                 S  s   i | ]}|j |“qS r   )rF   )Ú.0Úmethodr   r   r   Ú
<dictcomp>|   s   ÿz0Version.to_unittest_testcase.<locals>.<dictcomp>c                 3  s4   | ],}|D ]"}|j D ]}|jf i ˆ ¤ŽV  qq
qd S rK   )rC   Úto_unittest_method)rZ   ÚgrouprN   Útest©rM   r   r   Ú	<genexpr>~   s   
ýz/Version.to_unittest_testcase.<locals>.<genexpr>)r/   r<   ÚtitleÚreplaceÚtypeÚunittestZTestCaser   Ú	ExceptionÚ)_someone_save_us_the_module_of_the_callerrG   )r3   ÚgroupsrM   r<   ÚmethodsÚclsr   r`   r   Úto_unittest_testcasez   s    
þþ	
&zVersion.to_unittest_testcasezIterable[Path])rP   rB   c                 c  s>   |D ]4}t  |jdd�¡D ]}tj|| |j| jd�V  qqd S )Nr$   )Úencoding)r>   Úsubjectr#   )r   r-   Ú	read_textÚ_CaseÚ	from_dictÚstemr    )r3   rP   rD   rN   r   r   r   rR   �   s    üzVersion._cases_inN)
rF   rG   rH   rI   r?   rL   rU   rW   rk   rR   r   r   r   r   r@   e   s   
r@   c                   @  s\   e Zd ZU ded< ded< ded< ded< ded	< d
Zded< edd„ ƒZddœdd„Zd
S )ro   r@   r>   r)   rm   ÚdescriptionúMapping[str, Any] | boolÚschemazlist[_Test]rC   Nú
str | NoneÚcommentc                   s6   ˆ   |¡ ‡ ‡fdd„ˆ  d¡D ƒ}| f d|iˆ ¤ŽS )Nc              
     s6   g | ].}t f ˆ d  ˆ d ˆ d ˆ d ˆdœ|¤Ž‘qS )r>   rm   rr   rt   )r>   rm   Úcase_descriptionrt   r#   )Ú_Test)rZ   r_   ©Údatar#   r   r   Ú
<listcomp>¨   s   ùûúz#_Case.from_dict.<locals>.<listcomp>rC   )Úupdater/   )rj   rz   r#   rM   rC   r   ry   r   rp   ¥   s
    
ø
z_Case.from_dictr9   r:   c                 K  s,   | j D ] }| |jt|jfi |¤Ž¡ qd S rK   )rC   Z
bench_funcÚfully_qualified_namer   Úvalidate_ignoring_errors)r3   r;   rM   r_   r   r   r   r?   ´   s
    
þz_Case.benchmark)rF   rG   rH   rI   rv   Úclassmethodrp   r?   r   r   r   r   ro   š   s   

ro   F)Úreprc                   @  sŽ   e Zd ZU ded< ded< ded< ded< ded< d	ed
< ded< ded< dZded< dd„ Zedd„ ƒZdd„ fdd„Zdd„ Z	dd„ Z
dS )rx   r@   r>   r)   rm   rw   rr   r	   rz   rs   rt   ÚboolÚvalidr   r    Nru   rv   c                 C  s   d| j › d�S )Nz<Test ú>)r}   rT   r   r   r   Ú__repr__Î   s    z_Test.__repr__c                 C  s   d  | jj| j| j| jg¡S )Nz > )Újoinr>   r<   rm   rw   rr   rT   r   r   r   r}   Ñ   s    üÿz_Test.fully_qualified_namec                 C  s   d S rK   r   )r_   r   r   r   Ú<lambda>Ü   ó    z_Test.<lambda>c              	     sª   ˆj r‡ ‡fdd„}n‡ ‡fdd„}d dt dˆj¡t dˆj¡t dˆj¡g¡|_|ˆƒ}|d u sxtj	 
dd¡dkr||S tj	 
dd¡dkr˜t |¡S t |¡|ƒS d S )	Nc                   s   ˆj f i ˆ ¤Ž d S rK   )Úvalidate©Úthis©rM   r3   r   r   ÚfnÞ   s    z$_Test.to_unittest_method.<locals>.fnc                   s@   |   tj¡�  ˆjf i ˆ ¤Ž W d   ƒ n1 s20    Y  d S rK   )ÚassertRaisesr   ÚValidationErrorrˆ   r‰   r‹   r   r   rŒ   á   s    Ú_r_   ÚJSON_SCHEMA_DEBUGÚ0ZJSON_SCHEMA_EXPECTED_FAILURES)r‚   r…   Ú_DELIMITERSÚsubrm   rw   rr   rF   r   r   r   re   ZexpectedFailureÚskip)r3   r”   rM   rŒ   Úreasonr   r‹   r   r]   Ü   s     üÿ
z_Test.to_unittest_methodc                 K  sN   |  | j¡ |f | j| jdœ|¤Ž}tj dd¡dkr<tƒ  |j| jd� d S )N)rt   r7   r�   r‘   )Úinstance)	Zcheck_schemart   r    r   r   r   Ú
breakpointrˆ   rz   )r3   r=   rM   Z	validatorr   r   r   rˆ   õ   s    þýz_Test.validatec                 C  s:   t tjƒ� | j|d� W d   ƒ n1 s,0    Y  d S )N)r=   )r   r   rŽ   rˆ   )r3   r=   r   r   r   r~      s    z_Test.validate_ignoring_errors)rF   rG   rH   rI   rv   r„   Úpropertyr}   r]   rˆ   r~   r   r   r   r   rx   ¼   s   


rx   c                   C  s   t  d¡jd S )a‡  
    The FQON of the module 2nd stack frames up from here.

    This is intended to allow us to dynamically return test case classes that
    are indistinguishable from being defined in the module that wants them.

    Otherwise, trial will mis-print the FQON, and copy pasting it won't re-run
    the class that really is running.

    Save us all, this is all so so so so so terrible.
    é   rF   )r'   Ú	_getframeÚ	f_globalsr   r   r   r   rg     s    rg   )'Ú__doc__Ú
__future__r   Úcollections.abcr   r   Ú
contextlibr   Ú	functoolsr   Úpathlibr   Útypingr   r	   r   r   Úrer*   r'   re   Úattrsr
   r   r.   r   Zreferencing.jsonschemaZpyperfZjsonschema.validatorsr   r   Úcompiler’   r   r   r@   ro   rx   rg   r   r   r   r   Ú<module>   s<   
34!H