
    Mh                        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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mZ ddlZddlmZ ddlZdZ  ej!        d          Z"d Z#e G d d                      Z$e G d d                      Z%e G d d                      Z&d#dZ' ed           G d  d!                      Z(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)Schema)_VALIDATORSzhttp://localhost:1234z[\W\- ]+c                     t           j                            d          } | t          |           S t          t          j                  j        j        dz  } |                                 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    W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jsonschema/tests/_suite.py_find_suiter   "   sq    :>>233DDzz
#$$+2V;D;;== 
 
 
 	
 K    c                  B    e Zd ZU  ee          Zded<   ddZdd	Zd
S )Suite)factoryr   _rootrunnerpyperf.Runnerc                    t          j                    D ]0\  }}|                     |                              ||           1d S )N)name)r$   	Validator)r   itemsversion	benchmark)selfr$   r'   r(   s       r   r+   zSuite.benchmark:   s^    *022 	 	OD)LLdL##--# .    	 	r   returnVersionc                >   t           |         }|                    |j                  }t          j                            |          }t                                          t          | j	        dz  ||          |          }t          || j	        dz  |z  |          S )Nremotes)r   r'   uri)default_specificationtests)r'   pathr0   )r   ID_OFMETA_SCHEMAreferencingr   specification_withr   with_contents
remotes_inr#   r.   )r,   r'   r(   r1   specificationregistrys         r   r*   zSuite.versionA   s    %	??9#899#.AA#FF::++DJ23GGG"/ , 
 
 g%,
 
 
 	
r   Nr$   r%   )r-   r.   )	__name__
__module____qualname__r	   r   r#   __annotations__r+   r*    r   r   r!   r!   4   s^          %,,,E,,,,   
 
 
 
 
 
r   r!   c                  Z    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	dS )r.   r   _path%referencing.jsonschema.SchemaRegistry_remotesstrr'   c                N    |                                  D ]} |j        di | d S NrB   )casesr+   )r,   kwargscases      r   r+   zVersion.benchmarkY   s>    JJLL 	% 	%DDN$$V$$$$	% 	%r   r-   Iterable[_Case]c                ^    |                      | j                            d                    S )N*.jsonpaths	_cases_inrD   globr,   s    r   rJ   zVersion.cases]   s$    ~~DJOOH$=$=~>>>r   c                ^    |                      | j                            d                    S )Nzoptional/format/*.jsonrP   rR   rU   s    r   format_caseszVersion.format_cases`   s%    ~~DJOO4L$M$M~NNNr   c                L    |                      | j        dz  | dz  g          S )Noptionalz.jsonrP   )rS   rD   )r,   r'   s     r   optional_cases_ofzVersion.optional_cases_ofc   s+    ~~TZ*%<$~~~%M$N~OOOr   c                v                        dd| j                                                            dd          z             }d fd|D             D             }t	          |t
          j        f|          }t          t                    5  t                      |_
        d d d            n# 1 swxY w Y   |S )Nr'   Test- c                    i | ]
}|j         |S rB   )r>   ).0methods     r   
<dictcomp>z0Version.to_unittest_testcase.<locals>.<dictcomp>h   s,     
 
 
 OV
 
 
