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_validators.cpython-39.pyc
a

�,�h�W�@s4ddlmZddlmZmZddlmZddlmZddl	m
Z
ddlmZddl
mZmZddlmZdd	lZdd	lZdd	lZdd	lZdd	lZdd
lmZmZddlmZdd	lZddlmZm Z m!Z!m"Z"m#Z#d
d�Z$Gdd�de�Z%Gdd�de�Z&Gdd�de�Z'Gdd�d�Z(Gdd�de(�Z)Gdd�d�Z*Gdd�de*e)e�Z+Gdd�de*e)e�Z,Gdd �d e)e�Z-Gd!d"�d"e)e�Z.Gd#d$�d$e)e�Z/Gd%d&�d&e)e�Z0Gd'd(�d(e�Z1Gd)d*�d*e�Z2Gd+d,�d,e�Z3Gd-d.�d.e�Z4Gd/d0�d0e�Z5Gd1d2�d2e�Z6d3d4�Z7eGd5d6�d6��Z8eGd7d8�d8��Z9d	S)9�)�annotations)�deque�
namedtuple)�contextmanager)�Decimal)�BytesIO)�Any)�TestCase�mock)�pathname2urlN)�define�field)�DRAFT202012)�
FormatChecker�TypeChecker�
exceptions�	protocols�
validatorsccs,|D]"}|�dd�tjfi|��VqdS)N�messagezYou told me to fail!)�
setdefaultr�ValidationError)�	validator�errors�instance�schemaZeach�r�Q/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/jsonschema/tests/test_validators.py�failsrc@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)*�TestCreateAndExtendcCsh|�|jtjttj��|�|jtjttj��ddi|_dti|_t�|_	tj
|j|j|j	d�|_dS)N�$idzsome://meta/schemar)�meta_schemar�type_checker)�
addCleanup�assertEqualr�
_META_SCHEMAS�dict�_VALIDATORSr rrr!�create�	Validator��selfrrr�setUp$s$��

�zTestCreateAndExtend.setUpcCs.|�|jj|jj|jjf|j|j|jf�dS�N)r#r(�
VALIDATORS�META_SCHEMA�TYPE_CHECKERrr r!r)rrr�
test_attrs9s���zTestCreateAndExtend.test_attrscCs dgi}|�|�|�j|�dS)Nr)r#r(r�r*rrrr�	test_initFszTestCreateAndExtend.test_initcCs0dgi}|�|�}t|�d��}|�|g�dS)NrZhello)r(�list�iter_errorsr#�r*rrrrrr�test_iter_errors_successfulJs
z/TestCreateAndExtend.test_iter_errors_successfulcCstdddigi}|�|�}tjdd|dddigtdg�d�}t|�d��}|�t|�d�|�|d��|���dS)NrrzWhoops!�goodbye)rrr�validator_value�schema_path�r)	r(rrrr3r4r#�lenZ	_contents)r*rrZexpected_errorrrrr�test_iter_errors_one_errorQs
�	z.TestCreateAndExtend.test_iter_errors_one_errorcCsHdddiddd�ddigi}|�|�}t|�d��}|�t|�d	�dS)
NrrZFirstzSecond!Zasdf)rrZThirdr7�)r(r3r4r#r;r5rrr� test_iter_errors_multiple_errorsbs��
z4TestCreateAndExtend.test_iter_errors_multiple_errorscCsRtjddidd�}|�tjjd�|�tjjd�|�|jd�|�|jd�dS)Nr�	something�
my version�r �versionZMyVersionValidator)	rr'r"r$�popr&r#�__name__�__qualname__�r*r(rrr�.test_if_a_version_is_provided_it_is_registeredos�zBTestCreateAndExtend.test_if_a_version_is_provided_it_is_registeredcCsJtjddidd�}|�tjjd�|�tjjd�|�t|i��d�dS)Nrr?r@rAz2MyVersionValidator(schema={}, format_checker=None))rr'r"r$rCr&r#�reprrFrrr�	test_reprys�
�zTestCreateAndExtend.test_reprcCsVtjddidd�}|�tjjd�|�tjjd�|�t|dtt	d��i��d�dS)Nrr?r@rA�ai�zNMyVersionValidator(schema={'a': [0, 1, 2, 3, 4, 5, ...]}, format_checker=None))
rr'r"r$rCr&r#rHr3�rangerFrrr�test_long_repr�s��z"TestCreateAndExtend.test_long_reprcCs$tjid�}|�t|i��d�dS)N�r z)Validator(schema={}, format_checker=None))rr'r#rHrFrrr�test_repr_no_version�s

�z(TestCreateAndExtend.test_repr_no_versioncCsDtjddidd�}|�tjjd�|�tjjd�|�|jd�dS)Nrr?zfoo-barrAZFooBarValidator)rr'r"r$rCr&r#rErFrrr�-test_dashes_are_stripped_from_validator_names�s�zATestCreateAndExtend.test_dashes_are_stripped_from_validator_namescCs,ttj�}tjddid�|�tj|�dS)N�idrM)r%rr$r'r#)r*�originalrrr�6test_if_a_version_is_not_provided_it_is_not_registered�s
zJTestCreateAndExtend.test_if_a_version_is_not_provided_it_is_not_registeredcCsRd}d|i}tj|ddd�d�|�tjj|�|�tjjd�|�|tj�dS)N�meta schema idrPr@cSs|�dd�S�NrP���get��srrr�<lambda>��zMTestCreateAndExtend.test_validates_registers_meta_schema_id.<locals>.<lambda>�r rB�id_of�rr'r"r$rCr&�assertIn�r*Zmeta_schema_keyZmy_meta_schemarrr�'test_validates_registers_meta_schema_id�s�z;TestCreateAndExtend.test_validates_registers_meta_schema_idcCsLd}d|i}tj|dd�|�tjj|�|�tjjd�|�|tj�dS)N�meta schema $idrr@rAr^r`rrr�.test_validates_registers_meta_schema_draft6_id�s�zBTestCreateAndExtend.test_validates_registers_meta_schema_draft6_idcsDtjidd��|�t�fdd�dgfdddd	d
ifdfD���dS)Nr�r rc3s$|]\}}�i�j||d�VqdS))r�typeN)�is_type)�.0rer�r(rr�	<genexpr>�s�z@TestCreateAndExtend.test_create_default_types.<locals>.<genexpr>�array)�booleanT)�integer�)�nullN)�numberg(@�object)�string�foo)rr'�
assertTrue�allr)rrhr�test_create_default_types�s���z-TestCreateAndExtend.test_create_default_typescCsxtjtjjddiid�d�}|�ddi�|�tj��|�i�Wd�n1sX0Y|ddi��d�dS)zq
        One can create a validator class whose metaschema uses a different
        dialect than itself.
        r�const)�$schema�notrMrr�barN)	rr'�Draft202012Validatorr.�check_schema�assertRaisesr�SchemaError�validate�r*ZNoEmptySchemasValidatorrrr�+test_check_schema_with_different_metaschema�s
��(z?TestCreateAndExtend.test_check_schema_with_different_metaschemacCsVtjdddigidtid�}|�tj��|�i�Wd�n1sH0YdS)z�
        A validator whose metaschema doesn't declare $schema defaults to its
        own validation behavior, not the latest "normal" specification.
        rrzMeta schema whoops!rdN)rr'rr|rr}r{rrrr�<test_check_schema_with_different_metaschema_defaults_to_self�s�zPTestCreateAndExtend.test_check_schema_with_different_metaschema_defaults_to_selfcCs`t|jj�}t�}tj|jd|id�}|�|j|j|j|jjft||d�|jj|jj|f�dS)N�new)r)r�)	r%r(r-rpr�extendr#r.r/)r*rQr�ZExtendedrrr�test_extend�s$��
��zTestCreateAndExtend.test_extendcsf�fdd�}d}d|d�}tj|�j�j|d�}��|�|j�|�t�|�}��|�|j�|�dS)zK
        Extending a validator preserves its notion of schema IDs.
        cs|�d�j�|��S)N�__test__)rWr(�ID_OF�rr)rrr]sz3TestCreateAndExtend.test_extend_idof.<locals>.id_ofzthe://correct/id/zthe://wrong/id/)rr�)r rr!r]N)rr'r!r#r�r.r�)r*r]Z
correct_idr ZOriginal�Derivedrr)r�test_extend_idof
s��
z$TestCreateAndExtend.test_extend_idofcCsRdddiiddd�}t�|�}|�|�d��t�tj�}|�||��d��dS)	zV
        Extending a validator preserves its notion of applicable validators.
        �testreroz#/$defs/testr:)�$defs�$ref�maximum�%N)r�Draft4Validatorrs�is_validr�)r*rZdraft4r�rrr�!test_extend_applicable_validators s
