
    `dR                        d Z ddlZddlmZmZ ddlmZ ddlZ e       Zej                  d      Z
ej                  d      Zej                  d      Zej                  d	      Zej                  d
      Zej                  d      Zd Zd Zd Zej&                  dk(  ZerdZd Znd Zej.                  dk  rdZ eedd      Znd Zd Ze
j5                  e
j7                         e
j9                         e
j;                  d      e
j;                  d      e
j;                  d      ej<                  ej>                  d       Z ej5                  ej7                         ej9                         ej;                  d      ej;                  d      ej;                  d      ej;                  d      ejB                  ejD                  d  	      Z#ej5                  ej7                         ej9                         ej;                  d      ej;                  d      ej;                  d      ejH                  ejJ                  d!       Z&ej5                  ej7                         ej9                         ej;                  d      ej;                  d"      ej;                  d#      ej;                  d      ej;                  d      ejN                  ejP                  d$ 
      Z)ej5                  ej7                         ej;                  d      ej;                  d#      ej;                  d      ej;                  d      ej;                  d%      ejT                  d& '      Z+ej5                  ej9                         ejT                  ejX                  d(       Z-ej5                  ej7                         ej;                  d      ej;                  d#      ej;                  d      ej;                  d      ej;                  d%      ej\                  d) '      Z/ej5                  ej9                         ej\                  ej`                  d*       Z1y)+z
Test runner for the JSON Schema official test suite

Tests comprehensive correctness of each draft's validator.

See https://github.com/json-schema-org/JSON-Schema-Test-Suite for details.
    N)bugtest_suite_bug)Suitedraft3)namedraft4draft6draft7zdraft2019-09zdraft2020-12c                       fd}|S )Nc                 P     t         fdj                         D              rS y )Nc              3   B   K   | ]  \  }}|t        |      k(    y wN)getattr).0attrvaluetests      M/usr/lib/python3/dist-packages/jsonschema/tests/test_jsonschema_test_suite.py	<genexpr>z(skip.<locals>.skipper.<locals>.<genexpr>   s!     Neud++Ns   )allitems)r   kwargsmessages   `r   skipperzskip.<locals>.skipper   s"    Nv||~NNN O     )r   r   r   s   `` r   skipr      s     Nr   c                       fd}|S )Nc                     | j                   }|du s%|du s!d|vs|d   j                  v s| j                  ry dj                  |d         S )NTFformatzFormat checker {0!r} not found.)schemacheckersvalidr    )r   r!   checkers     r   missing_formatz&missing_format.<locals>.missing_format    sU    dNv%h7#3#33zz077x8HIIr   r   )r$   r%   s   ` r   r%   r%      s    J r   c                     | j                   dk7  ry d} t        |d      |       xsR  t        |d      |       xs=  t        |d      |       xs(  t        |d      |       xs  t        |d      |       S )	Nemailz8Complex email validation is (intentionally) unsupported.zan invalid domainr   descriptionzan invalid IPv4-address-literalz!dot after local part is not validz"dot before local part is not validz3two subsequent dots inside local part are not valid)subjectr   r   r   s     r   complex_email_validationr,   /   s    ||wHG4'  t5 t7 t8 tI r   i  z:Not running surrogate Unicode case, this Python is narrow.c                 b     t        t        d      |       xs  t        t        d      |       S )Nz7one supplementary Unicode code point is not long enoughr(   z4two supplementary Unicode code points is long enough)r   r   r   s    r   narrow_unicode_buildr/   J   sD    
tI

  

4N
 	r   c                      y r   r   r.   s    r   r/   r/   U       r   )   	   zRejecting leading zeros is 3.9+ipv4z5invalid leading zeroes, as they are treated as octalsr   r*   r)   c                      y r   r   r.   s    r   allowed_leading_zerosr7   a   r1   r   c                    d} t        |dd      |       xs  t        |dd      |       xs  t        |dd      |       xs  t        |dd      |       xs  t        |dd      |       xsl  t        |dd	      |       xsV  t        |dd
      |       xs@  t        |dd      |       xs*  t        |dd      |       xs  t        |dd      |       S )NzLeap seconds are unsupported.timez$a valid time string with leap secondr5   z*a valid time string with leap second, Zuluz0a valid time string with leap second with offsetz'valid leap second, positive time-offsetz'valid leap second, negative time-offsetz-valid leap second, large positive time-offsetz-valid leap second, large negative time-offsetz#valid leap second, zero time-offsetz	date-timez)a valid date-time with a leap second, UTCz7a valid date-time with a leap second, with minus offset)r   r+   s     r   leap_secondr:   e   ss   -G4: 	 (t@ 		(tF 	(t= 	( t= 	!((tC 	)(0tC 	1(8t9 	9(@t? 	A(HtM 	I(r   bignumznon-bmp-regexzeroTerminatedFloatsc                     t        |       xsL  t        t        j                        |       xs+ t	        |       xs  t        t        d      ddd      |       S )Ns  refF5$ref prevents a sibling id from changing the base urir   r*   r#   case_description)r/   r%   
