o
    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rZd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jsonzCan'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   GD:\Projects\ConvertPro\env\Lib\site-packages\jsonschema/tests/_suite.py_find_suite   s   r   c                   @  sN   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Z	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#   	resourcesZliZli4registryr   r   r   __attrs_post_init__7   s0   
zSuite.__attrs_post_init__runnerpyperf.Runnerc                 C  s,   t  D ]\}}| j|dj||d qd S )N)name)r8   	Validator)r   r0   version	benchmark)r3   r8   r:   r;   r   r   r   r=   V   s   zSuite.benchmarkreturnVersionc                 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r8   r9   )r>   r?   )__name__
__module____qualname__r
   r   r   __annotations__r    r7   r=   r<   r   r   r   r   r   1   s   
 
r   c                   @  s^   e Zd ZU ded< ded< ded< dd ZdddZdddZdddZdd ZdddZ	dS )r?   r   _pathr   r    r)   r:   c                 K  s"   |   D ]
}|jdi | qd S Nr   )casesr=   )r3   kwargscaser   r   r   r=   m   s   zVersion.benchmarkr>   Iterable[_Case]c                 C     | j | jddS )Nz*.jsonpaths	_cases_inrH   globr3   r   r   r   rJ   q      zVersion.casesc                 C  rN   )Nzoptional/format/*.jsonrO   rQ   rT   r   r   r   format_casest   rU   zVersion.format_casesc                 C  s   | j | jd | d gdS )Noptionalz.jsonrO   )rR   rH   rB   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    |S 1 s9w   Y  |S )	Nr:   ZTest- c                 S  s   i | ]}|j |qS r   )rD   ).0methodr   r   r   
<dictcomp>|   s    z0Version.to_unittest_testcase.<locals>.<dictcomp>c                 3  s6    | ]}|D ]}|j D ]}|jdi  V  qqqd S rI   )r@   to_unittest_method)r[   grouprL   testrK   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_callerrE   )r3   groupsrK   r:   methodsclsr   ra   r   to_unittest_testcasez   s   
	


zVersion.to_unittest_testcaserP   Iterable[Path]c                 c  s@    |D ]}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   rA   rL   r   r   r   rR      s   
zVersion._cases_inN)r>   rM   )r:   r)   r>   rM   )rP   rm   r>   rM   )
rD   rE   rF   rG   r=   rJ   rV   rX   rl   rR   r   r   r   r   r?   e   s   
 


r?   c                   @  sX   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Zd
S )rq   r?   r<   r)   ro   descriptionMapping[str, Any] | boolschemazlist[_Test]r@   N
str | Nonecommentc                   s6     |  fdd dD }| dd|i S )Nc              
     s6   g | ]}t d d   d  d  d d|qS )r<   ro   rt   rv   )r<   ro   case_descriptionrv   r#   r   )_Test)r[   r`   datar#   r   r   
<listcomp>   s    z#_Case.from_dict.<locals>.<listcomp>r@   r   )updater/   )rk   r|   r#   rK   r@   r   r{   r   rr      s
   

z_Case.from_dictr8   r9   c                 K  s,   | j D ]}||jt|jfi | qd S N)r@   Z
bench_funcfully_qualified_namer   validate_ignoring_errors)r3   r8   rK   r`   r   r   r   r=      s   
z_Case.benchmarkrC   )rD   rE   rF   rG   rx   classmethodrr   r=   r   r   r   r   rq      s   
 
rq   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 )rz   r?   r<   r)   ro   ry   rt   r	   r|   ru   rv   boolvalidr   r    Nrw   rx   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:   ro   ry   rt   rT   r   r   r   r      s   z_Test.fully_qualified_namec                 C  s   d S r   r   )r`   r   r   r   <lambda>   s    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 s<tj	
dddkr>|S tj	
dddkrLt|S t||S )	Nc                   s   j di   d S rI   )validatethisrK   r3   r   r   fn   rU   z$_Test.to_unittest_method.<locals>.fnc                   sB   |  tj jdi   W d    d S 1 sw   Y  d S rI   )assertRaisesr   ValidationErrorr   r   r   r   r   r      s   "_r`   JSON_SCHEMA_DEBUG0ZJSON_SCHEMA_EXPECTED_FAILURES)r   r   _DELIMITERSsubro   ry   rt   rD   r   r   r   rf   ZexpectedFailureskip)r3   r   rK   r   reasonr   r   r   r^      s    
z_Test.to_unittest_methodc                 K  sN   | | j |d| j| jd|}tjdddkrt  |j| jd d S )N)rv   r6   r   r   )instancer   )	Zcheck_schemarv   r    r   r   r   
breakpointr   r|   )r3   r;   rK   	validatorr   r   r   r      s   z_Test.validatec                 C  s<   t tj | j|d W d    d S 1 sw   Y  d S )N)r;   )r   r   r   r   )r3   r;   r   r   r   r      s   "z_Test.validate_ignoring_errors)rD   rE   rF   rG   rx   r   propertyr   r^   r   r   r   r   r   r   rz      s    
 

rz   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.
       rD   )r'   	_getframe	f_globalsr   r   r   r   rh     s   rh   )'__doc__
__future__r   collections.abcr   r   
contextlibr   	functoolsr   pathlibr   typingr   r	   r   r   rer*   r'   rf   attrsr
   r   r.   r   Zreferencing.jsonschemaZpyperfZjsonschema.validatorsr   r   compiler   r   r   r?   rq   rz   rh   r   r   r   r   <module>   s>    
34!H