
    g                       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j@                  d      Z!d Z"e G d d             Z#e G d d             Z$e G d d             Z% ed       G d d             Z&d Z'y)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                     t         j                  j                  d      } | t        |       S t        t        j
                        j                  j                  dz  } | j                         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)roots    L/var/www/openai/venv/lib/python3.12/site-packages/jsonschema/tests/_suite.py_find_suiter       sh    ::>>23DDz
##$++22V;D;;= 
 	
 K    c                  \    e Zd ZU  ee      Zded<    ed      Zded<   d Zdd	Z	dd
Z
y)Suite)factoryr   _rootF)init%referencing.jsonschema.SchemaRegistry_remotesc           	        | j                   j                  dd      }t        j                  t	        |      dg}t        j                  |      j                  d      }t        j                  |      }d}d}t               j                  |t        j                  j                  j                  |j!                  |            f|t        j                  j"                  j                  |j!                  |            fg      j%                  |j'                         t        j                  j(                        }t*        j-                  | d	|       y )
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registrys           r   __attrs_post_init__zSuite.__attrs_post_init__8   s'   ::..u6HI$4 5yA))$/66w?JJw'	NN:,, **11AA!*r!2 B  **11AA!*s!3 B 
 -OO"-"8"8"D"D  
 	& 	4X6r   c                    t        j                         D ](  \  }}| j                  |      j                  ||       * y )N)name)runner	Validator)r   r<   version	benchmark)r@   rI   rH   rJ   s       r   rL   zSuite.benchmarkW   s=    *002OD)LLdL#--# .   3r   c                R    t        || j                  dz  |z  | j                        S )Ntests)rH   pathr)   )Versionr"   r%   r@   rH   s     r   rK   zSuite.version^   s*    g%,MM
 	
r   NrI   zpyperf.Runner)returnrP   )__name__
__module____qualname__r	   r   r"   __annotations__r%   rF   rL   rK    r   r   r    r    2   s2     ,E4,6;6GH3G7>
r   r    c                  X    e Zd ZU ded<   ded<   ded<   d ZddZdd	Zdd
Zd ZddZ	y)rP   r   _pathr$   r%   r0   rH   c                R    | j                         D ]  } |j                  di |  y NrX   )casesrL   )r@   kwargscases      r   rL   zVersion.benchmarkn   s#    JJLDDNN$V$ !r   c                X    | j                  | j                  j                  d            S )Nz*.jsonpaths	_cases_inrZ   globr@   s    r   r]   zVersion.casesr   s     ~~DJJOOH$=~>>r   c                X    | j                  | j                  j                  d            S )Nzoptional/format/*.jsonra   rc   rf   s    r   format_caseszVersion.format_casesu   s!    ~~DJJOO4L$M~NNr   c                N    | j                  | j                  dz  | dz  g      S )Noptionalz.jsonra   )rd   rZ   rQ   s     r   optional_cases_ofzVersion.optional_cases_ofx   s*    ~~TZZ*%<$u~%M$N~OOr   c                r   j                  dd| j                  j                         j                  dd      z         }fd|D        D ci c]  }|j                  | }}t        |t        j                  f|      }t        t              5  t               |_        d d d        |S c c}w # 1 sw Y   |S xY w)NrH   Test- c              3  r   K   | ].  }|D ]'  }|j                   D ]  } |j                  di   ) 0 y wr\   )rN   to_unittest_method).0groupr_   testr^   s       r   	<genexpr>z/Version.to_unittest_testcase.<locals>.<genexpr>   sI      #E!D JJD (''1&1 ' 2! 2#s   47)r9   rH   titlereplacerT   typeunittestTestCaser   	Exception)_someone_save_us_the_module_of_the_callerrU   )r@   groupsr^   rH   methodmethodsclss     `    r   to_unittest_testcasezVersion.to_unittest_testcase{   s    zz&&499??+<+D+DS"+M"MN#
 OOV# 	 
 4(++-w7
 i FHCN ! 
#
 ! 
s   B'B,,B6c              #     K   |D ][  }t        j                  |j                  d            D ]1  }t        j	                  || |j
                  | j                         3 ] y w)Nr*   )encoding)rK   subjectr)   )r   r4   	read_text_Case	from_dictstemr%   )r@   rb   rO   r_   s       r   rd   zVersion._cases_in   sY     D