�
z5TestCreateAndExtend.test_extend_applicable_validatorsN)rD�
__module__rEr+r0r2r6r<r>rGrIrLrNrOrRrarcrur�r�r�r�r�rrrrr#s(


	

rc@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)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<duS)v�TestValidationErrorMessagescOst|�dtj�}|�|�||g|�Ri|��}t|�|��}|j|d|��d�|jt|�dd|��d�|dj	S)N�clszNo errors were raised for )�msgr:z"Expected exactly one error, found r)
rCr�_LATEST_VERSIONr{r3r4rsr#r;r)r*rr�args�kwargsr�rrrrr�message_for3s
�z'TestValidationErrorMessages.message_forcCs"|jdddid�}|�|d�dS�Nr:rerq�rr�1 is not of type 'string'�r�r#�r*rrrr�test_single_type_failure@sz4TestValidationErrorMessages.test_single_type_failurecCs$|jdddgid�}|�|d�dSr�r�r�rrr�test_single_type_list_failureDsz9TestValidationErrorMessages.test_single_type_list_failurecCs*d}|jddt|�id�}|�|d�dS)N)rqrpr:rer�z#1 is not of type 'string', 'object')r�r3r#)r*�typesrrrr�test_multiple_type_failureHsz6TestValidationErrorMessages.test_multiple_type_failurecCs2dddd�gi}|jd|tjd�}|�|d�dS)NreZFoor=)�name�minimumr:�rrr�z1 is not of type 'Foo'�r�r�Draft3Validatorr#�r*rrrrr�#test_object_with_named_type_failureMs�z?TestValidationErrorMessages.test_object_with_named_type_failurecCs"|jdddid�}|�|d�dS)Nr:r��r�z1 is less than the minimum of 2r�r�rrr�test_minimumVsz(TestValidationErrorMessages.test_minimumcCs"|jdddid�}|�|d�dS)Nr:r�rr�z"1 is greater than the maximum of 0r�r�rrr�test_maximumZsz(TestValidationErrorMessages.test_maximumcCs:d\}}d||ii}|jddi|tjd�}|�|d�dS�N�ryrr�dependenciesryr�r�z'foo' is a dependency of 'bar'r��r*Zdepend�onrrrrr� test_dependencies_single_element^s�z<TestValidationErrorMessages.test_dependencies_single_elementcCs6dddigi}|jdd|gitjd�}|�|d�dS)Nrer�r=r:r�z+1 is not of type {'type': [{'minimum': 3}]}r�)r*rerrrr�-test_object_without_title_type_failure_draft3hs��zITestValidationErrorMessages.test_object_without_title_type_failure_draft3cCs<d\}}d||gii}|jddi|tjd�}|�|d�dSr�r�r�rrr�test_dependencies_list_draft3ts�z9TestValidationErrorMessages.test_dependencies_list_draft3cCs<d\}}d||gii}|jddi|tjd�}|�|d�dSr��r�r�Draft7Validatorr#r�rrr�test_dependencies_list_draft7~s�z9TestValidationErrorMessages.test_dependencies_list_draft7cCs*|jdggdd�tjd�}|�d|�dS)Nr�F��itemsZadditionalItemsr�z(2 was unexpected)�r�rr�r_r�rrr�#test_additionalItems_single_failure�s�z?TestValidationErrorMessages.test_additionalItems_single_failurecCs,|jgd�gdd�tjd�}|�d|�dS)N�r:r�r=Fr�r�z(1, 2, 3 were unexpected)r�r�rrr�&test_additionalItems_multiple_failures�s�zBTestValidationErrorMessages.test_additionalItems_multiple_failurescCs.d}ddi}|j|di|d�}|�d|�dS)Nrr�additionalPropertiesFr�r�z('foo' was unexpected)�r�r_)r*�
additionalrrrrr�(test_additionalProperties_single_failure�szDTestValidationErrorMessages.test_additionalProperties_single_failurecCsPddi}|jt�ddg�|d�}|�td�|�|�td�|�|�d|�dS)Nr�Frrryr�zwere unexpected))r�r%�fromkeysr_rHr�rrr�+test_additionalProperties_multiple_failures�s�zGTestValidationErrorMessages.test_additionalProperties_multiple_failurescCs*ddi}|jddi|d�}|�d|�dS)Nrvrmrrryr�z12 was expectedr�r�rrr�
test_const�s�z&TestValidationErrorMessages.test_constcCs4dddii}|jdigg|tjd�}|�|d�dS)N�containsrvrmr�r�z4None of [2, {}, []] are valid under the given schema)r�r�Draft6Validatorr#r�rrr�test_contains_draft_6�s��z1TestValidationErrorMessages.test_contains_draft_6cCsdtdd�}|�d�dd��ddi}|jd||d�}|�td�|�|�td�|�|�d	|�dS)
Nr)�formats�thingcSsdS�NFr��valuerrrrZ�r[zQTestValidationErrorMessages.test_invalid_format_default_message.<locals>.<lambda>�formatZbla)rr�format_checkerzis not a)r�checksr�r_rH)r*�checkerrrrrr�#test_invalid_format_default_message�s
�z?TestValidationErrorMessages.test_invalid_format_default_messagec
Cs�ddddiddid�d�}|jddi|tjd	�}|�|d
�td�td�td���|jdd
d�|tjd	�}|�|d�td�td�td�td���dS)NrpFrerq)�^abc$�^def$)rer��patternProperties�zebra�{r�z,{} does not match any of the regexes: {}, {}r�r�i�)r��fishz.{}, {} do not match any of the regexes: {}, {}r�)r�rr�r#r�rHr�rrr�1test_additionalProperties_false_patternProperties�s8��������zMTestValidationErrorMessages.test_additionalProperties_false_patternPropertiescCs|jddd�}|�|d�dS)Nr?Fr�z'False schema does not allow 'something'r�r�rrr�test_False_schema�s
�z-TestValidationErrorMessages.test_False_schemacCs"|jdddid�}|�|d�dS)Nr=Z
multipleOfr�r�z3 is not a multiple of 2r�r�rrr�test_multipleOf�s
�z+TestValidationErrorMessages.test_multipleOfcCs"|jgddid�}|�|d�dS)N�minItemsr�r�z[] is too shortr�r�rrr�
test_minItems�sz)TestValidationErrorMessages.test_minItemscCs&|jgd�ddid�}|�|d�dS)Nr��maxItemsr�r�z[1, 2, 3] is too longr�r�rrr�
test_maxItems�sz)TestValidationErrorMessages.test_maxItemscCs"|jgddid�}|�|d�dS)Nr�r:r�z[] should be non-emptyr�r�rrr�test_minItems_1sz+TestValidationErrorMessages.test_minItems_1cCs&|jgd�ddid�}|�|d�dS)Nr�r�rr�z![1, 2, 3] is expected to be emptyr�r�rrr�test_maxItems_0sz+TestValidationErrorMessages.test_maxItems_0cCs"|jdddid�}|�|d�dS)NrU�	minLengthr�r�z'' is too shortr�r�rrr�test_minLengths
�z*TestValidationErrorMessages.test_minLengthcCs"|jdddid�}|�|d�dS)N�abc�	maxLengthr�r�z'abc' is too longr�r�rrr�test_maxLengths
�z*TestValidationErrorMessages.test_maxLengthcCs"|jdddid�}|�|d�dS)NrUr�r:r�z'' should be non-emptyr�r�rrr�test_minLength_1sz,TestValidationErrorMessages.test_minLength_1cCs"|jdddid�}|�|d�dS)Nr�r�rr�z'abc' is expected to be emptyr�r�rrr�test_maxLength_0sz,TestValidationErrorMessages.test_maxLength_0cCs"|jiddid�}|�|d�dS)N�
minPropertiesr�r�z"{} does not have enough propertiesr�r�rrr�test_minPropertiessz.TestValidationErrorMessages.test_minPropertiescCs*|jiiid�ddid�}|�|d�dS)N)rJ�b�c�
maxPropertiesr�r�z3{'a': {}, 'b': {}, 'c': {}} has too many propertiesr�r�rrr�test_maxProperties"s
��z.TestValidationErrorMessages.test_maxPropertiescCs"|jiddid�}|�|d�dS)Nr�r:r�z{} should be non-emptyr�r�rrr�test_minProperties_1,sz0TestValidationErrorMessages.test_minProperties_1cCs&|jddiddid�}|�|d�dS)Nr:r�r�rr�z{1: 2} is expected to be emptyr�r�rrr�test_maxProperties_00s
�z0TestValidationErrorMessages.test_maxProperties_0cCs,|jgd�diigd�d�}|�|d�dS)N)r:r�rrF�r��prefixItemsr�z1Expected at most 2 items but found 1 extra: 'foo'r�r�rrr�test_prefixItems_with_items7s��z7TestValidationErrorMessages.test_prefixItems_with_itemscCs,|jgd�diigd�d�}|�|d�dS)N�r:r�rr�Fr�r�z6Expected at most 2 items but found 2 extra: ['foo', 5]r�r�rrr�*test_prefixItems_with_multiple_extra_itemsAs��zFTestValidationErrorMessages.test_prefixItems_with_multiple_extra_itemscCs"|jdddid�}|�|d�dS)N�bbb�patternz^a*$r�z'bbb' does not match '^a*$'r�r�rrr�test_patternKs
�z(TestValidationErrorMessages.test_patterncCs&|jgdddiid�}|�|d�dS)Nr�rerqr�z3[] does not contain items matching the given schemar�r�rrr�test_does_not_containRs
��z1TestValidationErrorMessages.test_does_not_containcCs,|jddgddidd�d�}|�|d�dS)	Nrrr:rerqr��r��minContainsr��MToo few items match the given schema (expected at least 2 but only 1 matched)r�r�rrr�test_contains_too_few\s��z1TestValidationErrorMessages.test_contains_too_fewcCs.|jddgddiddd�d�}|�|d	�dS)
Nrrr:rerqr���r�r��maxContainsr�r�r�r�rrr�&test_contains_too_few_both_constrainedgs���zBTestValidationErrorMessages.test_contains_too_few_both_constrainedcCs,|jgd�ddidd�d�}|�|d�dS)N�rrry�bazrerqr��r�rr��:Too many items match the given schema (expected at most 2)r�r�rrr�test_contains_too_manyvs��z2TestValidationErrorMessages.test_contains_too_manycCs0|jdgdddiddd�d�}|�|d	�dS)
Nrrr�rerqr�r�r�r�z:Too many items match the given schema (expected at most 4)r�r�rrr�'test_contains_too_many_both_constrained�s���zCTestValidationErrorMessages.test_contains_too_many_both_constrainedcCs"|jdddid�}|�|d�dS)Nr=ZexclusiveMinimumr�r�z+3 is less than or equal to the minimum of 5r�r�rrr�test_exclusiveMinimum�s��z1TestValidationErrorMessages.test_exclusiveMinimumcCs"|jdddid�}|�|d�dS)Nr=ZexclusiveMaximumr�r�z.3 is greater than or equal to the maximum of 2r�r�rrr�test_exclusiveMaximum�s
�z1TestValidationErrorMessages.test_exclusiveMaximumcCs$|jiddgid�}|�|d�dS)N�requiredrrr�z'foo' is a required propertyr�r�rrr�
test_required�sz)TestValidationErrorMessages.test_requiredcCs,|jdiidddgiid�}|�|d�dS)NrrZdependentRequiredryr�z'bar' is a dependency of 'foo'r�r�rrr�test_dependentRequired�s
�z2TestValidationErrorMessages.test_dependentRequiredcCs$|jiddgid�}|�|d�dS)N�oneOfFr�z.{} is not valid under any of the given schemasr�r�rrr�test_oneOf_matches_none�s
�z3TestValidationErrorMessages.test_oneOf_matches_nonecCs&|jidddgid�}|�|d�dS)Nr
Tr�z${} is valid under each of True, Truer�r�rrr�test_oneOf_matches_too_many�sz7TestValidationErrorMessages.test_oneOf_matches_too_manycCs,ddd�}|jddg|d�}|�|d�dS)NrjF�re�unevaluatedItemsrrryr�z@Unevaluated items are not allowed ('foo', 'bar' were unexpected)r�r�rrr�test_unevaluated_items�s
�z2TestValidationErrorMessages.test_unevaluated_itemscCs(ddd�}|jd|d�}|�|d�dS)NrjFrrrr�z'foo' is not of type 'array'r�r�rrr�&test_unevaluated_items_on_invalid_type�s
zBTestValidationErrorMessages.test_unevaluated_items_on_invalid_typecCs<dddiiddid�}|jdddd�|d	�}|�|d
�dS)Nrrrerqrvrm��
properties�unevaluatedPropertiesryrr�z_Unevaluated properties are not valid under the given schema ('bar' was unevaluated and invalid)r�r�rrr�5test_unevaluated_properties_invalid_against_subschema�s
����zQTestValidationErrorMessages.test_unevaluated_properties_invalid_against_subschemacCs.ddd�}|jddd�|d�}|�|d�dS)	NrpF�rerrrry�rrryr�zEUnevaluated properties are not allowed ('bar', 'foo' were unexpected)r�r�rrr�&test_unevaluated_properties_disallowed�s
���zBTestValidationErrorMessages.test_unevaluated_properties_disallowedcCs(ddd�}|jd|d�}|�|d�dS)NrpFrrrr�z'foo' is not of type 'object'r�r�rrr�+test_unevaluated_properties_on_invalid_type�s
zGTestValidationErrorMessages.test_unevaluated_properties_on_invalid_typecCs.igdd�}|jgd�|d�}|�|d�dS)NF�r�r�rr�z9Expected at most 1 item but found 2 extra: ['bar', 'baz']r�r�rrr�test_single_item�s��z,TestValidationErrorMessages.test_single_itemcCs2igdd�}|jgd�|tjd�}|�|d�dS)NFr��rrryr�r�z<Additional items are not allowed ('bar', 37 were unexpected)r�r�rrr�-test_heterogeneous_additionalItems_with_Items�s��zITestValidationErrorMessages.test_heterogeneous_additionalItems_with_ItemscCs.igdd�}|jgd�|d�}|�|d�dS)NFrrr�z6Expected at most 1 item but found 2 extra: ['bar', 37]r�r�rrr�$test_heterogeneous_items_prefixItemss��z@TestValidationErrorMessages.test_heterogeneous_items_prefixItemscCs.igdd�}|jgd�|d�}|�|d�dS)NF)r�rrr�z=Unevaluated items are not allowed ('bar', 37 were unexpected)r�r�rrr�/test_heterogeneous_unevaluatedItems_prefixItemss��zKTestValidationErrorMessages.test_heterogeneous_unevaluatedItems_prefixItemscCs4diidd�}|jiddd�|d�}|�|d�d	S)
�K
        Not valid deserialized JSON, but this should not blow up.
        rrF)rr�rrm�rrrJr�r�z?Additional properties are not allowed (37, 'a' were unexpected)Nr�r�rrr�2test_heterogeneous_properties_additionalPropertiess
