관리-도구
편집 파일: test_exceptions.cpython-39.opt-1.pyc
a ���� 5q]�;����������������������@���s����d�dl�mZ�d�dlZd�dlmZmZ�d�dlmZ�G�dd��de�ZG�dd��de�Z G�d d ��d e�Z G�dd��de�ZG�d d��de�ZdS�)�����)�TestCaseN)�Draft4Validator� exceptions)�PY3c�������������������@���sT���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��ZdS�)� TestBestMatchc�����������������C���sH���t�|�}t�|�}t�t|��}d}|�j|���|���|�||�d��|S�)Nz:Didn't return a consistent best match! Got: {0} Then: {1})�msg)�listr���� best_match�reversed�assertEqualZ _contents�format)�self�errors�bestZ reversed_bestr�����r����D/usr/lib/python3.9/site-packages/jsonschema/tests/test_exceptions.pyr ��� ���s���� �zTestBestMatch.best_matchc�����������������C���sH���t�ddddddiid�ii�}|��|�ddg�ii��}|��|jd��d�S�) N� properties�foo�����bar�type�object)� minPropertiesr���r����r���r ����iter_errorsr���� validator�r ���r���r���r���r���r����(test_shallower_errors_are_better_matches���s���� ���� z6TestBestMatch.test_shallower_errors_are_better_matchesc�����������������C���sJ���t�dddiddigddiddigd��}|��|�i���}|��|jd��dS�)zn A property you *must* match is probably better than one you have to match a part of. r���r����stringZnumber)r����anyOf�oneOfr���Nr���r���r���r���r����%test_oneOf_and_anyOf_are_weak_matches"���s������z3TestBestMatch.test_oneOf_and_anyOf_are_weak_matchesc�������������� ���C���sR���t�dddddiddddiiigiii�}|��|�dddii��}|��|jd��d S�) 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. r���r���r���r���r���r����array����N�r���r ���r���r����validator_valuer���r���r���r����8test_if_the_most_relevant_error_is_anyOf_it_is_traversed2���s���� �����zFTestBestMatch.test_if_the_most_relevant_error_is_anyOf_it_is_traversedc�������������� ���C���sR���t�dddddiddddiiigiii�}|��|�dddii��}|��|jd��d S�) 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. r���r���r ���r���r���r���r"���r#���Nr$���r���r���r���r����8test_if_the_most_relevant_error_is_oneOf_it_is_traversedK���s���� �����zFTestBestMatch.test_if_the_most_relevant_error_is_oneOf_it_is_traversedc�������������� ���C���sR���t�dddddiddddiiigiii�}|��|�dddii��}|��|jd��d S�) 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���ZallOfr���r���r���r"���r#���Nr$���r���r���r���r����8test_if_the_most_relevant_error_is_allOf_it_is_traversedd���s���������zFTestBestMatch.test_if_the_most_relevant_error_is_allOf_it_is_traversedc�����������������C���s^���t�dddddidddiddddiiigigiii�}|��|�dddii��}|��|jd��d�S�) Nr���r���r ���r���r���r���r"���r#���r$���r���r���r���r����test_nested_context_for_oneOfy���s(�������������z+TestBestMatch.test_nested_context_for_oneOfc�����������������C���s6���t�ddi�}|�i��\}|��t�|�i���jd��d�S�)Nr���r���)r���r���r���r���r ���r���)r ���r����errorr���r���r����test_one_error����s�����zTestBestMatch.test_one_errorc�����������������C���s"���t�i��}|��t�|�i�����d�S�)N)r���ZassertIsNoner���r ���r���)r ���r���r���r���r����test_no_errors����s����zTestBestMatch.test_no_errorsN)�__name__� __module__�__qualname__r ���r���r!���r&���r'���r(���r)���r+���r,���r���r���r���r���r������s���r���c�������������������@���s,���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd S�) �TestByRelevancec�����������������C���sb���t�jddgd�}t�jdddgd�}t||gt�jd�}|��||��t||gt�jd�}|��||��d�S�)N�Oh no!Zbaz��path�Oh yes!r���r�����key)r����ValidationError�max� relevance�assertIs)r ����shallow�deep�matchr���r���r����#test_short_paths_are_better_matches����s����z3TestByRelevance.test_short_paths_are_better_matchesc�����������������C���s~���t�jdg�d�}t�jddgd�}t||gt�jd�}|��dd��|D��dgg�g��t||gt�jd�}|��dd��|D��dgg�g��d�S�) Nr1���r2���r4���r���r5���c�����������������S���s���g�|�]}t�|j��qS�r����r���r3�����.0r*���r���r���r���� <listcomp>���������zNTestByRelevance.test_global_errors_are_even_better_matches.<locals>.<listcomp>c�����������������S���s���g�|�]}t�|j��qS�r���r?���r@���r���r���r���rB�������rC���)r���r7����sortedr9���r���)r ���r;���r<���r���r���r���r����*test_global_errors_are_even_better_matches����s������z:TestByRelevance.test_global_errors_are_even_better_matchesc�����������������C���sh���t�jdg�dd�}t�jdg�dd�}t�jdd�}t||g|d�}|��||��t||g|d�}|��||��d�S�)Nr1����a�r3���r���r4����b)�weakr5����r���r7���Zby_relevancer8���r:���)r ���rI����normalr ���r=���r���r���r����'test_weak_validators_are_lower_priority����s����z7TestByRelevance.test_weak_validators_are_lower_priorityc�����������������C���s~���t�jdg�dd�}t�jdg�dd�}t�jdg�dd�}t�jddd�}t|||g|d �}|��||��t|||g|d �}|��||��d�S�) Nr1���rF���rG���r4���rH���zOh fine!�c)rI����strongr5���rJ���)r ���rI���rK���rN���r ���r=���r���r���r����*test_strong_validators_are_higher_priority����s����z:TestByRelevance.test_strong_validators_are_higher_priorityN)r-���r.���r/���r>���rE���rL���rO���r���r���r���r���r0�������s��� r0���c�������������������@���sT���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��ZdS�)� TestErrorTreec�����������������C���s.���dd��t�d�D��}t�|�}|��|jd��d�S�)Nc�����������������S���s���g�|�]}t�jd�|d��qS�)Z Something�r���)r���r7���)rA����ir���r���r���rB�������s����zQTestErrorTree.test_it_knows_how_many_total_errors_it_contains.<locals>.<listcomp>����)�ranger���� ErrorTreer���Ztotal_errors�r ���r����treer���r���r����/test_it_knows_how_many_total_errors_it_contains����s ����� z=TestErrorTree.test_it_knows_how_many_total_errors_it_containsc�����������������C���s,���t�jddgd�g}t��|�}|��d|��d�S�)N� a messager���r2���)r���r7���rU����assertInrV���r���r���r����1test_it_contains_an_item_if_the_item_had_an_error����s���� z?TestErrorTree.test_it_contains_an_item_if_the_item_had_an_errorc�����������������C���s,���t�jddgd�g}t��|�}|��d|��d�S�)NrY���r���r2���r���)r���r7���rU����assertNotInrV���r���r���r����9test_it_does_not_contain_an_item_if_the_item_had_no_error����s���� zGTestErrorTree.test_it_does_not_contain_an_item_if_the_item_had_no_errorc�����������������C���s0���t�jddd�}t��|g�}|��|jd|i��d�S�)NrY���r���rQ����r���r7���rU���r���r����r ���r*���rW���r���r���r����1test_validators_that_failed_appear_in_errors_dict����s����z?TestErrorTree.test_validators_that_failed_appear_in_errors_dictc�����������������C���sP���t�jddgd�t�jdddgd�g}t��|�}|��d|d���|��d|d���d�S�)Nz a bar messager���r2���za bar -> 0 messager�������)r���r7���rU���rZ���r\���rV���r���r���r����1test_it_creates_a_child_tree_for_each_nested_path����s����� z?TestErrorTree.test_it_creates_a_child_tree_for_each_nested_pathc�����������������C���sX���t�jddddgd�t�jddddgd��}}t��||g�}|��|d�d�j||d���d�S�) N�1r���r���r���)r���r3����2�quux)r���re���r^���)r ����e1�e2rW���r���r���r����+test_children_have_their_errors_dicts_built����s �����z9TestErrorTree.test_children_have_their_errors_dicts_builtc�����������������C���s@���t�jddddgdd�t�jddd d gdd��}}t��||g��d�S�)Nrc���r���r���Zbar2Zi1)r���r3����instancerd���re���Zfoobarr���Zi2)r���r7���rU���)r ���rf���rg���r���r���r����"test_multiple_errors_with_instance����s�������z0TestErrorTree.test_multiple_errors_with_instancec�����������������C���sR���t�jddg�d�}t��|g�}|��t���|d��W�d�����n1�sD0����Y��d�S�)NZ123r���)r���ri���r���)r���r7���rU���ZassertRaises� IndexErrorr_���r���r���r����>test_it_does_not_contain_subtrees_that_are_not_in_the_instance��s����zLTestErrorTree.test_it_does_not_contain_subtrees_that_are_not_in_the_instancec�����������������C���s6���t�jddi�dgd�}t��|g�}|��|d�t�j��dS�)z� If a validator is dumb (like :validator:`required` in draft 3) and refers to a path that isn't in the instance, the tree still properly returns a subtree for that path. rY���r���)r���ri���r3���N)r���r7���rU���ZassertIsInstancer_���r���r���r����9test_if_its_in_the_tree_anyhow_it_does_not_raise_an_error��s ���� �zGTestErrorTree.test_if_its_in_the_tree_anyhow_it_does_not_raise_an_errorN)r-���r.���r/���rX���r[���r]���r`���rb���rh���rj���rl���rm���r���r���r���r���rP�������s��� rP���c�������������������@���s\���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��Zdd��ZdS�)�TestErrorInitReprStrc�����������������K���s0���t�ddddddid�}|�|��tjf�i�|��S�)NZhellor���r�������)�messager���r%���ri����schema)�dict�updater���r7���)r ����kwargs�defaultsr���r���r���� make_error"��s����� zTestErrorInitReprStr.make_errorc�����������������K���sb���t�r|�dd�}t�|��d�}|�jf�i�|��}t|��d�\}}}|��||j ��|��||��d�S�)Nzu'�'� ) r����replace�textwrap�dedent�rstriprv����str� partitionr���rp���)r ���Zexpectedrt���r*���Zmessage_line�_�restr���r���r����assertShows-��s����z TestErrorInitReprStr.assertShowsc�����������������C���s���|�����}|��t|j�d��d�S�)Nra���)rv���Z assertGreater�len�args)r ���r*���r���r���r����!test_it_calls_super_and_sets_args7��s����z6TestErrorInitReprStr.test_it_calls_super_and_sets_argsc�����������������C���s ���|���ttjdd��dd���d�S�)NzHello!)rp���z<ValidationError: %r>)r����reprr���r7����r ���r���r���r���� test_repr;��s�����zTestErrorInitReprStr.test_reprc�����������������C���sh���t��d�}|��t|�d��dddddid�}|D�]2}t|�}||=�t�jdi�|��}|��t|�d��q0d�S�)Nrp���r���r���ro���)r���r%���ri���rq���)rp���)r���r7���r���r}���rr���)r ���r*���rt����attr�kr���r���r����test_unset_errorA��s���� �z%TestErrorInitReprStr.test_unset_errorc�����������������C���s���|�j�dg�g�d��d�S�)Nz� Failed validating u'type' in schema: {u'type': u'string'} On instance: 5 �r3���Zschema_path�r����r����r���r���r����test_empty_pathsR��s �����z%TestErrorInitReprStr.test_empty_pathsc�����������������C���s���|�j�ddgdgd��d�S�)Nz� Failed validating u'type' in schema: {u'type': u'string'} On instance[0]: 5 r����itemsr����r����r����r���r���r����test_one_item_paths_��s �����z(TestErrorInitReprStr.test_one_item_pathsc�����������������C���s���|�j�dddgg�d�d��d�S�)Nz� Failed validating u'type' in schema[u'items'][0]: {u'type': u'string'} On instance[0][u'a']: 5 r���rF���)r����r���ra���r����r����r����r���r���r����test_multiple_item_pathsl��s �����z-TestErrorInitReprStr.test_multiple_item_pathsc�����������������C���s0���|�j�dttd��tttd�td���dd��d�S�)Na@�� Failed validating u'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)ri���rq���r���)r����r���rT���rr����zipr����r���r���r����test_uses_pprinty��s����2 �z%TestErrorInitReprStr.test_uses_pprintc��������������������sF���G���fdd�dt��}|��}tjdd|ddd�}���t|�t|���dS�) z� Check for https://github.com/Julian/jsonschema/issues/164 which rendered exceptions unusable when a `ValidationError` involved instances with an `__eq__` method that returned truthy values. c�����������������������s$���e�Zd�Z��fdd�Z��fdd�ZdS�)zdTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBroc��������������������s�������d��d�S��NzDon't!�Zfail��this�otherr����r���r����__eq__���s����zkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__eq__c��������������������s�������d��d�S�r����r����r����r����r���r����__ne__���s����zkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__ne__N)r-���r.���r/���r����r����r���r����r���r����DontEQMeBro���s���r����rY���r���Zsomerq���)r���ri���r%���rq���N)r���r���r7���rZ���r����r}���)r ���r����ri���r*���r���r����r����:test_str_works_with_instances_having_overriden_eq_operator���s�����zOTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operatorN) r-���r.���r/���rv���r����r����r����r����r����r����r����r����r����r���r���r���r���rn���!��s��� 9rn���c�������������������@���s���e�Zd�Zdd��ZdS�)�TestHashablec�����������������C���s$���t�t�d�g��t�t�d�g��d�S�)N��)�setr���r7���ZSchemaErrorr����r���r���r���� test_hashable���s����zTestHashable.test_hashableN)r-���r.���r/���r����r���r���r���r���r�������s���r����) Zunittestr���rz���Z jsonschemar���r���Zjsonschema.compatr���r���r0���rP���rn���r����r���r���r���r����<module>���s����4N�+