o
    >�Ò]H  ã                   @   sÞ   d Z 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
 ddlZddlmZ ddlmZ ddlZdd„ Zejd	d
�G dd„ deƒƒZejd	d
�G dd„ deƒƒZejd	dd�G dd„ deƒƒZdd„ ZdS )z=
Python representations of the JSON Schema Test Suite tests.
é    )ÚpartialN)ÚFilePath)ÚPY3)Ú
validatorsc                  C   sD   t j d¡} | d urt| ƒS ttjƒ ¡  d¡} |  ¡ s t	dƒ‚| S )NÚ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ÚsiblingÚisdirÚ
ValueError)Úroot© r   ú9/usr/lib/python3/dist-packages/jsonschema/tests/_suite.pyÚ_find_suite   s   þr   T)Úhashc                   @   s6   e Zd Zeje e¡d�Zdd„ Zdd„ Z	dd„ Z
dS )	ÚSuite)Údefaultc                 C   sB   | j  ddg¡}t tj|jdg¡}dd„ t | 	d¡¡ 
¡ D ƒS )NÚbinÚjsonschema_suiteÚremotesc                 S   s   i | ]	\}}d | |“qS )zhttp://localhost:1234/r   )Ú.0ÚnameÚschemar   r   r   Ú
<dictcomp>1   s    ÿÿz"Suite._remotes.<locals>.<dictcomp>úutf-8)Ú_rootÚ
descendantÚ
subprocessÚcheck_outputÚsysÚ
executableÚpathr   ÚloadsÚdecodeÚitems)Úselfr   r   r   r   r   Ú_remotes,   s   ÿþzSuite._remotesc                 C   s"   t D ]}| j|d�j|d� qd S )N)r   )Úrunner)r   ÚversionÚ	benchmark)r*   r,   r   r   r   r   r.   6   s   ÿzSuite.benchmarkc                 C   s   t || j d|g¡|  ¡ d�S )NÚtests)r   r&   r   )ÚVersionr    r!   r+   ©r*   r   r   r   r   r-   :   s
   ýzSuite.versionN)Ú__name__Ú
__module__Ú__qualname__ÚattrÚibÚFactoryr   r    r+   r.   r-   r   r   r   r   r   '   s
    
r   c                   @   s\   e Zd Ze ¡ Ze ¡ Ze ¡ Zdd„ Zdd„ Z	dd„ Z
dd„ Zd	d
„ Zdd„ Zdd„ ZdS )r0   c              	   K   s8   |   ¡ D ]}|D ]}| |jt|jfi |¤Ž¡ qqd S ©N)r/   Ú
bench_funcÚfully_qualified_namer   Úvalidate_ignoring_errors)r*   r,   ÚkwargsÚsuiteÚtestr   r   r   r.   J   s   þÿÿzVersion.benchmarkc                    s   ‡ fdd„ˆ j  d¡D ƒS )Nc                 3   ó4   � | ]}ˆ j | ¡ d d… |d�D ]}|V  qqd S ©Néûÿÿÿ©Úsubjectr&   ©Ú	_tests_inÚbasename©r   Úchildr>   ©r*   r   r   Ú	<genexpr>S   ó   € þýþÿz Version.tests.<locals>.<genexpr>ú*.json)Ú_pathÚglobChildrenrI   r   rI   r   r/   R   s   

