name : test_exceptions.cpython-39.pyc
a

 5q]�;�@s�ddlmZddlZddlmZmZddlmZGdd�de�ZGdd�de�Z	Gd	d
�d
e�Z
Gdd�de�ZGd
d�de�ZdS)�)�TestCaseN)�Draft4Validator�
exceptions)�PY3c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�
TestBestMatchcCsHt|�}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_matchcCsHtddddddiid�ii�}|�|�ddgii��}|�|jd�dS)	N�
properties�foo��bar�type�object)�
minPropertiesrr�rr	�iter_errorsr�	validator�r
rrrrr�(test_shallower_errors_are_better_matchess
����
z6TestBestMatch.test_shallower_errors_are_better_matchescCsJtdddiddigddiddigd��}|�|�i��}|�|jd�dS)zn
        A property you *must* match is probably better than one you have to
        match a part of.
        rr�stringZnumber)r�anyOf�oneOfrNrrrrr�%test_oneOf_and_anyOf_are_weak_matches"s��z3TestBestMatch.test_oneOf_and_anyOf_are_weak_matchesc	CsRtdddddiddddiiigiii�}|�|�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.
        rrrrrr�array�N�rr	rr�validator_valuerrrr�8test_if_the_most_relevant_error_is_anyOf_it_is_traversed2s
�����zFTestBestMatch.test_if_the_most_relevant_error_is_anyOf_it_is_traversedc	CsRtdddddiddddiiigiii�}|�|�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.
        rrr rrrr"r#Nr$rrrr�8test_if_the_most_relevant_error_is_oneOf_it_is_traversedKs
�����zFTestBestMatch.test_if_the_most_relevant_error_is_oneOf_it_is_traversedc	CsRtdddddiddddiiigiii�}|�|�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.
        rrZallOfrrrr"r#Nr$rrrr�8test_if_the_most_relevant_error_is_allOf_it_is_traversedds�����zFTestBestMatch.test_if_the_most_relevant_error_is_allOf_it_is_traversedcCs^tdddddidddiddddiiigigiii�}|�|�dddii��}|�|jd�dS)	Nrrr rrrr"r#r$rrrr�test_nested_context_for_oneOfys(���������z+TestBestMatch.test_nested_context_for_oneOfcCs6tddi�}|�i�\}|�t�|�i��jd�dS)Nrr)rrrrr	r)r
r�errorrrr�test_one_error�s�zTestBestMatch.test_one_errorcCs"ti�}|�t�|�i���dS)N)rZassertIsNonerr	r)r
rrrr�test_no_errors�szTestBestMatch.test_no_errorsN)�__name__�
__module__�__qualname__r	rr!r&r'r(r)r+r,rrrrrsrc@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_matches�sz3TestByRelevance.test_short_paths_are_better_matchescCs~tjdgd�}tjddgd�}t||gtjd�}|�dd�|D�dggg�t||gtjd�}|�dd�|D�dggg�dS)	Nr1r2r4rr5cSsg|]}t|j��qSr�rr3��.0r*rrr�
<listcomp>��zNTestByRelevance.test_global_errors_are_even_better_matches.<locals>.<listcomp>cSsg|]}t|j��qSrr?r@rrrrB�rC)rr7�sortedr9r)r
r;r<rrrr�*test_global_errors_are_even_better_matches�s��z:TestByRelevance.test_global_errors_are_even_better_matchescCshtjdgdd�}tjdgdd�}tjdd�}t||g|d�}|�||�t||g|d�}|�||�dS)Nr1�a�r3rr4�b)�weakr5�rr7Zby_relevancer8r:)r
rI�normalr	r=rrr�'test_weak_validators_are_lower_priority�sz7TestByRelevance.test_weak_validators_are_lower_prioritycCs~tjdgdd�}tjdgdd�}tjdgdd�}tjddd�}t|||g|d	�}|�||�t|||g|d	�}|�||�dS)
Nr1rFrGr4rHzOh fine!�c)rI�strongr5rJ)r
rIrKrNr	r=rrr�*test_strong_validators_are_higher_priority�sz:TestByRelevance.test_strong_validators_are_higher_priorityN)r-r.r/r>rErLrOrrrrr0�s	r0c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�
TestErrorTreecCs.dd�td�D�}t�|�}|�|jd�dS)NcSsg|]}tjd|d��qS)Z	Something�r)rr7)rA�irrrrB�s�zQTestErrorTree.test_it_knows_how_many_total_errors_it_contains.<locals>.<listcomp>�)�ranger�	ErrorTreerZtotal_errors�r
r�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 messagerr2)rr7rU�assertInrVrrr�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)NrYrr2r)rr7rU�assertNotInrVrrr�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)NrYrrQ�rr7rUrr�r
r*rWrrr�1test_validators_that_failed_appear_in_errors_dict�sz?TestErrorTree.test_validators_that_failed_appear_in_errors_dictcCsPtjddgd�tjdddgd�g}t�|�}|�d|d�|�d|d�dS)Nz
a bar messagerr2za bar -> 0 messager�)rr7rUrZr\rVrrr�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)rr3�2�quux)rrer^)r
�e1�e2rWrrr�+test_children_have_their_errors_dicts_built�s
�z9TestErrorTree.test_children_have_their_errors_dicts_builtcCs@tjddddgdd�tjddd	d
gdd�}}t�||g�dS)NrcrrZbar2Zi1)rr3�instancerdreZfoobarrZi2)rr7rU)r
rfrgrrr�"test_multiple_errors_with_instance�s���z0TestErrorTree.test_multiple_errors_with_instancecCsRtjddgd�}t�|g�}|�t��|dWd�n1sD0YdS)NZ123r)rrir)rr7rUZ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 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.
        rYr)rrir3N)rr7rUZassertIsInstancer_rrr�9test_if_its_in_the_tree_anyhow_it_does_not_raise_an_errors

