+
     h?X  c                   s    ^ RI Ht ^ RIt^ RIHt ^ RIHt  ! R R]4      t ! R R]4      t ! R	 R
]4      t	 ! R R]4      t
 ! R R]4      tR# )    )TestCaseN)
exceptions)_LATEST_VERSIONc                   s   a  ] tR t^t o R tR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tR tRtV tR# )TestBestMatchc                sj   \        \        V4      P                  V4      4      pR V RV: R2pV P                  W4R7       \        P
                  ! \        V4      4      p\        P
                  ! \        V4      4      pV P                  VP                  4       VP                  4       RV RV 24       V# )zNo errors found for z under Z!)msgzNo consistent best match!
Got: z

Then: )
listr   iter_errorsZ
assertTruer   
best_matchZiterZreversedassertEqualZ	_contents)selfinstanceschemaerrorsr   bestZreversed_bests   &&&    E/usr/lib/python3.14/site-packages/jsonschema/tests/test_exceptions.pybest_match_ofZTestBestMatch.best_match_of	   s    of-99(CD%hZwvjB($$T&\2"--hv.>?NN##%.tfJ}oN	

     c                s    R RR^R RRR/////pV P                  RR. //VR7      pV P                  VP                  R4       R# )
propertiesfoominPropertiesbartypeobjectr   r   Nr   r	   	validatorr
   r   r      &  r   (test_shallower_errors_are_better_matchesZ6TestBestMatch.test_shallower_errors_are_better_matches   sa    #Q 568*<"=
 !!EE2;+?!O9r   c                s    R^RRR/RR/.RRR/RR/./pV P                  / VR7      pV P                  VP                  R4       R# )	zV
A property you *must* match is probably better than one you have to
match a part of.
r   anyOfr   stringZnumberoneOfr   Nr   r   r   r   %test_oneOf_and_anyOf_are_weak_matchesZ3TestBestMatch.test_oneOf_and_anyOf_are_weak_matches$   sc     Qvx(68*<=vx(68*<=

 !!2f!=9r   c                    RRRRR/RRRR///.///pV P                  RR^//VR7      pV P                  VP                  R4       R	# )
a  
If the most relevant error is an anyOf, then we traverse its context
and select the otherwise *least* relevant error, since in this case
that means the most specific, deep, error inside the instance.

I.e. since only one of the schemas must match, we look for the most
relevant one.
r   r   r   r   r   r   arrayr   Nr   r	   validator_valuer   r   r   8test_if_the_most_relevant_error_is_anyOf_it_is_traversedZFTestBestMatch.test_if_the_most_relevant_error_is_anyOf_it_is_traversed2   s     *%/@'AB	
 !!EE2;+?!O--w7r   c                ~    RRR/RR/RR/./pV P                  . VR7      pV P                  VP                  R4       R# )zz
We don't traverse into an anyOf (as above) if all of its context errors
seem to be equally "wrong" against the instance.
r   r   r   integerr   r   Nr   r   r   r   3test_no_anyOf_traversal_for_equally_relevant_errorsZATestBestMatch.test_no_anyOf_traversal_for_equally_relevant_errorsI   V     "#"
 !!2f!=1r   c                r    RRR/./pV P                  . VR7      pV P                  VP                  R4       R# )zl
We *do* traverse anyOf with a single nested error, even though it is
vacuously equally relevant to itself.
r   r   r   r   Nr   r   r   r   6test_anyOf_traversal_for_single_equally_relevant_errorZDTestBestMatch.test_anyOf_traversal_for_single_equally_relevant_errorY   F     "

 !!2f!=0r   c                z    RRR^%//./pV P                  ^^.VR7      pV P                  VP                  R4       R# )zd
We *do* traverse anyOf with a single subschema that fails multiple
times (e.g. on multiple items).
r   itemsconstr   Nr   r   r   r   .test_anyOf_traversal_for_single_sibling_errorsZ<TestBestMatch.test_anyOf_traversal_for_single_sibling_errorsg   N     7B-(

 !!B8F!C1r   c                    RRR/RR^%//./pV P                  ^^.VR7      pV P                  VP                  R4       R# )zO
We *do* traverse anyOf with multiple subschemas when one does not type
match.
r   r   r   r0   r1   r   Nr   r   r   r   9test_anyOf_traversal_for_non_type_matching_sibling_errorsZGTestBestMatch.test_anyOf_traversal_for_non_type_matching_sibling_errorsu   V     "7B-(
 !!B8F!C1r   c                r"   )
a  
If the most relevant error is an oneOf, then we traverse its context
and select the otherwise *least* relevant error, since in this case
that means the most specific, deep, error inside the instance.

I.e. since only one of the schemas must match, we look for the most
relevant one.
r   r   r    r   r   r   r#   r   Nr$   r   r   r   8test_if_the_most_relevant_error_is_oneOf_it_is_traversedZFTestBestMatch.test_if_the_most_relevant_error_is_oneOf_it_is_traversed   r'   r   c                r(   )zz
We don't traverse into an oneOf (as above) if all of its context errors
seem to be equally "wrong" against the instance.
r    r   r   r)   r   r   Nr   r   r   r   3test_no_oneOf_traversal_for_equally_relevant_errorsZATestBestMatch.test_no_oneOf_traversal_for_equally_relevant_errors   r+   r   c                r,   )zl
We *do* traverse oneOf with a single nested error, even though it is
vacuously equally relevant to itself.
r    r   r   r   Nr   r   r   r   6test_oneOf_traversal_for_single_equally_relevant_errorZDTestBestMatch.test_oneOf_traversal_for_single_equally_relevant_error   r.   r   c                r/   )zd
We *do* traverse oneOf with a single subschema that fails multiple
times (e.g. on multiple items).
r    r0   r1   r   Nr   r   r   r   .test_oneOf_traversal_for_single_sibling_errorsZ<TestBestMatch.test_oneOf_traversal_for_single_sibling_errors   r3   r   c                r4   )zO
We *do* traverse oneOf with multiple subschemas when one does not type
match.
r    r   r   r0   r1   r   Nr   r   r   r   9test_oneOf_traversal_for_non_type_matching_sibling_errorsZGTestBestMatch.test_oneOf_traversal_for_non_type_matching_sibling_errors   r6   r   c                s    RRRRR/RRRR///.///pV P                  RR^//VR7      pV P                  VP                  R4       R	# )
z
Now, if the error is allOf, we traverse but select the *most* relevant
error from the context, because all schemas here must match anyways.
r   r   ZallOfr   r   r   r#   r   Nr$   r   r   r   8test_if_the_most_relevant_error_is_allOf_it_is_traversedZFTestBestMatch.test_if_the_most_relevant_error_is_allOf_it_is_traversed   ss     *%/@'AB	
 !!EE2;+?!O--x8r   c           
     s    RRRRR/RRR/RRRR///././//pV P                  RR^//VR7      pV P                  VP                  R4       R	# )
zX
We traverse into nested contexts (a oneOf containing an error in a
nested oneOf here).
r   r   r    r   r   r   r#   r   Nr$   r   r   r   test_nested_context_for_oneOfZ+TestBestMatch.test_nested_context_for_oneOf   s     *#!' 2$0(-/@3&!"&	
& !!EE2;+?!O--w7r   c                s   R RRRRR^/RRR^
/.///pV P                  RR/VR	7      pV P                  VP                  R4       R RRRRR^
/RRR^/.///pV P                  RR/VR	7      pV P                  VP                  R4       R
# )r   r   r   r   r#   minItemsr   	minLengthr   r   Nr   r
   r   r   Z	reordered   &   r   "test_it_prioritizes_matching_typesZ0TestBestMatch.test_it_prioritizes_matching_types  s    *a8;;	
 !!E5>&!I5 ;;*a8	
	 !!E5>)!L5r   c                s   R RRRRR.R^/RRR.R	^
/.///pV P                  RR
/VR7      pV P                  VP                  R	4       R RRRRR	^
/RRR^/.///pV P                  RR
/VR7      pV P                  VP                  R	4       R# )r   r   r   r   r#   r   r>   r)   r   r?   r   r   Nr   r@   rA   r   (test_it_prioritizes_matching_union_typesZ6TestBestMatch.test_it_prioritizes_matching_union_types   s    '8!4j!D)X!6RH	
 !!E5>&!I5 ;;*a8	
	 !!E5>)!L5r   c                sr    R RR//pV P                  RR/VR7      pV P                  VP                  4       R# )r   r   Fr   r   N)r   assertIsNoner   r   r   r   test_boolean_schemasZ"TestBestMatch.test_boolean_schemas;  s;    /!!E5>&!I$..)r   c                s    \        R ^/4      pVP                  / 4      w  pV P                  \        P                  ! VP                  / 4      4      P
                  R 4       R# )r   N)r   r   r	   r   r   r   )r
   r   errorr   r   test_one_errorZTestBestMatch.test_one_error@  sS    #_a$89	&&r*!!)"7"7";<FF	
