L i^ddlmZddlZddlZddlmZddlmZGddeZGddeZ Gd d eZ Gd d eZ Gd deZ GddeZ y))TestCaseN) exceptions)_LATEST_VERSIONceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZy) TestBestMatchcftt|j|}d|d|d}|j||t j t |}t j t|}|j|j|jd|d||S)NzNo errors found for z under !)msgzNo consistent best match! Got: z Then: ) listr iter_errors assertTruer best_matchiterreversed assertEqual _contents)selfinstanceschemaerrorsr best reversed_bests f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/jsonschema/tests/test_exceptions.py best_match_ofzTestBestMatch.best_match_of sof-99(CD%hZwvjB C($$T&\2"--hv.>?   NN   # # %.tfJ}o N  cddddddiidii}|jddgii|}|j|jd y) N propertiesfoobartypeobject) minPropertiesrrrr#rr validatorrrrs r(test_shallower_errors_are_better_matchesz6TestBestMatch.test_shallower_errors_are_better_matchess] %&#(68*<"= !!EE2;+?!O 9rcdddiddigddiddigd}|ji|}|j|jdy) zn A property you *must* match is probably better than one you have to match a part of. rr!stringnumber)r#anyOfoneOfr$r#Nr%r's r%test_oneOf_and_anyOf_are_weak_matchesz3TestBestMatch.test_oneOf_and_anyOf_are_weak_matches&s]x(68*<=x(68*<=  !!2f!= 9rcdddddiddddiiigiii}|jdddii| }|j|jdy ) aL 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. rrr,r!r*r array r$Nrrvalidator_valuer's r8test_if_the_most_relevant_error_is_anyOf_it_is_traversedzFTestBestMatch.test_if_the_most_relevant_error_is_anyOf_it_is_traversed4s *%/@'AB  !!EE2;+?!O --w7rc|dddiddiddigi}|jg|}|j|jdy)z 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 r3test_no_anyOf_traversal_for_equally_relevant_errorszATestBestMatch.test_no_anyOf_traversal_for_equally_relevant_errorsKV "#" !!2f!= 1rcpdddigi}|jg|}|j|jdy)z 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 r6test_anyOf_traversal_for_single_equally_relevant_errorzDTestBestMatch.test_anyOf_traversal_for_single_equally_relevant_error[F "  !!2f!= 0rcxddddiigi}|jddg|}|j|jdy)z| We *do* traverse anyOf with a single subschema that fails multiple times (e.g. on multiple items). r,itemsconst%r1r$Nr%r's r.test_anyOf_traversal_for_single_sibling_errorszr?r@r1r$Nr%r's r9test_anyOf_traversal_for_non_type_matching_sibling_errorszGTestBestMatch.test_anyOf_traversal_for_non_type_matching_sibling_errorswV "7B-(  !!B8F!C 1rcdddddiddddiiigiii}|jdddii| }|j|jdy ) aL 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. rrr-r!r*r r0r1r$Nr2r's r8test_if_the_most_relevant_error_is_oneOf_it_is_traversedzFTestBestMatch.test_if_the_most_relevant_error_is_oneOf_it_is_traversedr5rc|dddiddiddigi}|jg|}|j|jdy)z 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*r7r"r$Nr%r's r3test_no_oneOf_traversal_for_equally_relevant_errorszATestBestMatch.test_no_oneOf_traversal_for_equally_relevant_errorsr9rcpdddigi}|jg|}|j|jdy)z 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 r6test_oneOf_traversal_for_single_equally_relevant_errorzDTestBestMatch.test_oneOf_traversal_for_single_equally_relevant_errorr<rcxddddiigi}|jddg|}|j|jdy)z| We *do* traverse oneOf with a single subschema that fails multiple times (e.g. on multiple items). r-r>r?r@r1r$Nr%r's r.test_oneOf_traversal_for_single_sibling_errorszr?r@r1r$Nr%r's r9test_oneOf_traversal_for_non_type_matching_sibling_errorszGTestBestMatch.test_oneOf_traversal_for_non_type_matching_sibling_errorsrErcdddddiddddiiigiii}|jdddii| }|j|jdy ) 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. rrallOfr!r*r r0r1r$Nr2r's r8test_if_the_most_relevant_error_is_allOf_it_is_traversedzFTestBestMatch.test_if_the_most_relevant_error_is_allOf_it_is_traversedss *%/@'AB  !!EE2;+?!O --x8rc dddddidddiddddiiigigiii}|jdddii| }|j|jdy ) zp We traverse into nested contexts (a oneOf containing an error in a nested oneOf here). rrr-r!r*r r0r1r$Nr2r's rtest_nested_context_for_oneOfz+TestBestMatch.test_nested_context_for_oneOfs *#!' 2$0(-/@3&!"&   &!!EE2;+?!O --w7rcddddddddd giii}|jdd i| }|j|jd dddddd dddgiii}|jdd i| }|j|jd y) Nrrr,r0rr!minItemsr* r! minLengthr r$rZr%rrr reordereds r"test_it_prioritizes_matching_typesz0TestBestMatch.test_it_prioritizes_matching_typess !(a8!);  !!E5>&!I 5 !);!(a8  !!E5>)!L 5rcdddddgdddd gd d giii}|jdd i| }|j|jddddd d d dddgiii}|jdd i| }|j|jdy)Nrrr,r0r"rrVr7r*rXrYr r$rZr%r[s r(test_it_prioritizes_matching_union_typesz6TestBestMatch.test_it_prioritizes_matching_union_types"s ")8!4!D"+X!6RH  !!E5>&!I 5 !);!(a8  !!E5>)!L 5rcpdddii}|jddi|}|j|jy)NrrFr r$)r assertIsNoner&r's rtest_boolean_schemasz"TestBestMatch.test_boolean_schemas=s;/!!E5>&!I $..)rctddi}|ji\}|jtj|jij dy)Nr#r)rr rrrr&)rr&errors rtest_one_errorzTestBestMatch.test_one_errorBsS#_a$89 &&r*   ! !)"7"7"; < F F  rcti}|jtj|j iy)N)rrarrr )rr&s rtest_no_errorszTestBestMatch.test_no_errorsJs0#B'  *// 0E0Eb0IJKrN)__name__ __module__ __qualname__rr(r.r4r8r;rArDrGrIrKrMrOrRrTr]r_rbrergrrrr sg  : :8.2 1 2 28.2 1 2 29&886666*  Lrrc$eZdZdZdZdZdZy)TestByRelevancec"tjddg}tjdddg}t||gtj}|j ||t||gtj}|j ||y)NOh no!bazpathOh yes!rr key)rValidationErrormax relevanceassertIs)rshallowdeepmatchs r#test_short_paths_are_better_matchesz3TestByRelevance.test_short_paths_are_better_matchesPst,,XUGD)))5%.IWdO)=)=> eW%T7O)=)=> eW%rctjdg}tjddg}t||gtj}|j |Dcgc]}t |j c}dgggt||gtj}|j |Dcgc]}t |j c}dgggycc}wcc}w)Nrorqrsrrt)rrvsortedrxrr rr)rrzr{rrds r*test_global_errors_are_even_better_matchesz:TestByRelevance.test_global_errors_are_even_better_matchesYs,,XB?)))5'B$Z-A-AB +1 2%T%**  2WbM wZ-A-AB +1 2%T%**  2WbM 3 3s C/Cctjdgd}tjdgd}tjd}t||g|}|j ||t||g|}|j ||y)Nroarrr&rsb)weakrtrrv by_relevancerwry)rrnormalrr|s r%test_weak_keywords_are_lower_priorityz5TestByRelevance.test_weak_keywords_are_lower_priorityisv))(sK++IB#N,,#6 T6N 3 eV$VTN 3 eV$rcJtjdgd}tjdgd}tjdgd}tjdd}t|||g| }|j ||t|||g| }|j ||y) NrorrrsrzOh fine!c)rstrongrtr)rrrrrr|s r(test_strong_keywords_are_higher_priorityz8TestByRelevance.test_strong_keywords_are_higher_priorityus))(sK++IB#N++JR3O,,#cB T66* ; eV$VVT* ; eV$rN)rhrirjr}rrrrkrrrmrmOs& % %rrmcZeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd Zy) TestErrorTreectdDcgc]}tjd|}}tj|}|j |j dycc}w)N Somethingr&)rangerrv ErrorTreer total_errors)rirtrees r/test_it_knows_how_many_total_errors_it_containsz=TestErrorTree.test_it_knows_how_many_total_errors_it_containss_1X   & &{a @  ##F+ **A.  sA ctjddgg}tj|}|jd|y)N a messager rq)rrvrassertInrrrs r1test_it_contains_an_item_if_the_item_had_an_errorz?TestErrorTree.test_it_contains_an_item_if_the_item_had_an_errors7,,[wGH##F+ eT"rctjddgg}tj|}|jd|y)Nrr rqr)rrvr assertNotInrs r9test_it_does_not_contain_an_item_if_the_item_had_no_errorzGTestErrorTree.test_it_does_not_contain_an_item_if_the_item_had_no_errors9,,[wGH##F+ %rctjdd}tj|g}|j|jd|iy)Nrrrrrvrrrrrdrs r/test_keywords_that_failed_appear_in_errors_dictz=TestErrorTree.test_keywords_that_failed_appear_in_errors_dicts>**;%H##UG, uen5rctjddgtjdddgg}tj|}|jd|d|j d|dy)Nz a bar messager rqza bar -> 0 messager)rrvrrrrs r1test_it_creates_a_child_tree_for_each_nested_pathz?TestErrorTree.test_it_creates_a_child_tree_for_each_nested_pathsh  & &eW E  & &';5!* M ##F+ ae% DK(rctjddddgtjddddg}}tj||g}|j|ddj||dy) N1rr r)r&rr2quux)rrrre1e2rs r+test_children_have_their_errors_dicts_builtz9TestErrorTree.test_children_have_their_errors_dicts_builtsn  & &se5!* M  & &sfE1: N ##RH- eQ..B0GHrctjddddgdtjddd d gd }}tj||gy Nrrr bar2i1r&rrrrrfoobarri2)rrvr)rrrs r"test_multiple_errors_with_instancez0TestErrorTree.test_multiple_errors_with_instances[  & &V_    & & ]    b"X&rctjddg}tj|g}|jt5|ddddy#1swYyxYw)N123r)r&rr)rrvr assertRaises IndexErrorrs r>test_it_does_not_contain_subtrees_that_are_not_in_the_instancezLTestErrorTree.test_it_does_not_contain_subtrees_that_are_not_in_the_instancesR**5EBO##UG,   z *  G   s AActjddidg}tj|g}|j|dtjy)z If a keyword refers to a path that isn't in the instance, the tree still properly returns a subtree for that path. rr)r&rrrN)rrvrassertIsInstancers r9test_if_its_in_the_tree_anyhow_it_does_not_raise_an_errorzGTestErrorTree.test_if_its_in_the_tree_anyhow_it_does_not_raise_an_errorsM ** 52UG ##UG, d5k:+?+?@rctjddddgdtjddd d gd }}tj||g}|jt |dd hyr)rrvrrsetrs r test_iterzTestErrorTree.test_itersv  & &V_    & & ]   ##RH- TUH$56rctjddddgd}tj|g}|jt |dy)Nrrr rrrzrrvrrreprrs rtest_repr_singlezTestErrorTree.test_repr_singlesK**    ##UG, d%BCrctjddddgdtjddd d gd }}tj||g}|jt |d y) Nrrr rrrrrrrrzrrs rtest_repr_multiplez TestErrorTree.test_repr_multiplesr  & &V_    & & ]   ##RH- d%CDrcdtjg}|jt|dy)Nz)rrrr)rrs rtest_repr_emptyzTestErrorTree.test_repr_emptys'##B' d%CDrN)rhrirjrrrrrrrrrrrrrrkrrrrsH/# & 6 )I ' A7 DE ErrcNeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z y ) TestErrorInitReprStrc rtddddddi}|j|tjdi|S)Nhellor!r*)messager&r3rrrk)dictupdaterrv)rkwargsdefaultss r make_errorzTestErrorInitReprStr.make_errorsB$H%   ))5H55rc tj|jd}|jdi|}t |j d\}}}|j ||j|j ||y)N rk)textwrapdedentrstriprstr partitionrr)rexpectedrrd message_line_rests r assertShowsz TestErrorInitReprStr.assertShows sm??8,33D9)&) #E 4 4T : a u}}5 x(rcn|j}|jt|jdy)Nr)r assertGreaterlenargs)rrds r!test_it_calls_super_and_sets_argsz6TestErrorInitReprStr.test_it_calls_super_and_sets_argss&! 3uzz?A.rcb|jttjddy)NzHello!rz)rrrrvrs r test_reprzTestErrorInitReprStr.test_reprs&  ++H= > ) rctjd}|jt|ddddddid}|D]@}t |}||=tjdi|}|jt|dBy)Nrr!r*r)r&r3rrr)rrvrrr)rrdrattrks rtest_unset_errorz%TestErrorInitReprStr.test_unset_errors**95 UY/ 'x(   4DV A$..>A>E   SZ 3  4rc,|jdggy)Nz Failed validating 'type' in schema: {'type': 'string'} On instance: 5 rr schema_pathrrs rtest_empty_pathsz%TestErrorInitReprStr.test_empty_paths-s"    rc0|jddgdgy)Nz Failed validating 'type' in schema: {'type': 'string'} On instance[0]: 5 rr>rrrs rtest_one_item_pathsz(TestErrorInitReprStr.test_one_item_paths:s&     rc4|jdddggdy)Nz Failed validating 'type' in schema['items'][0]: {'type': 'string'} On instance[0]['a']: 5 rr)r>rrrrrs rtest_multiple_item_pathsz-TestErrorInitReprStr.test_multiple_item_pathsGs&  S'  rc |jdttdtt tdtddy)Na? 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)rrr&)rr rrziprs rtest_uses_pprintz%TestErrorInitReprStr.test_uses_pprintTsC 1 d%)_E"IuRy12!k 6 rc @|jdddddddddddy) Nz Failed validating 'type' in schema: {'do': 3, 'not': 7, 'sort': 37, 'me': 73} On instance: {'here': 73, 'too': 37, 'no': 7, 'sorting': 3} r@I)donotsortme)heretoonosorting)rrrrs rtest_does_not_reorder_dictsz0TestErrorInitReprStr.test_does_not_reorder_dictss@      rcGfdd}|}tjdd|dd}jt|t |y) z Check for #164 which rendered exceptions unusable when a `ValidationError` involved instances with an `__eq__` method that returned truthy values. c"eZdZfdZfdZy)dTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator..DontEQMeBroc(jdyNzDon't!failthisotherrs r__eq__zkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator..DontEQMeBro.__eq__ (#rc(jdyrrrs r__ne__zkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator..DontEQMeBro.__ne__rrN)rhrirjrrrsr DontEQMeBrors  $ $rrrrsomer)r&rr3rN)rrvrrr)rrrrds` r:test_str_works_with_instances_having_overriden_eq_operatorzOTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operatorsM $ $=** "   d8nc%j1rN)rhrirjrrrrrrrrrr rrkrrrrs: 6)/ 4"      7 r .2rrceZdZdZy) TestHashablec\tjdhtjdhy)N)rrv SchemaErrorrs r test_hashablezTestHashable.test_hashables$  # #B '(    #$rN)rhrirjr"rkrrrrs%rrc`eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZy)TestJsonPathRenderingctj|gddd}|j}|j||t j |j jd}|j||y)Nrrr)rrrr&rr)rrv json_pathr jsonpath_ngparserightfields)r property_name expected_pathrdrendered_json_pathre_parsed_names rvalidate_json_path_renderingz2TestJsonPathRendering.validate_json_path_renderingso**  #__ +];$**+=>DDKKAN 7rc(|jddy)Nxz$.xr/rs r test_basicz TestJsonPathRendering.test_basics ))#u5rc(|jddy)Nr z$['']r2rs r test_emptyz TestJsonPathRendering.test_emptys ))"g6rc(|jddy)Nrz$['1']r2rs r test_numberz!TestJsonPathRendering.test_number ))#x8rc(|jddy)N.z$['.']r2rs r test_periodz!TestJsonPathRendering.test_periodr8rc(|jddy)N'z$['\'']r2rs rtest_single_quotez'TestJsonPathRendering.test_single_quotes ))#z:rc(|jddy)N z$[' ']r2rs r test_spacez TestJsonPathRendering.test_spacer8rc(|jddy)N\z$['\\']r2rs rtest_backslashz$TestJsonPathRendering.test_backslashs ))$ ;rc(|jddy)Nz\'z $['\\\'']r2rs rtest_backslash_single_quotez1TestJsonPathRendering.test_backslash_single_quotes ))%>rc(|jddy)Nrz$['_']r2rs rtest_underscorez%TestJsonPathRendering.test_underscores ))#y9rc(|jddy)N"z$['"']r2rs rtest_double_quotez'TestJsonPathRendering.test_double_quotes ))#|rc(|jddy)N[z$['[']r2rs rtest_open_bracketz'TestJsonPathRendering.test_open_bracketr8rN)rhrirjr/r3r5r7r;r>rArDrFrHrKrNrPrSrkrrr$r$sH 86799;9<?:=9?9rr$)unittestrrr' jsonschemarjsonschema.validatorsrrrmrrrr$rkrrrWsj!1BLHBLJ 1%h1%hxEHxEv|28|2~%8% 49H49r