4>>7>#CDoo  II MM	 &   E s   A"A$N)rS   Iterable[_Case])rH   r0   rS   r   )rb   zIterable[Path]rS   r   )
rT   rU   rV   rW   rL   r]   rh   rk   r   rd   rX   r   r   rP   rP   f   s4     K33
I%?OP*r   rP   c                  t    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        ZddZy
)r   rP   rK   r0   r   descriptionMapping[str, Any] | boolschemazlist[_Test]rN   N
str | NonecommentrX   zSequence[dict[str, str]]specificationc                    |j                  |       |j                  d      D cg c]  }t        d|d   |d   |d   |d   |d|! }} | dd|i|S c c}w )NrN   rK   r   r   r   )rK   r   case_descriptionr   r)   rX   )updater9   _Test)r   datar)   r^   rt   rN   s         r   r   z_Case.from_dict   s    F ((7+	
 ,$  YY!%m!4H~  , 	 	
 ''$''	
s   $Ac           	         | j                   D ]2  }|j                  |j                  t        |j                  fi |       4 y N)rN   
bench_funcfully_qualified_namer   validate_ignoring_errors)r@   rI   r^   rt   s       r   rL   z_Case.benchmark   s:    JJD))55@@ r   rR   )	rT   rU   rV   rW   r   r   classmethodr   rL   rX   r   r   r   r      sM     L$$GZ.0M+0( (r   r   F)reprc                      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 Zed        Zd fdZd Z	d Z
y)r   rP   rK   r0   r   r   r   r   r   r   r   boolvalidr$   r%   Nr   r   c                "    d| j                    dS )Nz<Test >)r   rf   s    r   __repr__z_Test.__repr__   s    112!44r   c                    dj                  | j                  j                  | j                  | j                  | j
                  g      S )Nz > )joinrK   rH   r   r   r   rf   s    r   r   z_Test.fully_qualified_name   s>    zz!!%%  	
 	
r   c                     y r   rX   )rt   s    r   <lambda>z_Test.<lambda>   s    4r   c           	     $     j                   r fd}n fd}dj                  dt        j                  d j                        t        j                  d j
                        t        j                  d j                        g      |_         |       }|#t        j                  j                  dd      dk7  r|S t        j                  j                  dd      dk7  rt        j                  |      S  t        j                  |      |      S )Nc                *     j                   di  y r\   )validatethisr^   r@   s    r   fnz$_Test.to_unittest_method.<locals>.fn   s    ''r   c                    | j                  t        j                        5   j                  di  d d d        y # 1 sw Y   y xY wr\   )assertRaisesr   ValidationErrorr   r   s    r   r   z$_Test.to_unittest_method.<locals>.fn   s5    &&z'A'AB!DMM+F+ CBBs	   =A_rt   JSON_SCHEMA_DEBUG0JSON_SCHEMA_EXPECTED_FAILURES)r   r   _DELIMITERSsubr   r   r   rT   r   r   r   ry   expectedFailureskip)r@   r   r^   r   reasons   ` `  r   rq   z_Test.to_unittest_method   s    ::(, hhT\\2T%:%:;T%5%56	
 d>RZZ^^,?ELIZZ^^;SASH++B//(8==(,,r   c                
   |j                  | j                          |d| j                  | j                  d|}t        j                  j                  dd      dk7  r
t                |j                  | j                         y )N)r   rE   r   r   )instancerX   )	check_schemar   r%   r   r   r   
breakpointr   r   )r@   rJ   r^   	validators       r   r   z_Test.validate   so    t{{+ 
;;]]
 
	
 ::>>-s3s:LDII.r   c                    t        t        j                        5  | j                  |       d d d        y # 1 sw Y   y xY w)N)rJ   )r   r   r   r   )r@   rJ   s     r   r   z_Test.validate_ignoring_errors  s*    j001MMIM. 211s   6?)rT   rU   rV   rW   r   r   propertyr   rq   r   r   rX   r   r   r   r      sh     L
I$$K33GZ5 
 
 '8 -2	//r   r   c                 F    t        j                  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.
       rT   )r.   	_getframe	f_globalsrX   r   r   r|   r|     s     ==%%j11r   )(__doc__
__future__r   
contextlibr   	functoolsr   pathlibr   typingr   r   r   r   rer1   r.   ry   attrsr	   r
   r6   r   referencing.jsonschemacollections.abcr   r   r   pyperfjsonschema.validatorsr   r   compiler   r   r    rP   r   r   r|   rX   r   r   <module>r      s    #    %  	 	  
     ;; - bjj%$ 0
 0
 0
f 1 1 1h   D UE/ E/ E/P2r   