��zNTestValidationErrorMessages.test_heterogeneous_properties_additionalPropertiescCs4diidd�}|jiddd�|d�}|�|d�d	S)
r"rrFrrrmr#r�z@Unevaluated properties are not allowed (37, 'a' were unexpected)Nr�r�rrr�3test_heterogeneous_properties_unevaluatedProperties$s
��zOTestValidationErrorMessages.test_heterogeneous_properties_unevaluatedPropertiesN)=rDr�rEr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	rrrrrrrrrrrr r!r$r%rrrrr�2st
	








r�c@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)*�TestValidationErrorDetailscCsd}dddiddigi}t�|�}t|�|��}|�t|�d�|d}|�|jd�|�|j|d�|�|j|�|�|j	|�|�
|j�|�|jt
g��|�|jt
g��|�|jt
g��|�|jd	�|�|jt
dg��|�|jt
dg��|�|jt
dg��|�t|j�d
�t|j�\}}|�|jd�|�|j|ddd�|�|j|�|�|j	|dd�|�|j|�|�|jt
g��|�|jt
g��|�|jt
g��|�|jd	�|�|jt
ddg��|�|jt
ddg��|�|jt
gd���|�|j�|�|jd�|�|j|ddd�|�|j|�|�|j	|dd�|�|j|�|�|jt
g��|�|jt
g��|�|jt
g��|�|jd	�|�|jt
ddg��|�|jt
ddg��|�|jt
gd���|�t|j�d�dS)
Nr��anyOfr��rerqr:r�$r�)r'rr�)r'r:re)rr�r3r4r#r;rr8rr�assertIsNone�parent�pathr�
relative_path�
absolute_path�	json_pathr9�relative_schema_path�absolute_schema_path�context�
sorted_errors�assertIs�assertFalse�r*rrrr�e�e1�e2rrr�
test_anyOf6sh��
�z%TestValidationErrorDetails.test_anyOfcCsddi}dddiddddgiid�gi}t�|�}t|�|��}|�t|�d�|d	}|�|jd�|�|j|d�|�|j|�|�|j	|�|�
|j�|�|jt
g��|�|jt
g��|�|jt
g��|�|jd
�|�|jt
dg��|�|jt
dg��|�|jt
dg��|�t|j�d�t|j�\}}|�|jd�|�|j|dd	d�|�|j|�|�|j	|dd	�|�|j|�|�|jt
g��|�|jt
g��|�|jt
g��|�|jd
�|�|jt
d	dg��|�|jt
d	dg��|�|jt
gd���|�|j�|�|jd�|�|jdg�|�|jd�|�|j	ddgi�|�|j|�|�|jt
dg��|�|jt
dg��|�|jt
dg��|�|jd�|�|jt
gd
���|�|jt
gd
���|�|jt
gd���|�|j�dS)Nrrr:rerlrp�enumr��rerrr))rerre�$.foo)r:rrrr;)rer:rrrr;)rr�r3r4r#r;rr8rrr*r+r,rr-r.r/r9r0r1r2r3r4r5r6rrr�	test_type{sv���

