o
    tf                     @  s8  d Z ddl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mZmZmZ 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)suppress)partial)Path)TYPE_CHECKINGAnyN)fieldfrozen)Registry)IterableMappingSequence)_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   `/var/www/html/software/conda/envs/catlas/lib/python3.10/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__8   s0   
zSuite.__attrs_post_init__runnerpyperf.Runnerc                 C  s,   t  D ]\}}| j|dj||d qd S )N)name)r9   	Validator)r   r1   version	benchmark)r4   r9   r;   r<   r   r   r   r>   W   s   zSuite.benchmarkreturnVersionc                 C  s   t || jd | | jdS )Ntests)r;   pathr$   )r@   r   r!   r4   r;   r   r   r   r=   ^   s
   zSuite.versionNr9   r:   )r?   r@   )__name__
__module____qualname__r   r   r   __annotations__r!   r8   r>   r=   r   r   r   r   r   2   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>   )r4   kwargscaser   r   r   r>   n   s   zVersion.benchmarkr?   Iterable[_Case]c                 C     | j | jddS )Nz*.jsonpaths	_cases_inrI   globr4   r   r   r   rK   r      zVersion.casesc                 C  rO   )Nzoptional/format/*.jsonrP   rR   rU   r   r   r   format_casesu   rV   zVersion.format_casesc                 C  s   | j | jd | d gdS )Noptionalz.jsonrP   )rS   rI   rC   r   r   r   optional_cases_ofx   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   )rE   ).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 rJ   )rA   to_unittest_method)r\   grouprM   testrL   r   r   	<genexpr>   s    z/Version.to_unittest_testcase.<locals>.<genexpr>)r0   r;   titlereplacetypeunittestZTestCaser   	Exception)_someone_save_us_the_module_of_the_callerrF   )r4   groupsrL   r;   methodsclsr   rb   r   to_unittest_testcase{   s   
	


zVersion.to_unittest_testcaserQ   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!   )r4   rQ   rB   rM   r   r   r   rS      s   
zVersion._cases_inN)r?   rN   )r;   r*   r?   rN   )rQ   rn   r?   rN   )
rE   rF   rG   rH   r>   rK   rW   rY   rm   rS   r   r   r   r   r@   f   s   
 


r@   c                   @  sd   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< dZded< edd ZdddZd
S )rr   r@   r=   r*   rp   descriptionMapping[str, Any] | boolschemazlist[_Test]rA   N
str | Nonecommentr   zSequence[dict[str, str]]specificationc                   s6     |  fdd dD }| dd|i S )Nc              
     s6   g | ]}t d d   d  d  d d|qS )r=   rp   ru   rw   )r=   rp   case_descriptionrw   r$   r   )_Test)r\   ra   datar$   r   r   
<listcomp>   s    z#_Case.from_dict.<locals>.<listcomp>rA   r   )updater0   )rl   r~   r$   rL   rA   r   r}   r   rs      s
   

z_Case.from_dictr9   r:   c                 K  s,   | j D ]}||jt|jfi | qd S N)rA   Z
bench_funcfully_qualified_namer   validate_ignoring_errors)r4   r9   rL   ra   r   r   r   r>      s   
z_Case.benchmarkrD   )	rE   rF   rG   rH   ry   rz   classmethodrs   r>   r   r   r   r   rr      s   
 
rr   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 )r|   r@   r=   r*   rp   r{   ru   r   r~   rv   rw   boolvalidr    r!   Nrx   ry   c                 C  s   d| j  dS )Nz<Test >)r   rU   r   r   r   __repr__   s   z_Test.__repr__c                 C  s   d | jj| j| j| jgS )Nz > )joinr=   r;   rp   r{   ru   rU   r   r   r   r      s   z_Test.fully_qualified_namec                 C  s   d S r   r   )ra   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 rJ   )validatethisrL   r4   r   r   fn   rV   z$_Test.to_unittest_method.<locals>.fnc                   sB   |  tj jdi   W d    d S 1 sw   Y  d S rJ   )assertRaisesr   ValidationErrorr   r   r   r   r   r      s   "_ra   JSON_SCHEMA_DEBUG0ZJSON_SCHEMA_EXPECTED_FAILURES)r   r   _DELIMITERSsubrp   r{   ru   rE   r   r   r   rg   ZexpectedFailureskip)r4   r   rL   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)rw   r7   r   r   )instancer   )	Zcheck_schemarw   r!   r   r   r   
breakpointr   r~   )r4   r<   rL   	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   )r4   r<   r   r   r   r     s   "z_Test.validate_ignoring_errors)rE   rF   rG   rH   ry   r   propertyr   r_   r   r   r   r   r   r   r|      s    
 

r|   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.
       rE   )r(   	_getframe	f_globalsr   r   r   r   ri     s   ri   )(__doc__
__future__r   
contextlibr   	functoolsr   pathlibr   typingr   r   r   r   rer+   r(   rg   attrsr   r	   r/   r
   Zreferencing.jsonschemacollections.abcr   r   r   ZpyperfZjsonschema.validatorsr   r   compiler   r   r   r@   rr   r|   ri   r   r   r   r   <module>   s>    
34"H