r   c              3  P   K   | ] }|D ]}|j         D ]} |j        di V  !d S rI   )r3   to_unittest_method)r`   grouprL   testrK   s       r   	<genexpr>z/Version.to_unittest_testcase.<locals>.<genexpr>j   sz        !   J	   ('11&11       r   )popr'   titlereplacetypeunittestTestCaser   	Exception)_someone_save_us_the_module_of_the_callerr?   )r,   groupsrK   r'   methodsclss     `   r   to_unittest_testcasezVersion.to_unittest_testcasef   s   zz&&49??+<+<+D+DS"+M+M"MNN
 
   #  
 
 
 4(+-w77
 i   	I 	IFHHCN	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 
s   B..B25B2rQ   Iterable[Path]c              #     K   |D ]W}t          j        |                    d                    D ],}t                              || |j        | j                  V  -Xd S )Nzutf-8)encoding)r*   subjectr0   )r   loads	read_text_Case	from_dictstemrF   )r,   rQ   r4   rL   s       r   rS   zVersion._cases_in{   s       	 	D
4>>7>#C#CDD  oo  I M	 &      	 	r   N)r-   rM   )r'   rG   r-   rM   )rQ   rt   r-   rM   )
r>   r?   r@   rA   r+   rJ   rW   rZ   rs   rS   rB   r   r   r.   r.   Q   s          KKK3333III% % %? ? ? ?O O O OP P P P  *     r   r.   c                  |    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d
S )rz   r.   r*   rG   rw   descriptionMapping[str, Any] | boolschemazlist[_Test]r3   N
str | NonecommentrB   zSequence[dict[str, str]]r;   c                                         |           fd                    d          D             } | dd|iS )Nc                d    g | ],}t          dd          d         d         d         d|-S )r*   rw   r~   r   )r*   rw   case_descriptionr   r0   rB   )_Test)r`   rf   datar0   s     r   
<listcomp>z#_Case.from_dict.<locals>.<listcomp>   si     	
 	
 	
   YY!%m!4H~   	
 	
 	
r   r3   rB   )updaterh   )rr   r   r0   rK   r3   s    ``  r   r{   z_Case.from_dict   sn    F	
 	
 	
 	
 	
 ((7++	
 	
 	
 s'''$'''r   r$   r%   c           	     p    | j         D ]-}|                    |j        t          |j        fi |           .d S N)r3   
bench_funcfully_qualified_namer   validate_ignoring_errors)r,   r$   rK   rf   s       r   r+   z_Case.benchmark   sV    J 	 	D)5@@@@   	 	r   r=   )	r>   r?   r@   rA   r   r;   classmethodr{   r+   rB   r   r   rz   rz      s          LLL$$$$G.0M0000( ( [(     r   rz   r   r   r'   rG   r1   r-   Iterable[tuple[str, Schema]]c              #    K   |                      d          D ]}t          j        |                                          }t	          |                    |                                         dd          }|dv r|j        dk    s.d|vr+|                    d          r|                    |          st           d| |fV  d S )NrO   \/>   draft3draft4treez$schemadraft)
rglobr   rx   ry   rG   relative_torj   r|   
startswithMAGIC_REMOTE_URL)r   r'   r1   eachr   relatives         r   r:   r:      s       

8$$ 7 7DNN,,--t''--..66tSAA ,,,I'' ''''00 ( ++D11 (
 !..H..66666#7 7r   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
dS )r   r.   r*   rG   rw   r   r~   r   r   r   r   boolvalidrE   rF   Nr   r   c                    d| j          dS )Nz<Test >)r   rU   s    r   __repr__z_Test.__repr__   s    414444r   c                f    d                     | j        j        | j        | j        | j        g          S )Nz > )joinr*   r'   rw   r   r~   rU   s    r   r   z_Test.fully_qualified_name   s6    zz!% 	
 
 	
r   c                    d S r   rB   )rf   s    r   <lambda>z_Test.<lambda>   s    4 r   c           	     .     j         r fd}n fd}d                    dt                              d j                  t                              d j                  t                              d j                  g          |_         |           }|$t          j	        
                    dd          dk    r|S t          j	        
                    dd          dk    rt          j        |          S  t          j        |          |          S )Nc                "     j         di  d S rI   )validatethisrK   r,   s    r   fnz$_Test.to_unittest_method.<locals>.fn   s!    '''''''r   c                    |                      t          j                  5   j        di  d d d            d S # 1 swxY w Y   d S rI   )assertRaisesr   ValidationErrorr   r   s    r   r   z$_Test.to_unittest_method.<locals>.fn   s    &&z'ABB , ,!DM++F+++, , , , , , , , , , , , , , , , , ,s   <A A _rf   JSON_SCHEMA_DEBUG0JSON_SCHEMA_EXPECTED_FAILURES)r   r   _DELIMITERSsubrw   r   r~   r>   r   r   r   rl   expectedFailureskip)r,   r   rK   r   reasons   ` `  r   rd   z_Test.to_unittest_method   s$   : 	,( ( ( ( ( ( (, , , , , , hhT\22T%:;;T%566	
 
 d>RZ^^,?EELLIZ^^;SAASHH+B///(8=((,,,r   c                    |                     | j                    |d| j        | j        d|}t          j                            dd          dk    rt                       |                    | j                   d S )N)r   r<   r   r   )instancerB   )	check_schemar   rF   r   r   r   
breakpointr   r   )r,   r(   rK   	validators       r   r   z_Test.validate   s    t{+++I 
;]
 
 
 
	
 :>>-s33s::LLLDI.....r   c                    t          t          j                  5  |                     |           d d d            d S # 1 swxY w Y   d S )N)r(   )r   r   r   r   )r,   r(   s     r   r   z_Test.validate_ignoring_errors  s    j011 	/ 	/MMIM...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   >AA)r>   r?   r@   rA   r   r   propertyr   rd   r   r   rB   r   r   r   r      s          LLLIII$$$$KKK3333G5 5 5 
 
 X
 '8&7 - - - -2	/ 	/ 	// / / / /r   r   c                 @    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.
       r>   )sys	_getframe	f_globalsrB   r   r   ro   ro     s     =%j11r   )r   r   r'   rG   r1   rG   r-   r   )*__doc__
__future__r   
contextlibr   	functoolsr   pathlibr   typingr   r   r   r   rer   rl   attrsr	   r
   r7   r   referencing.jsonschemacollections.abcr   r   r   r   pyperfjsonschema.validatorsr   r   r   compiler   r   r!   r.   rz   r:   r   ro   rB   r   r   <module>r      so    # " " " " "                   % % % % % % % %  				 				 



                          ;;;;;;;;;;------MMM - - - - - -    * bj%%  $ 
 
 
 
 
 
 
 
8 1 1 1 1 1 1 1 1h        D7 7 7 7< UE/ E/ E/ E/ E/ E/ E/ E/P2 2 2 2 2r   