�zGTestErrorTree.test_if_its_in_the_tree_anyhow_it_does_not_raise_an_errorN)r-r.r/rXr[r]r`rbrhrjrlrmrrrrrP�s		rPc@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestErrorInitReprStrcKs0tddddddid�}|�|�tjfi|��S)NZhellorr�)�messagerr%ri�schema)�dict�updaterr7)r
�kwargs�defaultsrrr�
make_error"s�
zTestErrorInitReprStr.make_errorcKsbtr|�dd�}t�|��d�}|jfi|��}t|��d�\}}}|�||j	�|�||�dS)Nzu'�'�
)
r�replace�textwrap�dedent�rstriprv�str�	partitionrrp)r
Zexpectedrtr*Zmessage_line�_�restrrr�assertShows-sz TestErrorInitReprStr.assertShowscCs|��}|�t|j�d�dS)Nra)rvZ
assertGreater�len�args)r
r*rrr�!test_it_calls_super_and_sets_args7sz6TestErrorInitReprStr.test_it_calls_super_and_sets_argscCs |�ttjdd��dd�dS)NzHello!)rpz<ValidationError: %r>)r�reprrr7�r
rrr�	test_repr;s�zTestErrorInitReprStr.test_reprcCsht�d�}|�t|�d�dddddid�}|D]2}t|�}||=tjdi|��}|�t|�d�q0dS)Nrprrro)rr%rirq)rp)rr7rr}rr)r
r*rt�attr�krrr�test_unset_errorAs
�z%TestErrorInitReprStr.test_unset_errorcCs|jdggd�dS)Nz�
            Failed validating u'type' in schema:
                {u'type': u'string'}

            On instance:
                5
            �r3Zschema_path�r�r�rrr�test_empty_pathsRs
�z%TestErrorInitReprStr.test_empty_pathscCs|jddgdgd�dS)Nz�
            Failed validating u'type' in schema:
                {u'type': u'string'}

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

            On instance[0][u'a']:
                5
            rrF)r�rrar�r�r�rrr�test_multiple_item_pathsls
�z-TestErrorInitReprStr.test_multiple_item_pathscCs0|jdttd��tttd�td���dd�dS)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)rirqr)r�rrTrr�zipr�rrr�test_uses_pprintys2
�z%TestErrorInitReprStr.test_uses_pprintcsFG�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.
        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)r-r.r/r�r�rr�rr�DontEQMeBro�sr�rYrZsomerq)rrir%rqN)rrr7rZr�r})r
r�rir*rr�r�:test_str_works_with_instances_having_overriden_eq_operator�s�zOTestErrorInitReprStr.test_str_works_with_instances_having_overriden_eq_operatorN)
r-r.r/rvr�r�r�r�r�r�r�r�r�rrrrrn!s



9rnc@seZdZdd�ZdS)�TestHashablecCs$tt�d�g�tt�d�g�dS)N�)�setrr7ZSchemaErrorr�rrr�
test_hashable�szTestHashable.test_hashableN)r-r.r/r�rrrrr��sr�)
ZunittestrrzZ
jsonschemarrZjsonschema.compatrrr0rPrnr�rrrr�<module>s4N+

© 2025 Cubjrnet7