��
�z$TestValidationErrorDetails.test_typec	Cs�ddgddd�}dddid	did
gd�d�d
�i}t�|�}|�|�}t|�\}}}}|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|jtdg��|�|j	d�|�|j	d�|�|j	d�|�|j	d�|�|j
d	�|�|j
d�|�|j
d�|�|j
d�dS)Nr�r:�Zspam)rrryr�quuxrrerqr��
)r�r���)r�r;rryrrr�$.barz$.bazr=r;r�)rr�r4r3r#r,rr-r.r/r)	r*rrrrr8r9�e3�e4rrr�test_single_nesting�s<��

z.TestValidationErrorDetails.test_single_nestingcCs ddddgid�dg}dddgddd	gid
ddid
did�d�d�d�d�}t�|�}|�|�}t|�\}}}}}	}
|�|jtg��|�|jtdg��|�|jtddg��|�|jtgd���|�|	jtgd���|�|
jtddg��|�|jd�|�|jd�|�|jd�|�|jd�|�|	jd�|�|
jd�|�|jtdg��|�|jtddg��|�t	|j�gd��|�t	|j�gd��|�t	|	j�gd ��|�t	|
j�gd!��|�|j
d�|�|j
d�|�|j
d�|�|j
d�|�|	j
d
�|�|
j
d�dS)"Nr:r�rrr@rqrpr;r=rjr
Tr�)ryrr<)rer�rry)r:ryry)r:ryrrrr)�$[0]z$[1].barz$[1].bar.barz$[1].bar.bazz$[1].foorer�)r�rryre)r�rryrryr
)r�rryrrr�)r�rrrr;)rr�r4r3r#r,rr/r9r3r)r*rrrrr8r9rErFZe5Ze6rrr�test_multiple_nesting�sb
�����

����z0TestValidationErrorDetails.test_multiple_nestingc	Cs<dddddgddiddd	d
iid�d�d
�giiddgdd	d
iid�}dddddddiid�id�i}t�|�}|�|�\}|�|jtdg��|�|jtgd���|�|jd�|j\}|�|jtgd���|�|jtgd���|�|jd�|j\}|�|jtgd���|�|jtgd���|�|jd�dS)N�noder'rpr��childrenrerq�^.*$r�z#/definitions/node)rer�)r�rK)rer
r�root)�definitionsrer
rrJ�ab)rrMr'z$.root)rMrKrJ)	rrMr'rrrKr�rLr'z$.root.children.a)rMrKrJrKrO)rrMr'rrrKr�rLr'rrrKr�rLr'z$.root.children.a.children.ab)	rr�r4r#r.rr1r/r2)r*rrrr7r8r9rrr�test_recursive,sv��������
�������
�������z)TestValidationErrorDetails.test_recursivecCs�ddd�}dddd�i}t�|�}|�|�}t|�\}}|�|jtdg��|�|jtdg��|�|jd	�|�|jd
�|�|jd�|�|jd�dS)
Nryr�r�r�rlr��rer�rrrDr=rer��	rr�r4r3r#r,rr/r�r*rrrrr8r9rrr�test_additionalProperties�s


z4TestValidationErrorDetails.test_additionalPropertiescCs�ddd�}dddiddid�i}t�|�}|�|�}t|�\}}|�|jtd	g��|�|jtd
g��|�|jd�|�|jd�|�|jd�|�|jd�dS)
Nr:r�r�r�rerqr�r�ryrrrDr=rRrSrrr�test_patternProperties�s
��

z1TestValidationErrorDetails.test_patternPropertiescCs�ddg}gddd�d�}t�|�}|�|�}t|�\}}|�|jtdg��|�|jtdg��|�|jd�|�|jd	�|�|jd
�|�|jd�dS)Nrrr:rlr�rQr�rrH�$[1]rer�rRrSrrr�test_additionalItems�s�

z/TestValidationErrorDetails.test_additionalItemscCs�gd�}igddd�d�}t�|�}|�|�}t|�\}}|�|jtdg��|�|jtdg��|�|jd�|�|jd	�|�|jd
�|�|jd�dS)N)rrryr:rlr�rQr�r:r�rVz$[2]rer�rRrSrrr�test_additionalItems_with_items�s�

z:TestValidationErrorDetails.test_additionalItems_with_itemscCs�ddi}ddddiii}t�|�}|�|�\}|�|jd�|�|jd�|�|jtg��|�|jd�|�|j	tddg��dS)NrrrmZ
propertyNamesrxrvz0'foo' should not be valid under {'const': 'foo'}r)�
rr�r4r#rrr,rr/r9)r*rrr�errorrrr�test_propertyNames�s
�z-TestValidationErrorDetails.test_propertyNamescCs~ddiddid�}t�|�}|�d�\}|�|jd�|�|jd�|�|jtg��|�|jd�|�|j	tddg��dS)Nrvrm�
)�if�then�13 was expectedr)r^rY�r*rrrZrrr�test_if_then�s�
z'TestValidationErrorDetails.test_if_thencCs~ddiddid�}t�|�}|�d�\}|�|jd�|�|jd�|�|jtg��|�|jd�|�|j	tddg��dS)	Nrvrmr\)r]�elser?r_r)rbrYr`rrr�test_if_else�s�
z'TestValidationErrorDetails.test_if_elsec
CsTt�d�}|�d�\}|�|j|j|j|j|j|j	|j
fdddddtg�df�dS)NFrmzFalse schema does not allow 12r))rr�r4r#rrr8rrr9r/r)r*rrZrrr�test_boolean_schema_Falses(
�
��z4TestValidationErrorDetails.test_boolean_schema_FalsecCs�ddddii}}tjd|itjdi||id�d�}|�d	d
i�\}|�|j|j|j|j|j	|j
|j|jfdddd
t
d	g�ddit
ddg�df�dS)
NZsomeRefr�rerlr�rU��store��resolverrrZnotAnIntegerz''notAnInteger' is not of type 'integer'r=)rr��_RefResolverr4r#rrr8rr.rr9r/r)r*�refrrrZrrr�test_ref's4��
��z#TestValidationErrorDetails.test_refcCs�dddiiiddigi}t�|�}|�gd��\}}|�|j|j|j|j|j|j	|j
|jfddddtd	g�dditgd
��df�|�|j|j|j|j|j|j	|j
|jfdddd
tdg�dditgd��df�dS)Nr�rerqr�r=r�r�r:r)r�rrerHz"5 is greater than the maximum of 3r�)r�r=r��$[3]�
rrzr4r#rrr8rr.rr9r/r)r*rrZ
type_errorZ	min_errorrrr�test_prefixItemsFsV
�
���
��z+TestValidationErrorDetails.test_prefixItemscCs�ddiigd�}t�|�}|�gd��\}}|�|j|j|j|j|j|j	|j
|jfddddtdg�dditddg�d	f�|�|j|j|j|j|j|j	|j
|jfd
dddtdg�dditddg�d
f�dS)Nrerqr�)rrr�ryr�rz2 is not of type 'string'r�r:r�rVz4 is not of type 'string'r�r=rlrm�r*rrr8r9rrrr�wsZ�
�
���
��z6TestValidationErrorDetails.test_prefixItems_with_itemscCs�ddidd�}t�|�}|�gd��\}|�|j|j|j|j|j|j	|j
|jfdddgd�tg�ddidd�tdg�d	f�d
S)z�
        `contains` + `maxContains` produces only one error, even if there are
        many more incorrectly matching elements.
        rerqr�r)rrr�ryr�rr@rrr�r)Nrmr`rrrr�s.
���z1TestValidationErrorDetails.test_contains_too_manycCs�ddidd�}t�|�}|�gd��\}|�|j|j|j|j|j|j	|j
|jfdddgd�tg�ddidd�tdg�d	f�dS)
Nrerqr�r�)rrr�r�r�r�r�r)rmr`rrrr��s.
���z0TestValidationErrorDetails.test_contains_too_fewcCs�ddidd�}t�|�}|�ddg�\}|�|j|j|j|j|j|j	|j
|jfddddiddgtg�ddidd�tdg�df�dS)	Nrerqr�r�r�z7[2, 4] does not contain items matching the given schemar�r)rmr`rrr�test_contains_none�s.
���z-TestValidationErrorDetails.test_contains_nonec
Csdddgiidddgd�id�}t�|�}|�dii�\}}|�|j|j|j|j|j|j	|j
|j|jf	d	ddgit
dg�ddgit
gd
��t
gd
��df	�|�|j|j|j|j|j|j	|j
|j|jf	dddgit
dg�ddgd�t
gd
��t
gd
��df	�dS)
Nrrr
ry�apropz#/$defs/foor)r�r
)r�rz'bar' is a required property)rrqr
z$.apropz'baz' is a required property)rrzr4r#rrr8rr.rr9r0r/rrorrr�test_ref_siblingsj���

�

���


��z+TestValidationErrorDetails.test_ref_siblingN)rDr�rEr:r>rGrIrPrTrUrWrXr[rarcrdrkrnr�rr�rprrrrrrr&3s(EM'=e14r&c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�MetaSchemaTestsMixincCs@|�tj�� |j�ddi�Wd�n1s20YdS)Nrrm�r|rr}r(r{r)rrr�test_invalid_propertiesDsz,MetaSchemaTestsMixin.test_invalid_propertiescCs@|�tj�� |j�ddi�Wd�n1s20YdS)Nr��1rtr)rrr�test_minItems_invalid_stringHsz1MetaSchemaTestsMixin.test_minItems_invalid_stringcCsd|jtjtjhvrP|�tj�� |j�dgi�Wd�q`1sD0Yn|j�dgi�dS)z�
        Technically, all the spec says is they SHOULD have elements, not MUST.

        (As of Draft 6. Previous drafts do say MUST).

        See #529.
        r;N�r(rr�r�r|rr}r{r)rrr�test_enum_allows_empty_arraysMs�0z2MetaSchemaTestsMixin.test_enum_allows_empty_arrayscCsl|jtjtjhvrT|�tj��$|j�dddgi�Wd�qh1sH0Yn|j�dddgi�dS)z�
        Technically, all the spec says is they SHOULD be unique, not MUST.

        (As of Draft 6. Previous drafts do say MUST).

        See #529.
        r;rmNrxr)rrr�!test_enum_allows_non_unique_items^s�4z6MetaSchemaTestsMixin.test_enum_allows_non_unique_itemscCs@|�tj�� |j�ddi�Wd�n1s20YdS)Nr��
