HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/jsonschema/tests/__pycache__/test_exceptions.cpython-39.pyc
a

�,�h�^�@s�ddlmZddlZddlZddlmZddlmZGdd�de�ZGdd�de�Z	Gd	d
�d
e�Z
Gdd�de�ZGd
d�de�ZGdd�de�Z
dS)�)�TestCaseN)�
exceptions)�_LATEST_VERSIONc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�
TestBestMatchcCsttt|��|��}d|�d|�d�}|j||d�t�t|��}t�t|��}|�|�	�|�	�d|�d|���|S)NzNo errors found for z under �!)�msgzNo consistent best match!
Got: z

Then: )
�listr�iter_errors�
assertTruer�
best_match�iter�reversed�assertEqualZ	_contents)�self�instance�schema�errorsr�bestZ
reversed_best�r�Q/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/jsonschema/tests/test_exceptions.py�
best_match_ofs�zTestBestMatch.best_match_ofcCsBddddddiid�ii}|jddgii|d�}|�|jd	�dS)
N�
properties�foo��bar�type�object)�
minPropertiesr�rrr�rr�	validator�rrrrrr�(test_shallower_errors_are_better_matchess
���z6TestBestMatch.test_shallower_errors_are_better_matchescCsDdddiddigddiddigd�}|ji|d�}|�|jd�dS)	zn
        A property you *must* match is probably better than one you have to
        match a part of.
        rr�string�number)r�anyOf�oneOfrrNrr!rrr�%test_oneOf_and_anyOf_are_weak_matches&s�z3TestBestMatch.test_oneOf_and_anyOf_are_weak_matchescCsLdddddiddddiiigiii}|jdddii|d	�}|�|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.
        rrr%rr#r�array�rN�rr�validator_valuer!rrr�8test_if_the_most_relevant_error_is_anyOf_it_is_traversed4s����
zFTestBestMatch.test_if_the_most_relevant_error_is_anyOf_it_is_traversedcCs:dddiddiddigi}|jg|d�}|�|jd�dS)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#�integerrrNrr!rrr�3test_no_anyOf_traversal_for_equally_relevant_errorsKs��zATestBestMatch.test_no_anyOf_traversal_for_equally_relevant_errorscCs.dddigi}|jg|d�}|�|jd�dS)z�
        We *do* traverse anyOf with a single nested error, even though it is
        vacuously equally relevant to itself.
        r%rr#rNrr!rrr�6test_anyOf_traversal_for_single_equally_relevant_error[s��zDTestBestMatch.test_anyOf_traversal_for_single_equally_relevant_errorcCs6ddddiigi}|jddg|d�}|�|jd�dS)z|
        We *do* traverse anyOf with a single subschema that fails multiple
        times (e.g. on multiple items).
        r%�items�const�%r)rNrr!rrr�.test_anyOf_traversal_for_single_sibling_errorsis
��z<TestBestMatch.test_anyOf_traversal_for_single_sibling_errorscCs<dddidddiigi}|jddg|d�}|�|jd�d	S)
zg
        We *do* traverse anyOf with multiple subschemas when one does not type
        match.
        r%rrr0r1r2r)rNrr!rrr�9test_anyOf_traversal_for_non_type_matching_sibling_errorsws
��zGTestBestMatch.test_anyOf_traversal_for_non_type_matching_sibling_errorscCsLdddddiddddiiigiii}|jdddii|d	�}|�|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.
        rrr&rr#rr(r)rNr*r!rrr�8test_if_the_most_relevant_error_is_oneOf_it_is_traversed�s����
zFTestBestMatch.test_if_the_most_relevant_error_is_oneOf_it_is_traversedcCs:dddiddiddigi}|jg|d�}|�|jd�dS)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#r-rrNrr!rrr�3test_no_oneOf_traversal_for_equally_relevant_errors�s��zATestBestMatch.test_no_oneOf_traversal_for_equally_relevant_errorscCs.dddigi}|jg|d�}|�|jd�dS)z�
        We *do* traverse oneOf with a single nested error, even though it is
        vacuously equally relevant to itself.
        r&rr#rNrr!rrr�6test_oneOf_traversal_for_single_equally_relevant_error�s��zDTestBestMatch.test_oneOf_traversal_for_single_equally_relevant_errorcCs6ddddiigi}|jddg|d�}|�|jd�dS)z|
        We *do* traverse oneOf with a single subschema that fails multiple
        times (e.g. on multiple items).
        r&r0r1r2r)rNrr!rrr�.test_oneOf_traversal_for_single_sibling_errors�s