r   c                s    \        / 4      pV P                  \        P                  ! VP	                  / 4      4      4       R # )N)r   rD   r   r   r   )r
   r      & r   test_no_errorsZTestBestMatch.test_no_errorsH  s0    #B'	*//	0E0Eb0IJKr    N)__name__
__module____qualname____firstlineno__r   r   r!   r&   r*   r-   r2   r5   r7   r8   r9   r:   r;   r<   r=   rB   rC   rE   rG   rI   __static_attributes____classdictcell____classdict__   @r   r   r      sp     
::8.2 1228.2 1229&886666*

L Lr   r   c                   s8   a  ] tR tRt o R tR tR tR tRtV t	R# )TestByRelevanceiM  c                s    \         P                  ! R R.R7      p\         P                  ! RRR.R7      p\        W.\         P                  R7      pV P	                  W14       \        W!.\         P                  R7      pV P	                  W14       R# )Oh no!ZbazpathOh yes!r   r   ZkeyN)r   ValidationErrormax	relevanceassertIs)r
   shallowdeepmatchrA   r   #test_short_paths_are_better_matchesZ3TestByRelevance.test_short_paths_are_better_matchesN  sl    ,,XUGD)))5%.IWO)=)=>e%TO)=)=>e%r   c                s   \         P                  ! R . R7      p\         P                  ! RR.R7      p\        W.\         P                  R7      pT P	                  V Uu. uF  p\        VP                  4      NK  	  upR.. .4       \        W!.\         P                  R7      pT P	                  V Uu. uF  p\        VP                  4      NK  	  upR.. .4       R# u upi u upi )rU   rV   rX   r   rY   N)r   rZ   Zsortedr\   r	   r   rW   )r
   r^   r_   r   rF      &    r   *test_global_errors_are_even_better_matchesZ:TestByRelevance.test_global_errors_are_even_better_matchesW  s    ,,XB?)))5'BZ-A-AB+126%T%**62WbM	

 Z-A-AB+126%T%**62WbM	
 3 3s   C1C!c                s   \         P                  ! R . RR7      p\         P                  ! R. RR7      p\         P                  ! RR7      p\        W.VR7      pV P	                  WB4       \        W!.VR7      pV P	                  WB4       R# )rU   arW   r   rX   b)weakrY   Nr   rZ   Zby_relevancer[   r]   )r
   rg   normalr   r`   rb   r   %test_weak_keywords_are_lower_priorityZ5TestByRelevance.test_weak_keywords_are_lower_priorityg  sn    ))(sK++IB#N,,#6
TN
3e$VN
3e$r   c                sL   \         P                  ! R . RR7      p\         P                  ! R. RR7      p\         P                  ! R. RR7      p\         P                  ! RRR7      p\        WV.VR7      pV P	                  WS4       \        W2V.VR7      pV P	                  WS4       R	# )
rU   rd   re   rX   rf   zOh fine!Zc)rg   strongrY   Nrh   )r
   rg   ri   rk   r   r`   s   &     r   (test_strong_keywords_are_higher_priorityZ8TestByRelevance.test_strong_keywords_are_higher_prioritys  s    ))(sK++IB#N++JR3O,,#cB
T6*
;e$VT*
;e$r   rJ   N)
rK   rL   rM   rN   ra   rc   rj   rl   rO   rP   rQ   rS   r   rT   rT   M  s     &
 
