+
    P4iL                         ^ 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                      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V tR# )TestBestMatchc                2   \        \        V4      P                  V4      4      p\        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 consistent best match!
Got: z

Then: )	listr   iter_errorsr   
best_matchiterreversedassertEqual	_contents)selfinstanceschemaerrorsbestreversed_bests   &&&   B/usr/lib/python3/dist-packages/jsonschema/tests/test_exceptions.pybest_match_ofTestBestMatch.best_match_of	   s    of-99(CD$$T&\2"--hv.>?NN##%.tfJ}oN	

     c                    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   s   &  r   (test_shallower_errors_are_better_matches6TestBestMatch.test_shallower_errors_are_better_matches   sa    #Q 568*<"=
 !!EE2;+?!O9r   c                    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   stringnumberoneOfr!   Nr"   r$   s   &  r   %test_oneOf_and_anyOf_are_weak_matches3TestBestMatch.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$   s   &  r   8test_if_the_most_relevant_error_is_anyOf_it_is_traversedFTestBestMatch.test_if_the_most_relevant_error_is_anyOf_it_is_traversed.   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$   s   &  r   3test_no_anyOf_traversal_for_equally_relevant_errorsATestBestMatch.test_no_anyOf_traversal_for_equally_relevant_errorsE   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$   s   &  r   6test_anyOf_traversal_for_single_equally_relevant_errorDTestBestMatch.test_anyOf_traversal_for_single_equally_relevant_errorU   F     "

 !!2f!=0r   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 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!   Nr0   r$   s   &  r   8test_if_the_most_relevant_error_is_oneOf_it_is_traversedFTestBestMatch.test_if_the_most_relevant_error_is_oneOf_it_is_traversedc   r4   r   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 oneOf (as above) if all of its context errors
seem to be equally "wrong" against the instance.
r+   r   r)   r6   r    r!   Nr"   r$   s   &  r   3test_no_oneOf_traversal_for_equally_relevant_errorsATestBestMatch.test_no_oneOf_traversal_for_equally_relevant_errorsz   r9   r   c                r    RRR/./pV P                  . VR7      pV P                  VP                  R4       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$   s   &  r   6test_oneOf_traversal_for_single_equally_relevant_errorDTestBestMatch.test_oneOf_traversal_for_single_equally_relevant_error   r=   r   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	# )
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   allOfr   r)   r   r/   r!   Nr0   r$   s   &  r   8test_if_the_most_relevant_error_is_allOf_it_is_traversedFTestBestMatch.test_if_the_most_relevant_error_is_allOf_it_is_traversed   ss     *%/@'AB	
 !!EE2;+?!O--x8r   c           
         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!   Nr0   r$   s   &  r   test_nested_context_for_oneOf+TestBestMatch.test_nested_context_for_oneOf   s     *#!' 2$0(-/@3&!"&	
& !!EE2;+?!O--w7r   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 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   	reordereds   &   r   "test_it_prioritizes_matching_types0TestBestMatch.test_it_prioritizes_matching_types   s    *a8;;	
 !!E5>&!I5 ;;*a8	
	 !!E5>)!L5r   c                   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    rO   r6   r)   rP   r   r!   Nr"   rQ   s   &   r   (test_it_prioritizes_matching_union_types6TestBestMatch.test_it_prioritizes_matching_union_types   s    '8!4j!D)X!6RH	
 !!E5>&!I5 ;;*a8	
	 !!E5>)!L5r   c                r    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$   s   &  r   test_boolean_schemas"TestBestMatch.test_boolean_schemas   s;    /!!E5>&!I$..)r   c                    \        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#   errors   &  r   test_one_errorTestBestMatch.test_one_error  sS    #_a$89	&&r*!!)"7"7";<FF	
r   c                    \        / 4      pV P                  \        P                  ! VP	                  / 4      4      4       R # )N)r   rY   r   r   r
   )r   r#   s   & r   test_no_errorsTestBestMatch.test_no_errors
  s0    #B'	*//	0E0Eb0IJKr    N)__name__
__module____qualname____firstlineno__r   r%   r,   r2   r7   r;   r?   rB   rE   rI   rL   rS   rV   rZ   r^   ra   __static_attributes____classdictcell____classdict__s   @r   r   r      s\     	
::8.2 18.2 19&886666*