��z<TestBestMatch.test_oneOf_traversal_for_single_sibling_errorscCs<dddidddiigi}|jddg|d�}|�|jd�d	S)
zg
        We *do* traverse oneOf with multiple subschemas when one does not type
        match.
        r&rrr0r1r2r)rNrr!rrr�9test_oneOf_traversal_for_non_type_matching_sibling_errors�s
��zGTestBestMatch.test_oneOf_traversal_for_non_type_matching_sibling_errorscCsLdddddiddddiiigiii}|jdddii|d	�}|�|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.
        rrZallOfrr#rr(r)rNr*r!rrr�8test_if_the_most_relevant_error_is_allOf_it_is_traversed�s����
zFTestBestMatch.test_if_the_most_relevant_error_is_allOf_it_is_traversedc
CsXdddddidddiddddiiigigiii}|jdddii|d	�}|�|jd�d
S)zp
        We traverse into nested contexts (a oneOf containing an error in a
        nested oneOf here).
        rrr&rr#rr(r)rNr*r!rrr�test_nested_context_for_oneOf�s$��������z+TestBestMatch.test_nested_context_for_oneOfcCs�dddddd�ddd	�giii}|jdd
i|d�}|�|jd�dddddd	�ddd�giii}|jdd
i|d�}|�|jd�dS)
Nrrr%r(r�rZminItemsr#�
�r�	minLengthrrr?r�rrr�	reorderedrrr�"test_it_prioritizes_matching_typess,����
����
z0TestBestMatch.test_it_prioritizes_matching_typescCs�dddddgdd�dd	gd
d�giii}|jddi|d
�}|�|jd�dddd	d
d�ddd�giii}|jddi|d
�}|�|jd�dS)Nrrr%r(rrr<r-r#r=r>rrr?rr@rrr�(test_it_prioritizes_matching_union_types"s,����
����
z6TestBestMatch.test_it_prioritizes_matching_union_typescCs.dddii}|jddi|d�}|�|j�dS)NrrFrr)r�assertIsNoner r!rrr�test_boolean_schemas=sz"TestBestMatch.test_boolean_schemascCs6tddi�}|�i�\}|�t�|�i��jd�dS)Nrr)rr	rrrr )rr �errorrrr�test_one_errorBs�zTestBestMatch.test_one_errorcCs"ti�}|�t�|�i���dS)N)rrDrrr	)rr rrr�test_no_errorsJszTestBestMatch.test_no_errorsN)�__name__�
__module__�__qualname__rr"r'r,r.r/r3r4r5r6r7r8r9r:r;rBrCrErGrHrrrrr
s(rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestByRelevancecCsbtjddgd�}tjdddgd�}t||gtjd�}|�||�t||gtjd�}|�||�dS)N�Oh no!Zbaz��path�Oh yes!rr��key)r�ValidationError�max�	relevance�assertIs)r�shallow�deep�matchrrr�#test_short_paths_are_better_matchesPsz3TestByRelevance.test_short_paths_are_better_matchescCs~tjdgd�}tjddgd�}t||gtjd�}|�dd�|D�dggg�t||gtjd�}|�dd�|D�dggg�dS)	NrMrNrPrrQcSsg|]}t|j��qSr�rrO��.0rFrrr�
<listcomp>_�zNTestByRelevance.test_global_errors_are_even_better_matches.<locals>.<listcomp>cSsg|]}t|j��qSrr[r\rrrr^er_)rrS�sortedrUr)rrWrXrrrr�*test_global_errors_are_even_better_matchesYs��z:TestByRelevance.test_global_errors_are_even_better_matchescCshtjdgdd�}tjdgdd�}tjdd�}t||g|d�}|�||�t||g|d�}|�||�dS)NrM�a�rOr rP�b)�weakrQ�rrSZby_relevancerTrV)rre�normalrrYrrr�%test_weak_keywords_are_lower_priorityisz5TestByRelevance.test_weak_keywords_are_lower_prioritycCs~tjdgdd�}tjdgdd�}tjdgdd�}tjddd�}t|||g|d	�}|�||�t|||g|d	�}|�||�dS)
NrMrbrcrPrdzOh fine!�c)re�strongrQrf)rrergrjrrYrrr�(test_strong_keywords_are_higher_priorityusz8TestByRelevance.test_strong_keywords_are_higher_priorityN)rIrJrKrZrarhrkrrrrrLOs	rLc@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�
TestErrorTreecCs.dd�td�D�}t�|�}|�|jd�dS)NcSsg|]}tjd|d��qS)Z	Something�r )rrS)r]�irrrr^�s�zQTestErrorTree.test_it_knows_how_many_total_errors_it_contains.<locals>.<listcomp>�)�ranger�	ErrorTreerZtotal_errors�rr�treerrr�/test_it_knows_how_many_total_errors_it_contains�s
�
z=TestErrorTree.test_it_knows_how_many_total_errors_it_containscCs,tjddgd�g}t�|�}|�d|�dS)N�	a messagerrN)rrSrq�assertInrrrrr�1test_it_contains_an_item_if_the_item_had_an_error�s
z?TestErrorTree.test_it_contains_an_item_if_the_item_had_an_errorcCs,tjddgd�g}t�|�}|�d|�dS)NrurrNr)rrSrq�assertNotInrrrrr�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_errorcCs0tjddd�}t�|g�}|�|jd|i�dS)Nrurrm�rrSrqrr�rrFrsrrr�/test_keywords_that_failed_appear_in_errors_dict�sz=TestErrorTree.test_keywords_that_failed_appear_in_errors_dictcCsPtjddgd�tjdddgd�g}t�|�}|�d|d�|�d|d�dS)Nz
a bar messagerrNza bar -> 0 messager�)rrSrqrvrxrrrrr�1test_it_creates_a_child_tree_for_each_nested_path�s�
z?TestErrorTree.test_it_creates_a_child_tree_for_each_nested_pathcCsXtjddddgd�tjddddgd�}}t�||g�}|�|ddj||d��dS)	N�1rrr)r rO�2�quux)rr�rz�r�e1�e2rsrrr�+test_children_have_their_errors_dicts_built�s
�z9TestErrorTree.test_children_have_their_errors_dicts_builtcCs@tjddddgdd�tjddd	d
gdd�}}t�||g�dS�Nrrr�bar2�i1�r rOrr�r��foobarr�i2)rrSrq)rr�r�rrr�"test_multiple_errors_with_instance�s���z0TestErrorTree.test_multiple_errors_with_instancecCsRtjddgd�}t�|g�}|�t��|dWd�n1sD0YdS)NZ123r)r rr)rrSrq�assertRaises�
IndexErrorr{rrr�>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_instancecCs6tjddidgd�}t�|g�}|�|dtj�dS)z�
        If a keyword refers to a path that isn't in the instance, the
        tree still properly returns a subtree for that path.
        rur)r rrON)rrSrqZassertIsInstancer{rrr�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_errorcCsTtjddddgdd�tjddd	d
gdd�}}t�||g�}|�t|�dd	h�dSr�)rrSrqr�setr�rrr�	test_iter�s���zTestErrorTree.test_itercCs6tjddddgdd�}t�|g�}|�t|�d�dS)Nrrrr�r�r�z<ErrorTree (1 total error)>�rrSrqr�reprr{rrr�test_repr_single�s�zTestErrorTree.test_repr_singlecCsPtjddddgdd�tjddd	d
gdd�}}t�||g�}|�t|�d�dS)
Nrrrr�r�r�r�r�r�rr�z<ErrorTree (2 total errors)>r�r�rrr�test_repr_multiple�s���z TestErrorTree.test_repr_multiplecCst�g�}|�t|�d�dS)Nz<ErrorTree (0 total errors)>)rrqrr�)rrsrrr�test_repr_empty�s
zTestErrorTree.test_repr_emptyN)rIrJrKrtrwryr|r~r�r�r�r�r�r�r�r�rrrrrl�s		
rlc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�TestErrorInitReprStrcKs0tddddddid�}|�|�tjfi|��S)NZhellorr#�)�messager r+rr)�dict�updaterrS)r�kwargs�defaultsrrr�
make_error�s�
zTestErrorInitReprStr.make_errorcKsRt�|��d�}|jfi|��}t|��d�\}}}|�||j�|�||�dS)N�
)�textwrap�dedent�rstripr��str�	partitionrr�)r�expectedr�rFZmessage_line�_�restrrr�assertShows
s
z TestErrorInitReprStr.assertShowscCs|��}|�t|j�d�dS)Nr})r�Z
assertGreater�len�args)rrFrrr�!test_it_calls_super_and_sets_argssz6TestErrorInitReprStr.test_it_calls_super_and_sets_argscCs|�ttjdd��d�dS)NzHello!)r�z<ValidationError: 'Hello!'>)rr�rrS�rrrr�	test_reprs�zTestErrorInitReprStr.test_reprcCsht�d�}|�t|�d�dddddid�}|D]2}t|�}||=tjdi|��}|�t|�d�q0dS)Nr�rr#r�)r r+rr)r�)rrSrr�r�)rrFr��attr�krrr�test_unset_errors
�z%TestErrorInitReprStr.test_unset_errorcCs|jdggd�dS)Nz�
            Failed validating 'type' in schema:
                {'type': 'string'}

            On instance:
                5
            �rOZschema_path�r�r�rrr�test_empty_paths-s