jsonschemadraft3_format_checkerr,   r   r   r.   s    r   <lambda>rE      sa    T" 
	;>*::;DA
	#D)
	
4HG
 	 r   )	Validatorformat_checkerr   zfloat-overflowc                 Z   t        |       xs t        |       xs t        |       xs  t        t        j
                        |       xs t        |       xs  t        t               dd      |       xs  t        t        d      dd      |       xs  t        t        d      dd      |       xsx  t        t        d      dd	      |       xsY  t        t        d      dd
	      |       xs:  t        t               dd      |       xs  t        t               dd      |       S )Nr?   z$Recursive references between schemasr   r*   rB   r>   zALocation-independent identifier with base URI change in subschemar@   idzmatch $ref to idr5   zno match on enum or $ref to id	refRemote,base URI change - change folder in subschemazEid must be resolved against nearest parent, not just immediate parent)	r/   r7   r:   r%   rC   draft4_format_checkerr,   r   r   r.   s    r   rE   rE      sn   T" /	 &/	t/	 <>*::;DA/	 $D)	/	

4EC
 	/	
4H/	
 /	$
4HG	
 %/	2
4H*
 	3/	<
4H8
 	=/	F
4EK
 	G/	P
4E,	
 S r   c                 "   t        |       xs t        |       xsv t        |       xsi  t        t        j
                        |       xsH t        |       xs;  t        t               dd      |       xs  t        t        d      dd      |       S )NrK   rL   rI   r>   r?   6$ref prevents a sibling $id from changing the base uri)	r/   r7   r:   r%   rC   draft6_format_checkerr,   r   r   r.   s    r   rE   rE      s    T" 	 &	t	 <>*::;DA	 $D)		

4EK
 		
4HH	
  r   contentzcross-draftc                     t        |       xs t        |       xs t        |       xs  t        t        j
                        |       xs t        |       xs  t        t               dd      |       xs  t        t        d      dd      |       xs|  t        t               dd      |       xs^  t        t        d      d	d
d      |       xs>  t        t        d      d	d
d      |       xs  t        t        d      d	d
d      |       S )NrK   rL   rI   r>   r?   rO   F$id must be resolved against nearest parent, not just immediate parentiQ  rQ   Fz8validation of string-encoded content based on media typerA   z$validation of binary string-encodingz1validation of binary-encoded media type documents)	r/   r7   r:   r%   rC   draft7_format_checkerr,   r   r   r.   s    r   rE   rE     sO   T" .	 &.	t.	 <>*::;DA.	 $D)	.	

4EK
 	.	
4HH	
 .	"
4E,	
 #.	2
4HJ
 3.	B
4HC	

 C.	N
4HC
 Q r   refOfUnknownKeywordc                     t        ddd      |       xs4  t        ddd      |       xs  t        ddd      |       xs  t        ddd      |       xs  t        dddd	
      |       xs  t        dddd	
      |       xs  t        dddd	
      |       xs  t        dddd	
      |       xs  t        dddd	
      |       xsw  t        ddd      |       xs`  t        dddd
      |       xsH  t        ddd      |       xs1  t        dddd
      |       xs  t        dddd
      |       xs  t        ddd      |       xs  t        ddd      |       xs  t        ddd      |       xs  t        ddd      |       xs  t        ddd      |       xs  t        ddd      |       xs}  t        ddd !      |       xsg  t        d"d#d$      |       xsQ  t        d"d%d&!      |       xs;  t        t        d'      d(d)      |       xs  t        t               d*d+!      |       S ),Nz6unevaluatedItems is different in 2019-09 (needs work).unevaluatedItemsz+uncle keyword evaluation is not significantr5   z1when one schema matches and has unevaluated itemsz0when two schemas match and has unevaluated itemsz,when if matches and it has unevaluated itemsz"unevaluatedItems with nested tuplezwith unevaluated items)r   r*   rB   r)   zunevaluatedItems with notzunevaluatedItems with oneOfzunevaluatedItems with $refzunevaluatedItems with tuplez2when if doesn't match and it has unevaluated itemsz'recursiveRef support isn't working yet.recursiveRefzL$recursiveRef with no $recursiveAnchor in the initial target schema resourcez9leaf node does not match: recursion uses the inner schemaz2leaf node matches: recursion uses the inner schemazJdynamic $recursiveRef destination (not predictable at schema compile time)zinteger nodez3multiple dynamic paths to the $recursiveRef keyword/recurse to integerNode - floats are not allowedz*integer does not match as a property valuez:leaf node does not match: recursion only uses inner schemaz3leaf node matches: recursion only uses inner schemaz6two levels, integer does not match as a property valuezrecursive mismatchztwo levels, no matchrJ   z4Invalid use of fragments in location-independent $idrI   +dynamicRef support isn't fully working yet.defsinvalid definition schemaanchor$same $anchor with different base uri>  
vocabulary5no validation: invalid number, but it still validatesr?   rS   )r   r   r   r.   s    r   rE   rE   L  s   	
L&E	
 		 ]	

4L&K
 	]	
4L&J
 	]	
4L&F
 	]	(
4L&A0	

 )]	4
4L&80	

 5]	@
4L&:0	

 A]	L
4L&90	

 M]	X
4L&:0	

 Y]	d
4L&L
 	e]	n

4="5 L

 
o]	D
4="L
 	E]	N
4="* '
 O]	`