%% %r   rT   c                   sn   a  ] tR tRt o R tR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tRtV tR# )TestErrorTreei  c                s    \        ^4       Uu. uF  p\        P                  ! RVR7      NK  	  pp\        P                  ! V4      pV P	                  VP
                  ^4       R# u upi )i   Z	Somethingr   N)ranger   rZ   	ErrorTreer	   Ztotal_errors)r
   Zir   treerA   r   /test_it_knows_how_many_total_errors_it_containsZ=TestErrorTree.test_it_knows_how_many_total_errors_it_contains  sb     1X
 &&{a@ 	 
 ##F+**A.
s   !A%c                s    \         P                  ! R R.R7      .p\         P                  ! V4      pV P                  RV4       R# )	a messager   rV   N)r   rZ   rp   assertInr
   r   rq   r   r   1test_it_contains_an_item_if_the_item_had_an_errorZ?TestErrorTree.test_it_contains_an_item_if_the_item_had_an_error  s7    ,,[wGH##F+eT"r   c                s    \         P                  ! R R.R7      .p\         P                  ! V4      pV P                  RV4       R# )rs   r   rV   r   N)r   rZ   rp   assertNotInru   r   r   9test_it_does_not_contain_an_item_if_the_item_had_no_errorZGTestErrorTree.test_it_does_not_contain_an_item_if_the_item_had_no_error  s9    ,,[wGH##F+%r   c                s    \         P                  ! R RR7      p\         P                  ! V.4      pV P                  VP                  RV/4       R# )rs   r   rn   Nr   rZ   rp   r	   r   r
   rF   rq   r   r   /test_keywords_that_failed_appear_in_errors_dictZ=TestErrorTree.test_keywords_that_failed_appear_in_errors_dict  s>    **;%H##UG,uen5r   c                s    \         P                  ! R R.R7      \         P                  ! RR^ .R7      .p\         P                  ! V4      pV P                  ^ VR,          4       V P	                  ^VR,          4       R# )za bar messager   rV   za bar -> 0 messageN)r   rZ   rp   rt   rw   ru   r   r   1test_it_creates_a_child_tree_for_each_nested_pathZ?TestErrorTree.test_it_creates_a_child_tree_for_each_nested_path  sh    &&eWE&&';5!*M
 ##F+ae%DK(r   c                s    \         P                  ! R RR^ .R7      \         P                  ! RRR^ .R7      r!\         P                  ! W.4      pV P                  VR,          ^ ,          P                  RVRV/4       R# )1r   r   )r   rW   2quuxNry   r
   e1e2rq   rA   r   +test_children_have_their_errors_dicts_builtZ9TestErrorTree.test_children_have_their_errors_dicts_built  sn    &&se5!*M&&sfE1:N  ##RH-eQ..FB0GHr   c                s    \         P                  ! R RRR.RR7      \         P                  ! RRR^.R	R7      r!\         P                  ! W.4       R
# r}   r   r   bar2i1r   rW   r   r~   r   foobari2N)r   rZ   rp   )r
   r   r   r   r   "test_multiple_errors_with_instanceZ0TestErrorTree.test_multiple_errors_with_instance  sW    &&V_	
 && ]	  	bX&r   c                s    \         P                  ! R R. R7      p\         P                  ! V.4      pV P                  \        4      ;_uu_ 4        V^ ,           RRR4       R#   + '       g   i     R# ; i)Z123r   )r   r   N)r   rZ   rp   ZassertRaisesZ
IndexErrorrz   r   r   >test_it_does_not_contain_subtrees_that_are_not_in_the_instanceZLTestErrorTree.test_it_does_not_contain_subtrees_that_are_not_in_the_instance  sO    **5EBO##UG,z**G +***s   
A""A3	c                s    \         P                  ! RR/ R.R7      p\         P                  ! V.4      pV P                  VR,          \         P                  4       R# )zt
If a keyword refers to a path that isn't in the instance, the
tree still properly returns a subtree for that path.
rs   r   )r   r   rW   N)r   rZ   rp   ZassertIsInstancerz   r   r   9test_if_its_in_the_tree_anyhow_it_does_not_raise_an_errorZGTestErrorTree.test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error  sM     **52UG
 ##UG,d5k:+?+?@r   c                s    \         P                  ! R RRR.RR7      \         P                  ! RRR^.R	R7      r!\         P                  ! W.4      pV P                  \	        V4      RR04       R