þzVersion.testsc                    s(   ˆ j  ddg¡}‡ fdd„| d¡D ƒS )NÚoptionalÚformatc                 3   r?   r@   rD   rG   rI   r   r   rJ   ^   rK   z'Version.format_tests.<locals>.<genexpr>rL   )rM   r!   rN   )r*   r&   r   rI   r   Úformat_tests\   s   
þzVersion.format_testsc                 C   s   | j || j |d ¡d�S )Nú.jsonrB   )rE   rM   rH   r1   r   r   r   Útests_ofg   s   þzVersion.tests_ofc                 C   s   | j || j d|d g¡d�S )NrO   rR   rB   )rE   rM   r!   r1   r   r   r   Úoptional_tests_ofm   s   þzVersion.optional_tests_ofc                    s\   ˆ   dd| j ¡  ¡}‡ fdd„|D ƒ}t|tjf|ƒ}ztƒ |_W |S  ty-   Y |S w )Nr   ÚTestc              	      s4   i | ]}|D ]}|D ]}|j |jd i ˆ ¤Ž“q
qqS )r   )Úmethod_nameÚto_unittest_method)r   r=   r/   r>   ©r<   r   r   r   u   s    ýüý
ÿz0Version.to_unittest_testcase.<locals>.<dictcomp>)	Úpopr   ÚtitleÚtypeÚunittestÚTestCaseÚ)_someone_save_us_the_module_of_the_callerr3   Ú	Exception)r*   Úsuitesr<   r   ÚmethodsÚclsr   rX   r   Úto_unittest_testcases   s   
þ
úúzVersion.to_unittest_testcasec                 #   s<   � t  | ¡  d¡¡D ]‰ ‡ ‡‡fdd„ˆ d D ƒV  qd S )Nr   c              	   3   s4   � | ]}t dˆˆˆ d  ˆ d ˆjdœ|¤ŽV  qdS )Údescriptionr   )r-   rC   Úcase_descriptionr   r   Nr   )Ú_Testr+   )r   r>   ©Úeachr*   rC   r   r   rJ   ‰   s   € ùûú
ÿz$Version._tests_in.<locals>.<genexpr>r/   )r   r'   Ú
getContentr(   )r*   rC   r&   r   rg   r   rE   ‡   s   €
øÿzVersion._tests_inN)r2   r3   r4   r5   r6   rM   r+   r   r.   r/   rQ   rS   rT   rc   rE   r   r   r   r   r0   B   s    
r0   F)r   Úreprc                   @   s�   e Zd Ze ¡ Ze ¡ Ze ¡ Ze ¡ Ze ¡ Z	ejdd�Z
e ¡ Ze ¡ Zdd„ Zedd„ ƒZedd„ ƒZd	d
„ fdd„Zdd„ Zdd„ ZdS )rf   F)rj   c                 C   s   d  | j¡S )Nz	<Test {}>)rP   r:   rI   r   r   r   Ú__repr__¥   s   z_Test.__repr__c                 C   s   d  | jj| j| j| jg¡S )Nz > )Újoinr-   r   rC   re   rd   rI   r   r   r   r:   ¨   s   üÿz_Test.fully_qualified_namec                 C   sH   d}dt  |d| j¡t  |d| j¡t  |d| j¡f }ts"| d¡}|S )Nz[\W\- ]+ztest_%s_%s_%sÚ_r   )ÚreÚsubrC   re   rd   r   Úencode)r*   Ú
delimitersr   r   r   r   rV   ³   s   ý
z_Test.method_namec                 C   s   d S r8   r   )r>   r   r   r   Ú<lambda>À   s    z_Test.<lambda>c                    sH   ˆj r‡ ‡fdd„}n‡ ‡fdd„}ˆj|_|ˆƒ}t |d u|¡|ƒS )Nc                    s   ˆj di ˆ ¤Ž d S ©Nr   )Úvalidate©Úthis©r<   r*   r   r   ÚfnÂ   s   z$_Test.to_unittest_method.<locals>.fnc                    sB   |   tj¡� ˆjdi ˆ ¤Ž W d   ƒ d S 1 sw   Y  d S rs   )ÚassertRaisesr   ÚValidationErrorrt   ru   rw   r   r   rx   Å   s   "ÿ)ÚvalidrV   r2   r\   ÚskipIf)r*   Úskipr<   rx   Úreasonr   rw   r   rW   À   s   z_Test.to_unittest_methodc                 K   s:   t jj| j| j|jd�}t jd| j| j||dœ|¤Ž d S )N)r   ÚstoreÚid_of)Úinstancer   rb   Úresolverr   )r   ÚRefResolverÚfrom_schemar   r+   ÚID_OFrt   Údata)r*   Ú	Validatorr<   r‚   r   r   r   rt   Í   s   ýü
ûz_Test.validatec                 C   s*   z	| j |d� W d S  tjy   Y d S w )N)r‡   )rt   r   rz   )r*   r‡   r   r   r   r;   Û   s
   ÿz_Test.validate_ignoring_errorsN)r2   r3   r4   r5   r6   r-   rC   re   rd   r†   r   r{   r+   rk   Úpropertyr:   rV   rW   rt   r;   r   r   r   r   rf   •   s"    


rf   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 dynamicallly 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.
    é   r2   )r$   Ú	_getframeÚ	f_globalsr   r   r   r   r^   â   s   r^   )Ú__doc__Ú	functoolsr   r   r   rn   r"   r$   r\   Útwisted.python.filepathr   r5   Újsonschema.compatr   Újsonschema.validatorsr   r   r   ÚsÚobjectr   r0   rf   r^   r   r   r   r   Ú<module>   s*    

RL