%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/jsonschema/tests/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/jsonschema/tests/__pycache__/test_exceptions.cpython-312.pyc

�

`��d�J���ddlmZddlZddlmZddlmZGd�de�ZGd�de�ZGd	�d
e�Z	Gd�de�Z
Gd
�de�Zy)�)�TestCaseN)�
exceptions)�_LATEST_VERSIONc�l�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zy)�
TestBestMatchc�.�tt|�j|��}tjt|��}tjt
|��}|j|j�|j�d|�d|���|S)NzNo 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_ofzTestBestMatch.best_match_of	s����o�f�-�9�9�(�C�D���$�$�T�&�\�2��"�-�-�h�v�.>�?�
�����N�N���#�#�%�.�t�f�J�}�o�N�	
�
��c��ddddddiid�ii}|jddgii|��}|j|jd	�y)
N�
properties�foo��bar�type�object)�
minPropertiesr�rrr �rr�	validator�rrrs   r�(test_shallower_errors_are_better_matchesz6TestBestMatch.test_shallower_errors_are_better_matchess]����%&�#(�6�8�*<�"=���
���!�!�E�E�2�;�+?��!�O���������9rc��dddiddigddiddigd�}|ji|��}|j|jd�y)	zn
        A property you *must* match is probably better than one you have to
        match a part of.
        rr�string�number)r �anyOf�oneOfr!r Nr"r$s   r�%test_oneOf_and_anyOf_are_weak_matchesz3TestBestMatch.test_oneOf_and_anyOf_are_weak_matches s]����x�(�6�8�*<�=��x�(�6�8�*<�=�
��
�!�!�2�f�!�=���������9rc��dddddiddddiiigiii}|jdddii|�	�}|j|jd�y
)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)rr'r�array�r!N�rr�validator_valuer$s   r�8test_if_the_most_relevant_error_is_anyOf_it_is_traversedzFTestBestMatch.test_if_the_most_relevant_error_is_anyOf_it_is_traversed.�s��
�����*�%����/@�'A�B����	
���!�!�E�E�2�;�+?��!�O������-�-�w�7rc�|�dddiddiddigi}|jg|��}|j|jd�y)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)rr'�integerrr!Nr"r$s   r�3test_no_anyOf_traversal_for_equally_relevant_errorszATestBestMatch.test_no_anyOf_traversal_for_equally_relevant_errorsE�V��
���"���#���"��
���!�!�2�f�!�=���������1rc�p�dddigi}|jg|��}|j|jd�y)z�
        We *do* traverse anyOf with a single nested error, even though it is
        vacuously equally relevant to itself.
        r)rr'r!Nr"r$s   r�6test_anyOf_traversal_for_single_equally_relevant_errorzDTestBestMatch.test_anyOf_traversal_for_single_equally_relevant_errorU�F��
���"��
��
�!�!�2�f�!�=���������0rc��dddddiddddiiigiii}|jdddii|�	�}|j|jd�y
)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*rr'rr-r.r!Nr/r$s   r�8test_if_the_most_relevant_error_is_oneOf_it_is_traversedzFTestBestMatch.test_if_the_most_relevant_error_is_oneOf_it_is_traversedcr2rc�|�dddiddiddigi}|jg|��}|j|jd�y)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*rr'r4rr!Nr"r$s   r�3test_no_oneOf_traversal_for_equally_relevant_errorszATestBestMatch.test_no_oneOf_traversal_for_equally_relevant_errorszr6rc�p�dddigi}|jg|��}|j|jd�y)z�
        We *do* traverse oneOf with a single nested error, even though it is
        vacuously equally relevant to itself.
        r*rr'r!Nr"r$s   r�6test_oneOf_traversal_for_single_equally_relevant_errorzDTestBestMatch.test_oneOf_traversal_for_single_equally_relevant_error�r9rc��dddddiddddiiigiii}|jdddii|�	�}|j|jd�y
)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.
        rr�allOfrr'rr-r.r!Nr/r$s   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����	
���!�!�E�E�2�;�+?��!�O������-�-�x�8rc
��dddddidddiddddiiigigiii}|jdddii|�	�}|j|jd�y
)zp
        We traverse into nested contexts (a oneOf containing an error in a
        nested oneOf here).
        rrr*rr'rr-r.r!Nr/r$s   r�test_nested_context_for_oneOfz+TestBestMatch.test_nested_context_for_oneOf�s���
�����*�#�!'�� 2�$0�(-���/@�3&�!"�&�	����
��&�!�!�E�E�2�;�+?��!�O������-�-�w�7rc��dddddd�ddd	�giii}|jdd
i|��}|j|jd�dddddd	�ddd�giii}|jdd
i|��}|j|jd�y)
Nrrr)r-r�r�minItemsr'�
�r�	minLengthrr!rJr"�rrr�	reordereds    r�"test_it_prioritizes_matching_typesz0TestBestMatch.test_it_prioritizes_matching_types�s������!(�a�8�!)��;����	
���!�!�E�5�>�&�!�I���������5�
���!)��;�!(�a�8����	
�	��!�!�E�5�>�)�!�L���������5rc��dddddgdd�dd	gd
d�giii}|jddi|�
�}|j|jd�dddd	d
d�ddd�giii}|jddi|�
�}|j|jd�y)Nrrr)r-rrrFr4r'rHrIrr!rJr"rKs    r�(test_it_prioritizes_matching_union_typesz6TestBestMatch.test_it_prioritizes_matching_union_types�s������")�8�!4�!�D�"+�X�!6�R�H����	
���!�!�E�5�>�&�!�I���������5�
���!)��;�!(�a�8����	
�	��!�!�E�5�>�)�!�L���������5rc�p�dddii}|jddi|��}|j|j�y)NrrFrr!)r�assertIsNoner#r$s   r�test_boolean_schemasz"TestBestMatch.test_boolean_schemas�s;������/���!�!�E�5�>�&�!�I�����$�.�.�)rc��tddi�}|ji�\}|jtj|ji��j
d�y)Nr r)rr
rrrr#)rr#�errors   r�test_one_errorzTestBestMatch.test_one_errorsS��#�_�a�$8�9�	��&�&�r�*�������!�!�)�"7�"7��";�<�F�F��	
rc��ti�}|jtj|j	i���y)N)rrQrrr
)rr#s  r�test_no_errorszTestBestMatch.test_no_errors
s0��#�B�'�	����*�/�/�	�0E�0E�b�0I�J�KrN)�__name__�
__module__�__qualname__rr%r+r1r5r8r;r=r?rBrDrMrOrRrUrW�rrrrsS��	�
:�:�8�.2� 1�8�.2� 1�9�&8�86�66�6*�

�Lrrc�$�eZdZd�Zd�Zd�Zd�Zy)�TestByRelevancec�"�tjddg��}tjdddg��}t||gtj��}|j	||�t||gtj��}|j	||�y)N�Oh no!�baz��path�Oh yes!rr��key)r�ValidationError�max�	relevance�assertIs)r�shallow�deep�matchs    r�#test_short_paths_are_better_matchesz3TestByRelevance.test_short_paths_are_better_matchesst���,�,�X�U�G�D���)�)�)�5�%�.�I���W�d�O��)=�)=�>���
�
�e�W�%��T�7�O��)=�)=�>���
�
�e�W�%rc���tjdg��}tjddg��}t||gtj��}|j	|D�cgc]}t|j���c}dggg�t||gtj��}|j	|D�cgc]}t|j���c}dggg�ycc}wcc}w)Nr_rarcrrd)rrf�sortedrhrr	rb)rrjrkrrTs     r�*test_global_errors_are_even_better_matchesz:TestByRelevance.test_global_errors_are_even_better_matchess����,�,�X�B�?���)�)�)�5�'�B����$��Z�-A�-A�B�����+1�2�%�T�%�*�*�
�2��W�b�M�	
�
��w��Z�-A�-A�B�����+1�2�%�T�%�*�*�
�2��W�b�M�	
��
3��
3s�C�/Cc��tjdgd��}tjdgd��}tjd��}t||g|��}|j	||�t||g|��}|j	||�y)Nr_�a�rbr#rc�b)�weakrd�rrf�by_relevancergri)rru�normalrrls     r�%test_weak_keywords_are_lower_priorityz5TestByRelevance.test_weak_keywords_are_lower_priority)sv���)�)�(��s�K���+�+�I�B�#�N���,�,�#�6�
��T�6�N�
�3���
�
�e�V�$��V�T�N�
�3���
�
�e�V�$rc�J�tjdgd��}tjdgd��}tjdgd��}tjdd��}t|||g|�	�}|j	||�t|||g|�	�}|j	||�y)
Nr_rrrsrcrtzOh fine!�c)ru�strongrdrv)rrurxr|rrls      r�(test_strong_keywords_are_higher_priorityz8TestByRelevance.test_strong_keywords_are_higher_priority5s����)�)�(��s�K���+�+�I�B�#�N���+�+�J�R�3�O���,�,�#�c�B�
��T�6�6�*�
�;���
�
�e�V�$��V�V�T�*�
�;���
�
�e�V�$rN)rXrYrZrmrpryr}r[rrr]r]s��&�
� 
%�%rr]c�H�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�
TestErrorTreec���td�D�cgc]}tjd|����}}tj|�}|j	|j
d�ycc}w)N��	Something�r#)�rangerrf�	ErrorTreer�total_errors)r�ir�trees    r�/test_it_knows_how_many_total_errors_it_containsz=TestErrorTree.test_it_knows_how_many_total_errors_it_containsDs_���1�X�
��
�&�&�{�a�@�
��
��#�#�F�+������*�*�A�.��
s�A c��tjddg��g}tj|�}|jd|�y)N�	a messagerra)rrfr��assertIn�rrr�s   r�1test_it_contains_an_item_if_the_item_had_an_errorz?TestErrorTree.test_it_contains_an_item_if_the_item_had_an_errorMs7���,�,�[��w�G�H���#�#�F�+���
�
�e�T�"rc��tjddg��g}tj|�}|jd|�y)Nr�rrar)rrfr��assertNotInr�s   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_errorRs9���,�,�[��w�G�H���#�#�F�+�������%rc��tjdd��}tj|g�}|j|jd|i�y)Nr�rr��rrfr�rr�rrTr�s   r�/test_keywords_that_failed_appear_in_errors_dictz=TestErrorTree.test_keywords_that_failed_appear_in_errors_dictWs>���*�*�;�%�H���#�#�U�G�,��������u�e�n�5rc���tjddg��tjdddg��g}tj|�}|jd|d�|j	d|d�y)Nz
a bar messagerraza bar -> 0 messager�)rrfr�r�r�r�s   r�1test_it_creates_a_child_tree_for_each_nested_pathz?TestErrorTree.test_it_creates_a_child_tree_for_each_nested_path\sh���&�&��e�W�E��&�&�';�5�!�*�M�
���#�#�F�+���
�
�a��e��%�����D��K�(rc���tjddddg��tjddddg��}}tj||g�}|j|ddj||d��y)	N�1rrr)r#rb�2�quux)rr�r��r�e1�e2r�s    r�+test_children_have_their_errors_dicts_builtz9TestErrorTree.test_children_have_their_errors_dicts_builtesn���&�&�s�e�5�!�*�M��&�&�s�f�E�1�:�N�
���#�#�R��H�-������e��Q��.�.��B�0G�Hrc��tjddddgd��tjddd	d
gd��}}tj||g�y)Nr�rr�bar2�i1�r#rbrr�r��foobarr�i2)rrfr�)rr�r�s   r�"test_multiple_errors_with_instancez0TestErrorTree.test_multiple_errors_with_instancems[���&�&����V�_��	
�

�&�&�� ���]��	
�

��	���b�"�X�&rc��tjddg��}tj|g�}|jt�5|dddd�y#1swYyxYw)N�123r)r#rr)rrfr��assertRaises�
IndexErrorr�s   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|sR���*�*�5�E�B�O���#�#�U�G�,��
�
�
�z�
*�	���G�	�	�	�s�A�Ac��tjddidg��}tj|g�}|j|dtj�y)z�
        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#rrbN)rrfr��assertIsInstancer�s   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���*�*��5�2�U�G�
���#�#�U�G�,�����d�5�k�:�+?�+?�@rc���tjddddgd��tjddd	d
gd��}}tj||g�}|jt	|�d�y)
Nr�rrr�r�r�r�r�r�rr�z<ErrorTree (2 total errors)>)rrfr�r�reprr�s    r�	test_reprzTestErrorTree.test_repr�sr���&�&����V�_��	
�

�&�&�� ���]��	
�

���#�#�R��H�-������d��%C�DrN)
rXrYrZr�r�r�r�r�r�r�r�r�r�r[rrrrCs7��/�#�
&�
6�
)�I�
'��
A�Errc�H�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�TestErrorInitReprStrc�r�tddddddi��}|j|�tjdi|��S)N�hellorr'�)�messager#r0rrr[)�dict�updaterrf)r�kwargs�defaultss   r�
make_errorzTestErrorInitReprStr.make_error�sB�����$���H�%�
��	������)�)�5�H�5�5rc��tj|�jd�}|jdi|��}t	|�jd�\}}}|j
||j�|j
||�y)N�
r[)�textwrap�dedent�rstripr��str�	partitionrr�)r�expectedr�rT�message_line�_�rests       r�assertShowsz TestErrorInitReprStr.assertShows�sm���?�?�8�,�3�3�D�9������)�&�)�� #�E�
� 4� 4�T� :���a������u�}�}�5�����x�(rc�n�|j�}|jt|j�d�y)Nr�)r��
assertGreater�len�args)rrTs  r�!test_it_calls_super_and_sets_argsz6TestErrorInitReprStr.test_it_calls_super_and_sets_args�s&�����!�����3�u�z�z�?�A�.rc�b�|jttjd���d�y)NzHello!�r�z<ValidationError: 'Hello!'>)rr�rrf�rs rr�zTestErrorInitReprStr.test_repr�s&�������+�+�H�=�>�)�	
rc��tjd�}|jt|�d�dddddid�}|D]@}t	|�}||=tjdi|��}|jt|�d��By)Nr�rr'r�)r#r0rrr�)rrfrr�r�)rrTr��attr�ks     r�test_unset_errorz%TestErrorInitReprStr.test_unset_error�s����*�*�9�5������U��Y�/� �'���x�(�	
���	4�D��V��A��$���.�.�>�A�>�E����S��Z��3�		4rc�,�|jdgg��y)Nz�
            Failed validating 'type' in schema:
                {'type': 'string'}

            On instance:
                5
            �rb�schema_path�r�r�s r�test_empty_pathsz%TestErrorInitReprStr.test_empty_paths�s"�����
���	�
	
rc�0�|jddgdg��y)Nz�
            Failed validating 'type' in schema:
                {'type': 'string'}

            On instance[0]:
                5
            r�itemsr�r�r�s r�test_one_item_pathsz(TestErrorInitReprStr.test_one_item_paths�s&�����
��� �	�	�
	
rc�4�|jdddggd���y)Nz�
            Failed validating 'type' in schema['items'][0]:
                {'type': 'string'}

            On instance[0]['a']:
                5
            rrr)r�rr�r�r�r�s r�test_multiple_item_pathsz-TestErrorInitReprStr.test_multiple_item_paths�s&�����
��S��'�	�
	
rc��|jdttd��tt	td�td���d��y)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#)r�r	r�r��zipr�s r�test_uses_pprintz%TestErrorInitReprStr.test_uses_pprint�sC�����1
�d�%��)�_���E�"�I�u�R�y�1�2�!�k	�6	
rc���G�fd�dt�}|�}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�"��eZdZ�fd�Z�fd�Zy)�dTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBroc�(���jd�y�NzDon't!��fail��this�otherrs  �r�__eq__zkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__eq__7�����	�	�(�#rc�(���jd�yr�r�r�s  �r�__ne__zkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__ne__:r�rN)rXrYrZr�r�r�s�r�DontEQMeBror�6s
���
$�
$rr�r�r�somer)r#rr0rN)rrrfr�r�r�)rr�rrTs`   r�:test_str_works_with_instances_having_overriden_eq_operatorzOTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator/sO���	$�&�	$��=���*�*����"��
��	
�
�
�d�8�n�c�%�j�1rN)
rXrYrZr�r�r�r�r�r�r�r�r�r�r[rrr�r��s5��	6�)�/�
�4�"
�
�
�7
�r2rr�c��eZdZd�Zy)�TestHashablec��ttjd�g�ttjd�g�y)N�)�setrrf�SchemaErrorr�s r�
test_hashablezTestHashable.test_hashableIs.���Z�
'�
'��
+�,�-��Z�
#�
#�B�
'�(�)rN)rXrYrZr�r[rrr�r�Hs��*rr�)�unittestrr��
jsonschemar�jsonschema.validatorsrrr]rr�r�r[rr�<module>rs[����!�1�DL�H�DL�N1%�h�1%�hZE�H�ZE�ze2�8�e2�P*�8�*r

Zerion Mini Shell 1.0