# r   )r   rZ   rp   r	   Zsetr   rA   r   	test_iterZTestErrorTree.test_iter  sr    &&V_	
 && ]	  ##RH-TUH$56r   c                s    \         P                  ! R RRR.RR7      p\         P                  ! V.4      pV P                  \	        V4      R4       R# )r}   r   r   r   r   r   z<ErrorTree (1 total error)>Nr   rZ   rp   r	   reprrz   r   r   test_repr_singleZTestErrorTree.test_repr_single  sK    **	
 ##UG,d%BCr   c                s    \         P                  ! R RRR.RR7      \         P                  ! RRR^.R	R7      r!\         P                  ! W.4      pV P                  \	        V4      R
4       R# )r}   r   r   r   r   r   r~   r   r   r   z<ErrorTree (2 total errors)>Nr   r   rA   r   test_repr_multipleZ TestErrorTree.test_repr_multiple  sn    &&V_	
 && ]	  ##RH-d%CDr   c                sh    \         P                  ! . 4      pV P                  \        V4      R 4       R# )z<ErrorTree (0 total errors)>N)r   rp   r	   r   )r
   rq   rH   r   test_repr_emptyZTestErrorTree.test_repr_empty  s'    ##B'd%CDr   rJ   N)rK   rL   rM   rN   rr   rv   rx   r{   r|   r   r   r   r   r   r   r   r   rO   rP   rQ   rS   r   rm   rm     sQ     /#
&
6
)I'
A7 DE E Er   rm   c                   sb   a  ] tR tRt o R tR tR tR tR tR t	R t
R	 tR
 tR tR tRtV tR# )TestErrorInitReprStri  c                st    \        R RR^RR/R7      pVP                  V4       \        P                  ! R/ VB # )Zhellor   r   )messager   r%   r   r   rJ   )dictZupdater   rZ   )r
   kwargsZdefaultss   &, r   