�z%TestErrorInitReprStr.test_empty_pathscCs|jddgdgd�dS)Nz�
            Failed validating 'type' in schema:
                {'type': 'string'}

            On instance[0]:
                5
            rr0r�r�r�rrr�test_one_item_paths:s
�z(TestErrorInitReprStr.test_one_item_pathscCs|jdddggd�d�dS)Nz�
            Failed validating 'type' in schema['items'][0]:
                {'type': 'string'}

            On instance[0]['a']:
                5
            rrb)r0rr}r�r�r�rrr�test_multiple_item_pathsGs
�z-TestErrorInitReprStr.test_multiple_item_pathscCs0|jdttd��tttd�td���dd�dS)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]
            ��Z	maxLength)rrr )r�rrpr��zipr�rrr�test_uses_pprintTs2
�z%TestErrorInitReprStr.test_uses_pprintcCs(|jdddddd�ddddd�d�dS)	Nz�
            Failed validating 'type' in schema:
                {'do': 3, 'not': 7, 'sort': 37, 'me': 73}

            On instance:
                {'here': 73, 'too': 37, 'no': 7, 'sorting': 3}
            ��r2�I)�do�not�sort�me)�hereZtoo�noZsorting)rrr�r�rrr�test_does_not_reorder_dicts�s���z0TestErrorInitReprStr.test_does_not_reorder_dictscsDG�fdd�d�}|�}tjdd|ddd�}��t|�t|��dS)	z�
        Check for #164 which rendered exceptions unusable when a
        `ValidationError` involved instances with an `__eq__` method
        that returned truthy values.
        cs$eZdZ�fdd�Z�fdd�ZdS)zdTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBrocs��d�dS�NzDon't!�Zfail��this�otherr�rr�__eq__�szkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__eq__cs��d�dSr�r�r�r�rr�__ne__�szkTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operator.<locals>.DontEQMeBro.__ne__N)rIrJrKr�r�rr�rr�DontEQMeBro�sr�rurZsomer)r rr+rN)rrSrvr�r�)rr�rrFrr�r�:test_str_works_with_instances_having_overriden_eq_operator�s�zOTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operatorN)rIrJrKr�r�r�r�r�r�r�r�r�r�r�rrrrr��s