*notaregexrtr)rrr�test_schema_with_invalid_regexosz3MetaSchemaTestsMixin.test_schema_with_invalid_regexcCs|jjddidd�dS)Nr�r{�r�)r(r{r)rrr�>test_schema_with_invalid_regex_with_disabled_format_validationss�zSMetaSchemaTestsMixin.test_schema_with_invalid_regex_with_disabled_format_validationN)	rDr�rErurwryrzr|r~rrrrrsBsrsc@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'S)(�ValidatorTestMixincCs|�|�i�tj�dSr,)�assertIsInstancer(rr)rrr�)test_it_implements_the_validator_protocol{sz<ValidatorTestMixin.test_it_implements_the_validator_protocolcCs$|j\}}|�|�|��|��dSr,)�validrsr(r��r*rrrrr�test_valid_instances_are_valid~s
z1ValidatorTestMixin.test_valid_instances_are_validcCs$|j\}}|�|�|��|��dSr,)�invalidr5r(r�r�rrr�$test_invalid_instances_are_not_valid�s
z7ValidatorTestMixin.test_invalid_instances_are_not_validcCs |�t�t�i�jt�d�dS)N�r)r(rpr~r)rrr�(test_non_existent_properties_are_ignored�sz;ValidatorTestMixin.test_non_existent_properties_are_ignoredcCsjddit�}}|j||d�}|jddi|jjd�}|jddi|jj|jd�}|�||�|�||�dS)Nrerlr}rq)rr�)r��	_resolver)rr(�evolveZFORMAT_CHECKERr�r#ZassertNotEqual)r*rr�rQr��expectedrrr�test_evolve�s ���zValidatorTestMixin.test_evolvecCs�|�t��&tGdd�d|j��}Wd�n1s60Y|idd�}|�|jgd��|jddid	�}|�|jgd��|�|jd�dS)
ar
        Subclassing validators isn't supported public API, but some users have
        done it, because we don't actually error entirely when it's done :/

        We need to deprecate doing so first to help as many of these users
        ensure they can move to supported APIs, but this test ensures that in
        the interim, we haven't broken those users.
        c@s$eZdZedd�d�Zedd�ZdS)z:ValidatorTestMixin.test_evolve_with_subclass.<locals>.OhNocSsgd�S)Nr�rrrrrrZ�r[zCValidatorTestMixin.test_evolve_with_subclass.<locals>.OhNo.<lambda>)�factoryr���defaultN)rDr�rEr
rr�_barrrrr�OhNo�sr�Nrm)ryr�rerlr�)�assertWarns�DeprecationWarningrr(r#rrr�r�)r*r�rr�rrr�test_evolve_with_subclass�s
2z,ValidatorTestMixin.test_evolve_with_subclasscCs|�|�i��dd��dS)Nrrrq)rsr(rfr)rrr�#test_is_type_is_true_for_valid_type�sz6ValidatorTestMixin.test_is_type_is_true_for_valid_typecCs|�|�i��dd��dS)Nrrrj�r5r(rfr)rrr�&test_is_type_is_false_for_invalid_type�sz9ValidatorTestMixin.test_is_type_is_false_for_invalid_typecCs4|�|�i��dd��|�|�i��dd��dS)NTrlror�r)rrr�,test_is_type_evades_bool_inheriting_from_int�sz?ValidatorTestMixin.test_is_type_evades_bool_inheriting_from_intcCs~dddii}tj|j|jj�ddd��d�}||�}|�ddtd�td	�g�d
igddg}|�dd
�|�|�D�|�dS)Nr�rerocSst|tttf�ot|t�Sr,)�
isinstance�int�floatr�bool�r�r�rrrrZ�s
�zGValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<lambda>�r!r:g�������?rCrrTcSsg|]
}|j�qSrr�)rgrZrrr�
<listcomp>�r[zIValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<listcomp>)	rr�r(r/�redefiner~rr#r4)r*rr(rr�rrr�"test_it_can_validate_with_decimals�s��
�z5ValidatorTestMixin.test_it_can_validate_with_decimalscCs"|jddit�d�}|�d�dS)Nr�Zcarrotr}Zbugs)r(rr~�r*rrrr�7test_it_returns_true_for_formats_it_does_not_know_about�s
�zJValidatorTestMixin.test_it_returns_true_for_formats_it_does_not_know_aboutcCs|�i�}|�|j�dSr,)r(r*r�r�rrr�,test_it_does_not_validate_formats_by_default�s
z?ValidatorTestMixin.test_it_does_not_validate_formats_by_defaultcs�t�}td��|jdtd���fdd��}�jddi|d�}|�d���tj��}|�d	�Wd�n1sr0Y��|j	j
��dS)
NzBad!rr)Zraisescs0|dkrdS|dkr��n��d|�d��dS)N�goodT�badzWhat is z? [Baby Don't Hurt Me])rr��r�r*rr�check�s
zTValidatorTestMixin.test_it_validates_formats_if_a_checker_is_provided.<locals>.checkr�r}r�r�)r�
ValueErrorr�r(r~r|rrr4�	exception�cause)r*r�r�r�cmrr�r�2test_it_validates_formats_if_a_checker_is_provided�s�
(zEValidatorTestMixin.test_it_validates_formats_if_a_checker_is_providedcCsBt�}d|gi}tj|j|jj�|dd��d�}||��d�dS)NrecSs
t|t�Sr,�r�r�r�rrrrZ�r[z@ValidatorTestMixin.test_non_string_custom_type.<locals>.<lambda>r�r?)rprr�r(r/r�r~)r*Znon_string_typer�Crazyrrr�test_non_string_custom_type�s
��z.ValidatorTestMixin.test_non_string_custom_typecCsttj|j|jj�ddd��d�}|�tj��"}|ddi��d�Wd�n1sT0Y|�	d	t
|j��dS)
zh
        A tuple instance properly formats validation errors for uniqueItems.

        See #224
        rjcSs