make_errorZTestErrorInitReprStr.make_error  sB    $H%
 	))5H55r   c                s   \         P                  ! V4      P                  R 4      pV P                  ! R/ VB p\	        V4      P                  R 4      w  rEpV P                  WCP                  4       V P                  Wa4       R# )Z
NrJ   )textwrapZdedentZrstripr   strZ	partitionr	   r   )r
   Zexpectedr   rF   Zmessage_lineZ_Zrests   &&,    r   assertShowsZ TestErrorInitReprStr.assertShows  se    ??8,33D9)&) #E
 4 4T :}}5(r   c                sp    V P                  4       pV P                  \        VP                  4      ^4       R# )   N)r   ZassertGreaterZlenZargs)r
   rF   rH   r   !test_it_calls_super_and_sets_argsZ6TestErrorInitReprStr.test_it_calls_super_and_sets_args  s&    !3uzz?A.r   c                sf    V P                  \        \        P                  ! R R7      4      R4       R# )zHello!r   z<ValidationError: 'Hello!'>N)r	   r   r   rZ   r
      &r   	test_reprZTestErrorInitReprStr.test_repr  s&    ++H=>)	
r   c           	     s   \         P                  ! R 4      pV P                  \        V4      R 4       RRRRR^RRR//pV FA  p\	        V4      pWC \         P                  ! R/ VB pV P                  \        V4      R 4       KC  	  R# )	r   r   r   r%   r   r   r   Nr   )r   rZ   r	   r   r   )r
   rF   r   ZattrZkrb   r   test_unset_errorZ%TestErrorInitReprStr.test_unset_error  s    **95UY/ xvx(	
 DVA..>A>ESZ3	 r   c                s.    V P                  R . . R7       R# )z
            Failed validating 'type' in schema:
                {'type': 'string'}

            On instance:
                5
            rW   Zschema_pathNr   r   r   r   test_empty_pathsZ%TestErrorInitReprStr.test_empty_paths+  s"      	 
	
r   c                s2    V P                  R ^ .R.R7       R# )z
            Failed validating 'type' in schema:
                {'type': 'string'}

            On instance[0]:
                5
            r0   r   Nr   r   r   r   test_one_item_pathsZ(TestErrorInitReprStr.test_one_item_paths8  s&      	 	 
	
r   c                s6    V P                  R ^ R.. ROR7       R# )z
            Failed validating 'type' in schema['items'][0]:
                {'type': 'string'}

            On instance[0]['a']:
                5
            rd   r   N)r0   r    r   r   r   r   r   test_multiple_item_pathsZ-TestErrorInitReprStr.test_multiple_item_pathsE  s&     S' 	 
	
r   c                s    V P                  R \        \        ^4      4      \        \	        \        ^4      \        ^4      4      4      RR7       R# )a?  
            Failed validating 'maxLength' in schema:
                {0: 0,
                 1: 1,
                 2: 2,
                 3: 3,
                 4: 4,
                 5: 5,
                 6: 6,
                 7: 7,
                 8: 8,
                 9: 9,
                 10: 10,
                 11: 11,
                 12: 12,
                 13: 13,
                 14: 14,
                 15: 15,
                 16: 16,
                 17: 17,
                 18: 18,
                 19: 19}

            On instance:
                [0,
                 1,
                 2,
                 3,
                 4,
                 5,
                 6,
                 7,
                 8,
                 9,
                 10,
                 11,
                 12,
                 13,
                 14,
                 15,
                 16,
                 17,
                 18,
                 19,
                 20,
                 21,
                 22,
                 23,
                 24]
            Z	maxLength)r   r   r   N)r   r   ro   r   Zzipr   r   r   test_uses_pprintZ%TestErrorInitReprStr.test_uses_pprintR  sC    1d %)_E"IuRy12!k 	 6	