L Lr   r   c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )TestByRelevancei  c                    \         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!bazpathOh yes!r   r   keyN)r   ValidationErrormax	relevanceassertIs)r   shallowdeepmatchs   &   r   #test_short_paths_are_better_matches3TestByRelevance.test_short_paths_are_better_matches  sl    ,,XUGD)))5%.IWO)=)=>e%TO)=)=>e%r   c                   \         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 )ro   rq   rs   r   rt   N)r   rv   sortedrx   r   r	   rr   )r   rz   r{   r   r]   s   &    r   *test_global_errors_are_even_better_matches:TestByRelevance.test_global_errors_are_even_better_matches  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                   \         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# )ro   arr   r#   rs   b)weakrt   Nr   rv   by_relevancerw   ry   )r   r   normalr   r|   s   &    r   %test_weak_keywords_are_lower_priority5TestByRelevance.test_weak_keywords_are_lower_priority)  sn    ))(sK++IB#N,,#6
TN
3e$VN
3e$r   c                L   \         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	# )
ro   r   r   rs   r   zOh fine!c)r   strongrt   Nr   )r   r   r   r   r   r|   s   &     r   (test_strong_keywords_are_higher_priority8TestByRelevance.test_strong_keywords_are_higher_priority5  s    ))(sK++IB#N++JR3O,,#cB
T6*
;e$VT*
;e$r   rc   N)
rd   re   rf   rg   r}   r   r   r   rh   ri   rj   s   @r   rm   rm     s     &
 
%% %r   rm   c                   h   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V tR# )TestErrorTreeiC  c                    \        ^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 )   	Somethingr#   N)ranger   rv   	ErrorTreer   total_errors)r   ir   trees   &   r   /test_it_knows_how_many_total_errors_it_contains=TestErrorTree.test_it_knows_how_many_total_errors_it_containsD  sb     1X
 &&{a@ 	 
 ##F+**A.
s   !A%c                    \         P                  ! R R.R7      .p\         P                  ! V4      pV P                  RV4       R# )	a messager   rq   N)r   rv   r   assertInr   r   r   s   &  r   1test_it_contains_an_item_if_the_item_had_an_error?TestErrorTree.test_it_contains_an_item_if_the_item_had_an_errorM  s7    ,,[wGH##F+eT"r   c                    \         P                  ! R R.R7      .p\         P                  ! V4      pV P                  RV4       R# )r   r   rq   r   N)r   rv   r   assertNotInr   s   &  r   9test_it_does_not_contain_an_item_if_the_item_had_no_errorGTestErrorTree.test_it_does_not_contain_an_item_if_the_item_had_no_errorR  s9    ,,[wGH##F+%r   c                    \         P                  ! R RR7      p\         P                  ! V.4      pV P                  VP                  RV/4       R# )r   r   r   Nr   rv   r   r   r   r   r]   r   s   &  r   /test_keywords_that_failed_appear_in_errors_dict=TestErrorTree.test_keywords_that_failed_appear_in_errors_dictW  s>    **;%H##UG,uen5r   c                    \         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   rq   za bar -> 0 messageN)r   rv   r   r   r   r   s   &  r   1test_it_creates_a_child_tree_for_each_nested_path?TestErrorTree.test_it_creates_a_child_tree_for_each_nested_path\  sh    &&eWE&&';5!*M
 ##F+ae%DK(r   c                    \         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#   rr   2quuxNr   r   e1e2r   s   &   r   +test_children_have_their_errors_dicts_built9TestErrorTree.test_children_have_their_errors_dicts_builte  sn    &&se5!*M&&sfE1:N  ##RH-eQ..FB0GHr   c                    \         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#   rr   r   r   r   foobari2N)r   rv   r   )r   r   r   s   &  r   "test_multiple_errors_with_instance0TestErrorTree.test_multiple_errors_with_instancem  sW    &&V_	
 && ]	  	bX&r   c                    \         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)123r   )r#   r   N)r   rv   r   assertRaises