t|t�Sr,)r��tupler�rrrrZr[zNValidatorTestMixin.test_it_properly_formats_tuples_in_errors.<locals>.<lambda>r��uniqueItemsT)r:r:Nz(1, 1) has non-unique elements)rr�r(r/r�r|rrr~r_�strr�)r*ZTupleValidatorr7rrr�)test_it_properly_formats_tuples_in_errorss��0z<ValidatorTestMixin.test_it_properly_formats_tuples_in_errorscs�ddd�}tdd��tj|j|jj�dd��fdd�d	��d
�}||�}tgd��tdgd
gg�tdg�td
g�gtdg�gtd
g�ggtdg�ggggtd
g�gggggttdg�g�ttd
g�g�g�dd
��dd�g�dtd
g�g��dtdg�g�g�d�dtd
g��g��d�dtdg��g�gtttdg���tttd
g���gg
}|D]}|�|��qTtgd��tdgdgg�tdg�tdg�gtdg�gtdg�ggtdg�ggggtdg�gggggttdg�g�ttdg�g�g�dd��dd�g�dtdg�g��dtdg�g�g�d�dtdg��g��d�dtdg��g�gtttdg���tttdg���gg
}|D]>}|�t	j
��|�|�Wd�n1�s�0Y�qrdS)zO
        Allow array to validate against another defined sequence type
        rjT)rer��	MyMappingza, bcSst|ttf�Sr,)r�r3rr�rrrrZs�zBValidatorTestMixin.test_check_redefined_sequence.<locals>.<lambda>cst|t�f�Sr,)r�r%r��r�rrrZs�)rjrpr�)rJNrvrUTFrrJ)rJr�rJN)rrr�r(r/Z
redefine_manyrr~r|rr)r*rr(rZvalid_instancesrZinvalid_instancesrr�r�test_check_redefined_sequences\


���

"��"�
"��"�z0ValidatorTestMixin.test_check_redefined_sequencecCsH|�t��|�i�j}Wd�n1s,0Y|�|tj�dSr,)r�r�r(rhr�rri)r*rhrrr�.test_it_creates_a_ref_resolver_if_not_providedTs*zAValidatorTestMixin.test_it_creates_a_ref_resolver_if_not_providedcCsndddi}}tjdi||id�}|jd|i|d�}|�tj��|�d�Wd�n1s`0YdS)N�someCoolRefrerlrUrer�rg)rrir(r|rrr~�r*rjrrhrrrr�/test_it_upconverts_from_deprecated_RefResolversYs
zBValidatorTestMixin.test_it_upconverts_from_deprecated_RefResolverscsdG�fdd�d�}|�}ddi}��tj��$�j||d��d�Wd�n1sV0YdS)zb
        Legacy RefResolvers support only the context manager form of
        resolution.
        cseZdZe�fdd��ZdS)znValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolvers.<locals>.LegacyRefResolverc3s��|d�ddiVdS)N�the refrerl�r#)�thisrjr)rr�	resolvinghszxValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolvers.<locals>.LegacyRefResolver.resolvingN)rDr�rErr�rr)rr�LegacyRefResolvergsr�r�r�rgN)r|rrr(r~)r*r�rhrrr)r�@test_it_upconverts_from_yet_older_deprecated_legacy_RefResolversas
zSValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolversN)rDr�rEr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrzs&Brc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�AntiDraft6LeakMixinzN
    Make sure functionality from draft 6 doesn't leak backwards in time.
    cCsN|�tj��}|j�d�Wd�n1s.0Y|�dt|j��dS)NTzTrue is not of type�r|rr}r(r{r_r�r��r*r7rrr�test_True_is_not_a_schemays*z-AntiDraft6LeakMixin.test_True_is_not_a_schemacCsN|�tj��}|j�d�Wd�n1s.0Y|�dt|j��dS)NFzFalse is not of typer�r�rrr�test_False_is_not_a_schema~s*z.AntiDraft6LeakMixin.test_False_is_not_a_schemacCsN|�t�� }|�d��d�Wd�n1s00Y|�|jtj�dS)NTrm�r|�	Exceptionr(r~ZassertNotIsInstancer�rrr�rrr�5test_True_is_not_a_schema_even_if_you_forget_to_check�s.zIAntiDraft6LeakMixin.test_True_is_not_a_schema_even_if_you_forget_to_checkcCsN|�t�� }|�d��d�Wd�n1s00Y|�|jtj�dS)NFrmr�r�rrr�6test_False_is_not_a_schema_even_if_you_forget_to_check�s.zJAntiDraft6LeakMixin.test_False_is_not_a_schema_even_if_you_forget_to_checkN)rDr�rE�__doc__r�r�r�r�rrrrr�ts
r�c@sPeZdZUejZiifZded<ddidfZdd�Z	dd	�Z
d
d�Zdd
�ZdS)�TestDraft3Validator�tuple[dict, dict]r�rerlrrcCs|�ddi�}|�t��dS�Nre�any)r(r~rpr�rrr�#test_any_type_is_valid_for_type_any�sz7TestDraft3Validator.test_any_type_is_valid_for_type_anycCsptj|j|jj�ddd��d�}|ddi�}|�d�|�tj��|�d�Wd�n1sb0YdS)	z(
        Sigh, because why not.
        r�cSs
t|t�Sr,r�r�rrrrZ�r[zBTestDraft3Validator.test_any_type_is_redefinable.<locals>.<lambda>r�rermrrN)	rr�r(r/r�r~r|rr)r*r�rrrr�test_any_type_is_redefinable�s��
z0TestDraft3Validator.test_any_type_is_redefinablecCs |�|�ddi��t���dSr�)rsr(r�rpr)rrr�!test_is_type_is_true_for_any_type�sz5TestDraft3Validator.test_is_type_is_true_for_any_typecCs6|�|�i��dd��|�|�ddi��d��dS)NTrkrer�)rsr(rfr�r)rrr�6test_is_type_does_not_evade_bool_if_it_is_being_tested�szJTestDraft3Validator.test_is_type_does_not_evade_bool_if_it_is_being_testedN)
rDr�rErr�r(r��__annotations__r�r�r�r�r�rrrrr��s
r�c@s0eZdZUejZiifZded<ddidfZdS)�TestDraft4Validatorr�r�rerlrrN)	rDr�rErr�r(r�r�r�rrrrr��s
r�c@s0eZdZUejZiifZded<ddidfZdS)�TestDraft6Validatorr�r�rerlrrN)	rDr�rErr�r(r�r�r�rrrrr��s
r�c@s0eZdZUejZiifZded<ddidfZdS)�TestDraft7Validatorr�r�rerlrrN)	rDr�rErr�r(r�r�r�rrrrr��s
r�c@s0eZdZUejZiifZded<ddidfZdS)�TestDraft201909Validatorr�r�rerlrrN)	rDr�rEr�Draft201909Validatorr(r�r�r�rrrrr��s
r�c@s0eZdZUejZiifZded<ddidfZdS)�TestDraft202012Validatorr�r�rerlrrN)	rDr�rErrzr(r�r�r�rrrrr��s
r�c@seZdZdZdd�ZdS)�TestLatestValidatorzQ
    These really apply to multiple versions but are easiest to test on one.
    cCshd}d|i}tjdi|did�}tj||d�}|�tj��|�d�Wd�n1sZ0YdS)Nr�r�rUFrerg)rrir�r|rrr~r�rrr�2test_ref_resolvers_may_have_boolean_schemas_stored�szFTestLatestValidator.test_ref_resolvers_may_have_boolean_schemas_storedN)rDr�rEr�r�rrrrr��sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS) �TestValidatorForcCs<ddi}|�t�|�tj�ddi}|�t�|�tj�dS)Nrw�&http://json-schema.org/draft-03/schema�'http://json-schema.org/draft-03/schema#)r4r�
validator_forr�r1rrr�test_draft_3�s��zTestValidatorFor.test_draft_3cCs<ddi}|�t�|�tj�ddi}|�t�|�tj�dS)Nrw�&http://json-schema.org/draft-04/schema�'http://json-schema.org/draft-04/schema#)r4rr�r�r1rrr�test_draft_4�s��zTestValidatorFor.test_draft_4cCs<ddi}|�t�|�tj�ddi}|�t�|�tj�dS)Nrw�&http://json-schema.org/draft-06/schema�'http://json-schema.org/draft-06/schema#)r4rr�r�r1rrr�test_draft_6�s��zTestValidatorFor.test_draft_6cCs<ddi}|�t�|�tj�ddi}|�t�|�tj�dS)Nrw�&http://json-schema.org/draft-07/schema�'http://json-schema.org/draft-07/schema#)r4rr�r�r1rrr�test_draft_7s��zTestValidatorFor.test_draft_7cCs<ddi}|�t�|�tj�ddi}|�t�|�tj�dS)Nrwz,https://json-schema.org/draft/2019-09/schemaz-https://json-schema.org/draft/2019-09/schema#)r4rr�r�r1rrr�test_draft_201909s��z"TestValidatorFor.test_draft_201909cCs<ddi}|�t�|�tj�ddi}|�t�|�tj�dS)Nrw�,https://json-schema.org/draft/2020-12/schema�-https://json-schema.org/draft/2020-12/schema#)r4rr�rzr1rrr�test_draft_202012s��z"TestValidatorFor.test_draft_202012cCs|�t�d�tj�dS)NT�r4rr�r�r)rrr�	test_True*s�zTestValidatorFor.test_TruecCs|�t�d�tj�dSr�r�r)rrr�
test_False0s�zTestValidatorFor.test_FalsecCs6tjddiddd�d�}ddi}|�t�|�|�dS)NrPrSZ12cSs|�dd�SrTrVrXrrrrZ:r[z8TestValidatorFor.test_custom_validator.<locals>.<lambda>r\rw�rr'r4r��r*r(rrrr�test_custom_validator6s��z&TestValidatorFor.test_custom_validatorcCs0tjddidd�}ddi}|�t�|�|�dS)NrrbZ13rArwr�r�rrr�test_custom_validator_draft6Bs��z-TestValidatorFor.test_custom_validator_draft6cCs|�t�i�tj�dSr,r�r)rrr�%test_validator_for_jsonschema_defaultMsz6TestValidatorFor.test_validator_for_jsonschema_defaultcCs|�tjidd�d�dS)Nr�)r4rr�r)rrr�!test_validator_for_custom_defaultPsz2TestValidatorFor.test_validator_for_custom_defaultcCs^|�t�� }tjddid�Wd�n1s00Y|�|jt�|�t|j�d�dS)NrwZ
unknownSchemar�z�The metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future.)	r�r�rr�r#�filename�__file__r��warning)r*r�rrr�1test_warns_if_meta_schema_specified_was_not_foundSs.�zBTestValidatorFor.test_warns_if_meta_schema_specified_was_not_foundcCsRtjdd��(}t�d�tjiid�Wd�n1s:0Y|�|�dS)NT��record�always)rr�)�warnings�catch_warnings�simplefilterrr�r5)r*�wrrr�0test_does_not_warn_if_meta_schema_is_unspecified_s
,zATestValidatorFor.test_does_not_warn_if_meta_schema_is_unspecifiedcCs(ddit�}}|�t�||�|�dS)Nrwzmailto:foo@example.com)rpr4rr�)r*rr�rrr�-test_validator_for_custom_default_with_schemaesz>TestValidatorFor.test_validator_for_custom_default_with_schemaN)rDr�rEr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr��s





r�c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestValidatecCsTg}tj�|d|j��t�i|�Wd�n1s80Y|�||g�dS)Nr{)r
�patchrp�appendrr~r#)r*rr(�resultrrr�
assertUsesks*zTestValidate.assertUsescCs,|jdditjd�|jdditjd�dS)Nrwr��rr(r�)r	rr�r)rrr�test_draft3_validator_is_chosenqs��z,TestValidate.test_draft3_validator_is_chosencCs,|jdditjd�|jdditjd�dS)Nrwr�r
r�)r	rr�r)rrr�test_draft4_validator_is_chosen|s��z,TestValidate.test_draft4_validator_is_chosencCs,|jdditjd�|jdditjd�dS)Nrwr�r
r�)r	rr�r)rrr�test_draft6_validator_is_chosen�s��z,TestValidate.test_draft6_validator_is_chosencCs,|jdditjd�|jdditjd�dS)Nrwr�r
r�)r	rr�r)rrr�test_draft7_validator_is_chosen�s��z,TestValidate.test_draft7_validator_is_chosencCs,|jdditjd�|jdditjd�dS)Nrwr�r
r��r	rrzr)rrr�$test_draft202012_validator_is_chosen�s����z1TestValidate.test_draft202012_validator_is_chosencCs|jitjd�dS)Nr
rr)rrr�)test_draft202012_validator_is_the_default�sz6TestValidate.test_draft202012_validator_is_the_defaultcCsR|�tj�� }t�dddi�Wd�n1s20Y|�t|j�d�dS)Nrmrerqz1(?s)Failed validating '.*' in schema.*On instance)r|rrrr~�assertRegexr�r�r�rrr�test_validation_error_message�s.�z*TestValidate.test_validation_error_messagecCsR|�tj�� }t�dddi�Wd�n1s20Y|�t|j�d�dS)Nrmrez3(?s)Failed validating '.*' in metaschema.*On schema)r|rr}rr~rr�r�r�rrr�test_schema_error_message�s.�z&TestValidate.test_schema_error_messagecCsddddd�ddigi}|�tj��}t�d|�Wd�n1sD0Y|�dt|j��dS)	Nr
ror(rQrerjrmz!12 is less than the minimum of 20)r|rrrr~r_r�r�)r*rr7rrr�test_it_uses_best_match�s��*z$TestValidate.test_it_uses_best_matchN)
rDr�rEr	rrr
rrrrrrrrrrrjsrc@seZdZdZdd�ZdS)�
TestThreadinga�
    Threading-related functionality tests.

    jsonschema doesn't promise thread safety, and its validation behavior
    across multiple threads may change at any time, but that means it isn't
    safe to share *validators* across threads, not that anytime one has
    multiple threads that jsonschema won't work (it certainly is intended to).

    These tests ensure that this minimal level of functionality continues to
    work.
    csXg��fdd�}|�ddlm}||d�}|��|��|�|���fdgf�dS)Ncs2ztjddd�Wn��t���Yn0dS)Nr�Tr�)rr~r�sys�exc_infor��failedrrr~�szFTestThreading.test_validation_across_a_second_thread.<locals>.validater)�Thread)�targetF)�	threadingr�start�joinr#�is_alive)r*r~r�threadrrr�&test_validation_across_a_second_thread�s
z4TestThreading.test_validation_across_a_second_threadN)rDr�rEr�r"rrrrr�src@seZdZdd�Zdd�ZdS)�TestReferencingcCsJdd�}tj|d�}ddi}tj||d�}|�|�d�|�d�fd	�dS)
NcSst�ddi�S)Nrerl)rZcreate_resource��urirrr�retrieve�sz=TestReferencing.test_registry_with_retrieve.<locals>.retrieve)r&r��https://example.com/��registryrmrr)TF)�referencing�Registryrrzr#r�)r*r&r)rrrrr�test_registry_with_retrieve�s�z+TestReferencing.test_registry_with_retrievec	Cs�t��}ddi}tj||d�}tjdd��R}t�d�|�tjj	��|�
d�Wd�n1sd0YWd�n1s�0Y|�|�dS)Nr�r'r(Tr�r�rm)r*r+rrzr�rrr|rZUnresolvabler~r5)r*r)rrrrrr�;test_custom_registries_do_not_autoretrieve_remote_resources�s
FzKTestReferencing.test_custom_registries_do_not_autoretrieve_remote_resourcesN)rDr�rEr,r-rrrrr#�s
r#c@s�eZdZdZdZddiZdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�TestRefResolverrUzfoo://storedZstoredrcCs.i|_|j|ji|_t�|j|j|j�|_dSr,)�referrer�
stored_uri�
stored_schemarfrri�base_urirhr)rrrr+
	s
�zTestRefResolver.setUpc	Cs�tjjd}tj�|jd��<}|j�|��}Wd�n1s@0YWd�n1s^0Y|�|tjj�|�	|j
�dS)NrPZresolve_remote)rr�r.r
rrprhr�r#r5�called)r*rjZpatched�resolvedrrr�6test_it_does_not_retrieve_schema_urls_from_the_network	s<zFTestRefResolver.test_it_does_not_retrieve_schema_urls_from_the_networkcCsZd}dt�i|jd<|j�|��&}|�||jdd�Wd�n1sL0YdS)Nz#/properties/foorrr)rpr/rhr�r#)r*rjr4rrr�test_it_resolves_local_refs	sz+TestRefResolver.test_it_resolves_local_refscCs�dddid�}tjj|dd�d�}|�d�� }|�||d	�Wd�n1sR0Y|�d
�� }|�||d	�Wd�n1s�0YdS)Nzhttp://bar/schema#rrry)rPrJcSs|�dd�SrTrVr�rrrrZ#	r[zETestRefResolver.test_it_resolves_local_refs_with_id.<locals>.<lambda>�r]z#/arJzhttp://bar/schema#/a)rri�from_schemar�r#�r*rrhr4rrr�#test_it_resolves_local_refs_with_id	s�.z3TestRefResolver.test_it_resolves_local_refs_with_idcCs�|j�|j��}|�||j�Wd�n1s20Yddi|jjd<|j�d��}|�|d�Wd�n1sz0YdS)NrrrmZ
cached_refzcached_ref#/foo)rhr�r0r4r1rfr#)r*r4rrr�test_it_retrieves_stored_refs*	s
,z-TestRefResolver.test_it_retrieves_stored_refscCs|d}ddi}dtjvr.|�tjjdtjd�td|i�tjd<|j�|��}|�|d�Wd�n1sn0YdS)N�http://bar#bazrrm�requests�
http://bar)r�modulesr"�__setitem__�ReallyFakeRequestsrhr�r#)r*rjrr4rrr�,test_it_retrieves_unstored_refs_via_requests2	s
�z<TestRefResolver.test_it_retrieves_unstored_refs_via_requestscs�d}ddi�dtjvr.��tjjdtjd�dtjd<t��fdd��}��ttdtj�|t_�j�	|��}Wd�n1s�0Y��
|d�dS)Nr<rrmr=c3s&��|d�tt����d��VdS)Nr>�utf8)r#r�json�dumps�encode��url�rr*rr�fake_urlopenI	szQTestRefResolver.test_it_retrieves_unstored_refs_via_urlopen.<locals>.fake_urlopen�urlopen)rr?r"r@r�setattrrrKrhr�r#)r*rjrJr4rrIr�+test_it_retrieves_unstored_refs_via_urlopen?	s
�
z;TestRefResolver.test_it_retrieves_unstored_refs_via_urlopencCs�tjddd��0}|�tj|j�t�ddi|�Wd�n1sD0Ydt|j��d�}|j	�
|��}|�|d�Wd�n1s�0YdS)NF�wt)�delete�moderrryzfile://z#foo)�tempfile�NamedTemporaryFiler"�os�remover�rD�dumprrhr�r#)r*Ztempfrjr4rrr�(test_it_retrieves_local_refs_via_urlopenU	s.z8TestRefResolver.test_it_retrieves_local_refs_via_urlopencCsddi}tjj|dd�d�}|�|jd�|�|jd�|�d��}|�||�Wd�n1sd0Y|�d��}|�||�Wd�n1s�0Y|�d��}|�||�Wd�n1s�0Y|�d��}|�||�Wd�n1�s0YdS)	NrPrrcSs|�dd�SrTrVr�rrrrZb	r[zPTestRefResolver.test_it_can_construct_a_base_uri_from_a_schema.<locals>.<lambda>r7rU�#zfoo#�rrir8r#r2Zresolution_scoper�r9rrr�.test_it_can_construct_a_base_uri_from_a_schema^	s�***z>TestRefResolver.test_it_can_construct_a_base_uri_from_a_schemacCs�i}tj�|�}|�|jd�|�|jd�|�d��}|�||�Wd�n1sX0Y|�d��}|�||�Wd�n1s�0YdS)NrUrWrXr9rrr�9test_it_can_construct_a_base_uri_from_a_schema_without_ido	s*zITestRefResolver.test_it_can_construct_a_base_uri_from_a_schema_without_idcsj���fdd�}ddi�d�tjdid|id�}|����}��|��Wd�n1s\0YdS)Ncs��|���Sr,r�rG�rjrr*rr�handlerz	sz@TestRefResolver.test_custom_uri_scheme_handlers.<locals>.handlerrrry�	foo://barrU��handlers)rrir�r#)r*r\rhr4rr[r�test_custom_uri_scheme_handlersy	sz/TestRefResolver.test_custom_uri_scheme_handlerscs�t�g���fdd�}d}tjdidd|id�}|�|��Wd�n1sP0Y|�|��Wd�n1sz0YdS)Ncs,z
���WSty&��d�Yn0dS)Nz#Response must not have been cached!�rC�
IndexErrorrrG��responser*rrr\�	s
z5TestRefResolver.test_cache_remote_on.<locals>.handlerr]rUTrr�Zcache_remoter_�rprrir��r*r\rjrhrrcr�test_cache_remote_on�	s�z$TestRefResolver.test_cache_remote_oncs^t�g���fdd�}d}tjdidd|id�}|�|��Wd�n1sP0YdS)Ncs,z
���WSty&��d�Yn0dS)NzHandler called twice!rarGrcrrr\�	s
z6TestRefResolver.test_cache_remote_off.<locals>.handlerr]rUFrrrerfrgrrcr�test_cache_remote_off�	s�z%TestRefResolver.test_cache_remote_offc	s�td���fdd�}d}tjdid|id�}|�tj��D}|�|��|�d�Wd�n1sd0YWd�n1s�0Y|�|j	t����dS)	NzOh no! What's this?cs��dSr,rrG�rZrrr\�	szTTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_error.<locals>.handlerr]rUrrr^zShouldn't get this far!)
r�rrir|r�_RefResolutionErrorr�rr#r�)r*r\rjrh�errrrjr�3test_if_you_give_it_junk_you_get_a_resolution_error�	sFzCTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_errorcCs^t�di�}|��|�tj��}|��Wd�n1s>0Y|�dt|j��dS)NrUzFailed to pop the scope)	rriZ	pop_scoper|rrkr_r�r�)r*rh�excrrr�.test_helpful_error_message_on_failed_pop_scope�	s
&z>TestRefResolver.test_helpful_error_message_on_failed_pop_scopecCs~tjj}t�d|�}tj||d�}|�|�ddi��ddtjjdigi}t�d|�}tj||d�}|�|�ddi��dS)	z
        See #1085.
        rUrgr�rrZallOfr�rN)rr�r.rir5r�)r*r�onerZanotherZtworrr�,test_pointer_within_schema_with_different_id�	s�z<TestRefResolver.test_pointer_within_schema_with_different_idcsh�fdd�}tjdid|id�}tjitjjd�}ddd	�}|||d
�}��|�i�|�d�fd�d
S)zj
        See https://github.com/python-jsonschema/jsonschema/issues/1061#issuecomment-1624266555.
        cs��|d�ddiS)Nzhttp://example.com/foorerlr�r$r)rr�handle�	szNTestRefResolver.test_newly_created_validator_with_ref_resolver.<locals>.handlerU�httpr^rdzhttp://example.com/barrr)rr�rgr��FTN)rrir'r�r-r#r�)r*rrrhr(rrrr)r�.test_newly_created_validator_with_ref_resolver�	s�
�z>TestRefResolver.test_newly_created_validator_with_ref_resolvercCsXdddiidddiid�}tj|t�d|�d�}|�|�dd	i�|�dd
i�fd�dS)
zj
        See https://github.com/python-jsonschema/jsonschema/issues/1124#issuecomment-1632574249.
        �xr�z#/definitions/xrerl)rrNrUrg�yr�rtN)rrzrir#r�)r*rrrrr�2test_refresolver_with_pointer_in_schema_with_no_id�	s

�
��zBTestRefResolver.test_refresolver_with_pointer_in_schema_with_no_idN)rDr�rEr2r0r1r+r5r6r:r;rBrMrVrYrZr`rhrirmrorqrurxrrrrr.	s*
	