9r�c@seZdZdd�ZdS)�TestHashablecCst�d�ht�d�hdS)N�)rrSZSchemaErrorr�rrr�
test_hashable�szTestHashable.test_hashableN)rIrJrKr�rrrrr��sr�c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�TestJsonPathRenderingcCsHtj|gdddd�}|j}|�||�t�|�jjd}|�||�dS)Nrrr�)rOr�r rr)rrSZ	json_pathr�jsonpath_ng�parse�right�fields)rZ
property_nameZ
expected_pathrFZrendered_json_pathZre_parsed_namerrr�validate_json_path_rendering�s�z2TestJsonPathRendering.validate_json_path_renderingcCs|�dd�dS)N�xz$.x�r�r�rrr�
test_basic�sz TestJsonPathRendering.test_basiccCs|�dd�dS)Nr�z$['']r�r�rrr�
test_empty�sz TestJsonPathRendering.test_emptycCs|�dd�dS)Nrz$['1']r�r�rrr�test_number�sz!TestJsonPathRendering.test_numbercCs|�dd�dS)N�.z$['.']r�r�rrr�test_period�sz!TestJsonPathRendering.test_periodcCs|�dd�dS)N�'z$['\'']r�r�rrr�test_single_quote�sz'TestJsonPathRendering.test_single_quotecCs|�dd�dS)N� z$[' ']r�r�rrr�
test_space�sz TestJsonPathRendering.test_spacecCs|�dd�dS)N�\z$['\\']r�r�rrr�test_backslash�sz$TestJsonPathRendering.test_backslashcCs|�dd�dS)Nz\'z	$['\\\'']r�r�rrr�test_backslash_single_quote�sz1TestJsonPathRendering.test_backslash_single_quotecCs|�dd�dS)Nr�z$['_']r�r�rrr�test_underscore�sz%TestJsonPathRendering.test_underscorecCs|�dd�dS)N�"z$['"']r�r�rrr�test_double_quote�sz'TestJsonPathRendering.test_double_quotecCs|�dd�dS)N�-z$['-']r�r�rrr�test_hyphen�sz!TestJsonPathRendering.test_hyphencCs|�dd�dS)Nza[0]z	$['a[0]']r�r�rrr�test_json_path_injection�sz.TestJsonPathRendering.test_json_path_injectioncCs|�dd�dS)N�[z$['[']r�r�rrr�test_open_bracket�sz'TestJsonPathRendering.test_open_bracketN)rIrJrKr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��sr�)�unittestrr�r�Z
jsonschemarZjsonschema.validatorsrrrLrlr�r�r�rrrr�<module>sG4{@