IndexErrorr   s   &  r   >test_it_does_not_contain_subtrees_that_are_not_in_the_instanceLTestErrorTree.test_it_does_not_contain_subtrees_that_are_not_in_the_instance|  sO    **5EBO##UG,z**G +***s   
A""A3	c                    \         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.
r   r   )r#   r   rr   N)r   rv   r   assertIsInstancer   s   &  r   9test_if_its_in_the_tree_anyhow_it_does_not_raise_an_errorGTestErrorTree.test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error  sM     **52UG
 ##UG,d5k:+?+?@r   c                    \         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   rv   r   r   reprr   s   &  r   test_repr_singleTestErrorTree.test_repr_single  sK    **	
 ##UG,d%BCr   c                    \         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   s   &   r   test_repr_multiple TestErrorTree.test_repr_multiple  sn    &&V_	
 && ]	  ##RH-d%CDr   c                h    \         P                  ! . 4      pV P                  \        V4      R 4       R# )z<ErrorTree (0 total errors)>N)r   r   r   r   )r   r   s   & r   test_repr_emptyTestErrorTree.test_repr_empty  s'    ##B'd%CDr   rc   N)rd   re   rf   rg   r   r   r   r   r   r   r   r   r   r   r   r   rh   ri   rj   s   @r   r   r   C  sL     /#
&
6
)I'
ADE E Er   r   c                   \   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V tR# )TestErrorInitReprStri  c                t    \        R RR^RR/R7      pVP                  V4       \        P                  ! R/ VB # )hellor   r)   )messager#   r1   r   r   rc   )dictupdater   rv   )r   kwargsdefaultss   &, r   
make_errorTestErrorInitReprStr.make_error  sB    $H%
 	))5H55r   c                   \         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# )
Nrc   )textwrapdedentrstripr   str	partitionr   r   )r   expectedr   r]   message_line_rests   &&,    r   assertShows TestErrorInitReprStr.assertShows  se    ??8,33D9)&) #E
 4 4T :}}5(r   c                p    V P                  4       pV P                  \        VP                  4      ^4       R# )   N)r   assertGreaterlenargs)r   r]   s   & r   !test_it_calls_super_and_sets_args6TestErrorInitReprStr.test_it_calls_super_and_sets_args  s&    !3uzz?A.r   c                f    V P                  \        \        P                  ! R R7      4      R4       R# )zHello!r   z<ValidationError: 'Hello!'>N)r   r   r   rv   r   s   &r   	test_reprTestErrorInitReprStr.test_repr  s&    ++H=>)	
r   c           	        \         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   r1   r)   r   r   Nr   )r   rv   r   r   r   )r   r]   r   attrks   &    r   test_unset_error%TestErrorInitReprStr.test_unset_error  s    **95UY/ xvx(	
 DVA..>A>ESZ3	 r   c                .    V P                  R . . R7       R# )z
            Failed validating 'type' in schema:
                {'type': 'string'}

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

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

            On instance[0]['a']:
                5
            r   r  N)r  r   r   r  r   s   &r   test_multiple_item_paths-TestErrorInitReprStr.test_multiple_item_paths  s&     S' 	 
	
r   c                    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]
            	maxLength)r   r   r#   N)r   r	   r   r   zipr   s   &r   test_uses_pprint%TestErrorInitReprStr.test_uses_pprint  sC    1d %)_E"IuRy12!k 	 6	
r   c                   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                   :   <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>.DontEQMeBroiD  c                *   < SP                  R 4       R# zDon't!Nfailthisotherr   s   &&r   __eq__kTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__eq__E      		(#r   c                *   < SP                  R 4       R# r  r  r  s   &&r   __ne__kTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__ne__H  r  r   rc   N)rd   re   rf   rg   r  r   rh   ri   )rk   r   s   @r   DontEQMeBror  D  s     $$ $r   r"  r   r   somer   )r#   r   r1   r   N)r   rv   r   r   r   )r   r"  r   r]   s   f   r   :test_str_works_with_instances_having_overriden_eq_operatorOTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator=  sM    	$ 	$ =**"
 	d8nc%j1r   rc   N)rd   re   rf   rg   r   r   r   r   r   r  r  r  r  r$  rh   ri   rj   s   @r   r   r     s=     	6)/
4"


7
r2 2r   r   c                   &   a  ] tR tRt o R tRtV tR# )TestHashableiV  c                    \        \        P                  ! R 4      .4       \        \        P                  ! R 4      .4       R# ) N)setr   rv   SchemaErrorr   s   &r   test_hashableTestHashable.test_hashableW  s.    Z''+,-Z##B'()r   rc   N)rd   re   rf   rg   r,  rh   ri   rj   s   @r   r'  r'  V  s     * *r   r'  )unittestr   r   
jsonschemar   jsonschema.validatorsr   r   rm   r   r   r'  rc   r   r   <module>r1     s[      ! 1DLH DLN1%h 1%hhEH hEVe28 e2P*8 *r   