o
    h                     @  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 )N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   K/var/www/vscode/kcb/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)default_specificationr"   )r   joinpathsys
executablestr
subprocesscheck_outputdecoder   loadsr
   with_resourcesreferencingr   DRAFT7create_resourcepopDRAFT4with_contentsitemsDRAFT202012object__setattr__)selfr$   argvr%   	resourcesli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)rC   	Validator)r   r8   version	benchmark)r<   rC   rE   rF   r   r   r   rH   W   s   zSuite.benchmarkreturnVersionc                 C  s   t || jd | | jdS )Ntests)rE   pathr%   )rJ   r   r"   r<   rE   r   r   r   rG   ^   s
   zSuite.versionNrC   rD   )rI   rJ   )__name__
__module____qualname__r   r   r   __annotations__r"   rB   rH   rG   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 )rJ   r   _pathr!   r"   r,   rE   c                 K  s"   |   D ]
}|jdi | qd S Nr   )casesrH   )r<   kwargscaser   r   r   rH   n   s   zVersion.benchmarkrI   Iterable[_Case]c                 C     | j | jddS )Nz*.jsonpaths	_cases_inrS   globr<   r   r   r   rU   r      zVersion.casesc                 C  rY   )Nzoptional/format/*.jsonrZ   r\   r_   r   r   r   format_casesu   r`   zVersion.format_casesc                 C  s   | j | jd | d gdS )Noptionalz.jsonrZ   )r]   rS   rM   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 )	NrE   Test- c                 S  s   i | ]}|j |qS r   )rO   ).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 rT   )rK   to_unittest_method)rg   grouprW   testrV   r   r   	<genexpr>   s    z/Version.to_unittest_testcase.<locals>.<genexpr>)r5   rE   titlereplacetypeunittestTestCaser   	Exception)_someone_save_us_the_module_of_the_callerrP   )r<   groupsrV   rE   methodsclsr   rm   r   to_unittest_testcase{   s   
	


zVersion.to_unittest_testcaser[   Iterable[Path]c                 c  s@    |D ]}t |jddD ]}tj|| |j| jdV  qqd S )Nr&   )encoding)rG   subjectr%   )r   r0   	read_text_Case	from_dictstemr"   )r<   r[   rL   rW   r   r   r   r]      s   
zVersion._cases_inN)rI   rX   )rE   r,   rI   rX   )r[   rz   rI   rX   )
rO   rP   rQ   rR   rH   rU   ra   rc   ry   r]   r   r   r   r   rJ   f   s   
 


rJ   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 )r~   rJ   rG   r,   r|   descriptionMapping[str, Any] | boolschemazlist[_Test]rK   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 )rG   r|   r   r   )rG   r|   case_descriptionr   r%   r   )_Test)rg   rl   datar%   r   r   
<listcomp>   s    z#_Case.from_dict.<locals>.<listcomp>rK   r   )updater5   )rx   r   r%   rV   rK   r   r   r   r      s
   

z_Case.from_dictrC   rD   c                 K  s,   | j D ]}||jt|jfi | qd S N)rK   
bench_funcfully_qualified_namer   validate_ignoring_errors)r<   rC   rV   rl   r   r   r   rH      s   
z_Case.benchmarkrN   )	rO   rP   rQ   rR   r   r   classmethodr   rH   r   r   r   r   r~      s   
 
r~   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   rJ   rG   r,   r|   r   r   r   r   r   r   boolvalidr!   r"   Nr   r   c                 C  s   d| j  dS )Nz<Test >)r   r_   r   r   r   __repr__   s   z_Test.__repr__c                 C  s   d | jj| j| j| jgS )Nz > )joinrG   rE   r|   r   r   r_   r   r   r   r      s   z_Test.fully_qualified_namec                 C  s   d S r   r   )rl   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 rT   )validatethisrV   r<   r   r   fn   r`   z$_Test.to_unittest_method.<locals>.fnc                   sB   |  tj jdi   W d    d S 1 sw   Y  d S rT   )assertRaisesr   ValidationErrorr   r   r   r   r   r      s   "_rl   JSON_SCHEMA_DEBUG0JSON_SCHEMA_EXPECTED_FAILURES)r   r   _DELIMITERSsubr|   r   r   rO   r   r   r   rr   expectedFailureskip)r<   r   rV   r   reasonr   r   r   rj      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)r   rA   r   r   )instancer   )	check_schemar   r"   r   r   r   
breakpointr   r   )r<   rF   rV   	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)rF   )r   r   r   r   )r<   rF   r   r   r   r     s   "z_Test.validate_ignoring_errors)rO   rP   rQ   rR   r   r   propertyr   rj   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.
       rO   )r*   	_getframe	f_globalsr   r   r   r   ru     s   ru   )(__doc__
__future__r   
contextlibr   	functoolsr   pathlibr   typingr   r   r   r   rer-   r*   rr   attrsr   r	   r2   r
   referencing.jsonschemacollections.abcr   r   r   pyperfjsonschema.validatorsr   r   compiler   r   r   rJ   r~   r   ru   r   r   r   r   <module>   s>    
34"H