r.cCsdd�}t||d�S)NcSs dd�|jD�dd�|jD�fS)NcSsg|]}t|��qSr�r��rgr7rrrr��	r[z.sorted_errors.<locals>.key.<locals>.<listcomp>cSsg|]}t|��qSrryrzrrrr��	r[)r,r9rjrrr�key�	s�zsorted_errors.<locals>.key)r{)�sorted)rr{rrrr3�	sr3c@seZdZUded<dd�ZdS)rAzdict[str, Any]�
_responsescCs2|j�|�}|dur$tdt|���tt�|��S)Nz
Unknown URL: )r}rWr�rH�_ReallyFakeJSONResponserDrE)r*rHrdrrrrW
szReallyFakeRequests.getN)rDr�rEr�rWrrrrrA�	s
rAc@seZdZUded<dd�ZdS)r~r��	_responsecCst�|j�Sr,)rD�loadsrr)rrrrD
sz_ReallyFakeJSONResponse.jsonN)rDr�rEr�rDrrrrr~	
s
r~):�
__future__r�collectionsrr�
contextlibr�decimalr�ior�typingr�unittestr	r
�urllib.requestrrDrSrrQr��attrsrr
Zreferencing.jsonschemarZreferencing.exceptionsr*Z
jsonschemarrrrrrrr�r&rsrr�r�r�r�r�r�r�r�r�rrr#r.r3rAr~rrrr�<module>sn	8{ aq