4="EI
 a]	p
4="D
 	q]	z
4="3	
 {]	J
4="3	
 K]	Z
4="H	
 []	h
4=",
 	i]	r
4=".
 	s]	|
4=F	
 }]	J
4A3
 	K]	T
4AC
 	U]	^
4"3' G	
 _]	l
4E,	
 o r   )rF   r   c                     t        |       xsF t        |       xs9 t        |       xs,  t        t        j
                        |       xs t        |       S r   )r,   r7   r:   r%   rC   draft201909_format_checkerr.   s    r   rE   rE     U     & 	* &	*t	* A>*??@F	* $D) r   c                    t        |       xs3  t        ddd      |       xs  t        dddd      |       xs  t        dddd      |       xs  t        dddd	      |       xs  t        dddd	      |       xs  t        ddd
      |       xs  t        ddd      |       xs  t        ddd      |       xs}  t        ddd      |       xsg  t        ddd      |       xsQ  t        ddd      |       xs;  t        t        d      dd      |       xs  t        t               dd      |       S )NrZ   
dynamicRefz0The recursive part is not valid against the rootr5   zincorrect extended schemaz>$ref and $dynamicAnchor are independent of order - $defs first)r   r*   r)   rB   zcorrect extended schemaz=$ref and $dynamicAnchor are independent of order - $ref firstz8/then/$defs/thingy is the final stop for the $dynamicRefzDstring matches /$defs/thingy, but the $dynamicRef does not stop hererY   r[   r\   r]   r^   rI   r_   r`   ra   r?   rS   )r/   r   r   r   r.   s    r   rE   rE     s   T" \	
4A J
 	\	
4A 3
 \	
4A 1
 \	0
4A 1O
 1\	@
4A 3O
 A\	P
4A J	
 Q\	^
4A %	
 _\	n
4A %	
 o\	~
4A I
 	\	H
4A3
 	I\	R
4AC
 	S\	\
4"3' G	
 ]\	j
4E,	
 m r   c                     t        |       xsF t        |       xs9 t        |       xs,  t        t        j
                        |       xs t        |       S r   )r,   r7   r:   r%   rC   draft202012_format_checkerr.   s    r   rE   rE   k  rd   r   )2__doc__sysjsonschema.tests._helpersr   r   jsonschema.tests._suiter   rC   SUITEversionDRAFT3DRAFT4DRAFT6DRAFT7DRAFT201909DRAFT202012r   r%   r,   
maxunicodeis_narrow_buildr   r/   version_infor7   r:   to_unittest_testcasetestsformat_testsoptional_tests_ofDraft3ValidatorrD   
TestDraft3Draft4ValidatorrM   
TestDraft4Draft6ValidatorrP   
TestDraft6Draft7ValidatorrT   
TestDraft7Draft201909ValidatorTestDraft201909rc   TestDraft201909FormatDraft202012ValidatorTestDraft202012rh   TestDraft202012Formatr   r   r   <module>r      s    9 ) 	H	%	H	%	H	%	H	%mmm0mmm0 . ..K/JG	 f/G K*Z ((
LLN

(+
/2
"89((33
 ) 
0 ((
LLN

(+
"23
/2
"89((331
 ) ;
| ((
LLN

(+
"23
/2((33
 ) 
< ((
LLN

(+
),
-0
"23
/2((330
 ) ;
| 22!!x!0!!}!5!!'7!8!!!7!!'<!=--_
 3 hV $88--88
	 9   22!!x!0!!}!5!!'7!8!!!7!!'<!=--^
 3 gT $88--88
	 9  r   