r   c                sN    V P                  R R^R^R^%R^I/R^IR^%R^R^/R	7       R
# )z
            Failed validating 'type' in schema:
                {'do': 3, 'not': 7, 'sort': 37, 'me': 73}

            On instance:
                {'here': 73, 'too': 37, 'no': 7, 'sorting': 3}
            ZdoZnotZsortZmeZhereZtooZnoZsorting)r   r   Nr   r   r   r   test_does_not_reorder_dictsZ0TestErrorInitReprStr.test_does_not_reorder_dicts  sP     aqb	 ra1	 	 	
r   c                s   a   ! V 3R lR4      pV! 4       p\         P                  ! RRVRRR7      pS P                  \        V4      \	        V4      4       R# )	z
Check for #164 which rendered exceptions unusable when a
`ValidationError` involved instances with an `__eq__` method
that returned truthy values.
c                   s:   <a  ] tR tRt o V3R ltV3R ltRtV tR# )dTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBroi  c                *   < SP                  R 4       R# zDon't!NZfailZthisZotherr
      &&r   __eq__ZkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__eq__      		(#r   c                r   r   r   r   r   r   __ne__ZkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__ne__  r   r   rJ   N)rK   rL   rM   rN   r   r   rO   rP   )rR   r
   s   @r   DontEQMeBror     s     $$ $r   r   rs   r   Zsomer   )r   r   r%   r   N)r   rZ   rt   r   r   )r
   r   r   rF   s   f   r   :test_str_works_with_instances_having_overriden_eq_operatorZOTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator  sM    	$ 	$ =**"
 	d8nc%j1r   rJ   N)rK   rL   rM   rN   r   r   r   r   r   r   r   r   r   r   r   rO   rP   rQ   rS   r   r   r     sB     	6)/
4"


7
r
.2 2r   r   c                   s&   a  ] tR tRt o R tRtV tR# )TestHashablei  c                sb    \         P                  ! R 4      0 \         P                  ! R 4      0 R# )Z N)r   rZ   ZSchemaErrorr   r   r   test_hashableZTestHashable.test_hashable  s$    		#	#B	'(				#$r   rJ   N)rK   rL   rM   rN   r   rO   rP   rQ   rS   r   r   r     s     % %r   r   )Zunittestr   r   Z
jsonschemar   Zjsonschema.validatorsr   r   rT   rm   r   r   rJ   r   r   <module>r      s[      ! 1BLH BLJ
1%h 1%hxEH xEv|28 |2~%8 %r   