o
    3IhW                    @  s4  d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ d d	lZd d	lZd d	lZd d	lZd d	lZd d
lmZmZ d dlmZ d d	lZd dlmZm Z m!Z!m"Z"m#Z# dd Z$G dd deZ%G dd deZ&G dd deZ'G dd dZ(G dd de(Z)G dd dZ*G dd de*e)eZ+G dd de*e)eZ,G dd  d e)eZ-G d!d" d"e)eZ.G d#d$ d$e)eZ/G d%d& d&e)eZ0G d'd( d(eZ1G d)d* d*eZ2G d+d, d,eZ3G d-d. d.eZ4G d/d0 d0eZ5G d1d2 d2eZ6d3d4 Z7eG d5d6 d6Z8eG d7d8 d8Z9d	S )9    )annotations)deque
namedtuple)contextmanager)Decimal)BytesIO)Any)TestCasemock)pathname2urlN)definefield)DRAFT202012)FormatCheckerTypeChecker
exceptions	protocols
validatorsc                 c  s.    |D ]}| dd tjdi |V  qd S )NmessagezYou told me to fail! )
setdefaultr   ValidationError)	validatorerrorsinstanceschemaeachr   r   `/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/jsonschema/tests/test_validators.pyfail   s
   r   c                   @     e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)S )*TestCreateAndExtendc                 C  sh   |  | jtjttj |  | jtjttj ddi| _dti| _t | _	tj
| j| j| j	d| _d S )N$idzsome://meta/schemar   )meta_schemar   type_checker)
addCleanupassertEqualr   _META_SCHEMASdict_VALIDATORSr"   r   r   r#   create	Validatorselfr   r   r   setUp$   s$   

zTestCreateAndExtend.setUpc                 C  s.   |  | jj| jj| jjf| j| j| jf d S N)r%   r*   
VALIDATORSMETA_SCHEMATYPE_CHECKERr   r"   r#   r+   r   r   r   
test_attrs9   s   zTestCreateAndExtend.test_attrsc                 C  s    dg i}|  | |j| d S )Nr   )r%   r*   r   r,   r   r   r   r   	test_initF   s   zTestCreateAndExtend.test_initc                 C  s0   dg i}|  |}t|d}| |g  d S )Nr   hello)r*   listiter_errorsr%   r,   r   r   r   r   r   r   test_iter_errors_successfulJ   s   
z/TestCreateAndExtend.test_iter_errors_successfulc                 C  st   dddigi}|  |}tjdd|dddigtdgd}t|d}| t|d | |d  |  d S )Nr   r   zWhoops!goodbye)r   r   r   validator_valueschema_path   r   )	r*   r   r   r   r6   r7   r%   len	_contents)r,   r   r   expected_errorr   r   r   r   test_iter_errors_one_errorQ   s   
	z.TestCreateAndExtend.test_iter_errors_one_errorc                 C  sH   dddidddddigi}|  |}t|d}| t|d	 d S )
Nr   r   FirstzSecond!asdf)r   r   Thirdr:      )r*   r6   r7   r%   r>   r8   r   r   r    test_iter_errors_multiple_errorsb   s   
z4TestCreateAndExtend.test_iter_errors_multiple_errorsc                 C  sR   t jddidd}| t jjd | t jjd | |jd | |jd d S )Nr!   	something
my versionr"   versionMyVersionValidator)	r   r)   r$   r&   popr(   r%   __name____qualname__r,   r*   r   r   r   .test_if_a_version_is_provided_it_is_registeredo   s   zBTestCreateAndExtend.test_if_a_version_is_provided_it_is_registeredc                 C  sJ   t jddidd}| t jjd | t jjd | t|i d d S )Nr!   rG   rH   rI   z2MyVersionValidator(schema={}, format_checker=None))r   r)   r$   r&   rL   r(   r%   reprrO   r   r   r   	test_repry   s   
zTestCreateAndExtend.test_reprc                 C  sV   t jddidd}| t jjd | t jjd | t|dtt	did d S )Nr!   rG   rH   rI   ai  zNMyVersionValidator(schema={'a': [0, 1, 2, 3, 4, 5, ...]}, format_checker=None))
r   r)   r$   r&   rL   r(   r%   rQ   r6   rangerO   r   r   r   test_long_repr   s   z"TestCreateAndExtend.test_long_reprc                 C  s$   t ji d}| t|i d d S )Nr"   z)Validator(schema={}, format_checker=None))r   r)   r%   rQ   rO   r   r   r   test_repr_no_version   s
   
z(TestCreateAndExtend.test_repr_no_versionc                 C  sD   t jddidd}| t jjd | t jjd | |jd d S )Nr!   rG   zfoo-barrI   FooBarValidator)r   r)   r$   r&   rL   r(   r%   rN   rO   r   r   r   -test_dashes_are_stripped_from_validator_names   s   zATestCreateAndExtend.test_dashes_are_stripped_from_validator_namesc                 C  s,   t tj}tjddid | tj| d S )NidrV   )r'   r   r&   r)   r%   )r,   originalr   r   r   6test_if_a_version_is_not_provided_it_is_not_registered   s   
zJTestCreateAndExtend.test_if_a_version_is_not_provided_it_is_not_registeredc                 C  sR   d}d|i}t j|ddd d | t jj| | t jjd | |t j d S )Nmeta schema idrZ   rH   c                 S     |  ddS NrZ    getsr   r   r   <lambda>       zMTestCreateAndExtend.test_validates_registers_meta_schema_id.<locals>.<lambda>r"   rJ   id_ofr   r)   r$   r&   rL   r(   assertInr,   meta_schema_keymy_meta_schemar   r   r   'test_validates_registers_meta_schema_id   s   z;TestCreateAndExtend.test_validates_registers_meta_schema_idc                 C  sL   d}d|i}t j|dd | t jj| | t jjd | |t j d S )Nmeta schema $idr!   rH   rI   ri   rk   r   r   r   .test_validates_registers_meta_schema_draft6_id   s   zBTestCreateAndExtend.test_validates_registers_meta_schema_draft6_idc                   sD   t ji dd | t fdddg fdddd	d
i fdfD  d S )Nr   r"   r   c                 3  s&    | ]\}} i j ||d V  qdS ))r   typeN)is_type).0rr   r   r*   r   r   	<genexpr>   s
    
z@TestCreateAndExtend.test_create_default_types.<locals>.<genexpr>array)booleanT)integer   )nullN)numberg      (@object)stringfoo)r   r)   
assertTrueallr+   r   ru   r   test_create_default_types   s   z-TestCreateAndExtend.test_create_default_typesc                 C  sx   t jt jjd di idd}|ddi | tj |i  W d   n1 s,w   Y  |ddid dS )zq
        One can create a validator class whose metaschema uses a different
        dialect than itself.
        r!   const)$schemanotrV   r   barN)	r   r)   Draft202012Validatorr0   check_schemaassertRaisesr   SchemaErrorvalidater,   NoEmptySchemasValidatorr   r   r   +test_check_schema_with_different_metaschema   s   
z?TestCreateAndExtend.test_check_schema_with_different_metaschemac                 C  sX   t jdddigidtid}| tj |i  W d   dS 1 s%w   Y  dS )z
        A validator whose metaschema doesn't declare $schema defaults to its
        own validation behavior, not the latest "normal" specification.
        r   r   zMeta schema whoops!rq   N)r   r)   r   r   r   r   r   r   r   r   r   <test_check_schema_with_different_metaschema_defaults_to_self   s   "zPTestCreateAndExtend.test_check_schema_with_different_metaschema_defaults_to_selfc                 C  s`   t | jj}t }tj| jd|id}| |j|j|j| jjft ||d| jj| jj|f d S )Nnew)r   )r   )	r'   r*   r/   r}   r   extendr%   r0   r1   )r,   r[   r   Extendedr   r   r   test_extend   s$   
zTestCreateAndExtend.test_extendc                   sf    fdd}d}d|d}t j| j  j|d} ||j| t |} ||j| dS )zK
        Extending a validator preserves its notion of schema IDs.
        c                   s   |  d j| S )N__test__)rb   r*   ID_OFr   r+   r   r   rh        z3TestCreateAndExtend.test_extend_idof.<locals>.id_ofzthe://correct/id/zthe://wrong/id/)r!   r   )r"   r   r#   rh   N)r   r)   r#   r%   r   r0   r   )r,   rh   
correct_idr"   OriginalDerivedr   r+   r   test_extend_idof
  s   
z$TestCreateAndExtend.test_extend_idofc                 C  sR   dddiiddd}t |}| |d t t j}| ||d dS )	zV
        Extending a validator preserves its notion of applicable validators.
        testrr   r|   z#/$defs/testr=   )$defs$refmaximum%   N)r   Draft4Validatorr   is_validr   )r,   r   draft4r   r   r   r   !test_extend_applicable_validators   s   

z5TestCreateAndExtend.test_extend_applicable_validatorsN)rM   
__module__rN   r-   r2   r4   r9   rA   rF   rP   rR   rU   rW   rY   r\   rn   rp   r   r   r   r   r   r   r   r   r   r   r    #   s*    
	r    c                   @  s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;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TestValidationErrorMessagesc                 O  st   | dtj}|| ||g|R i |}t||}| j|d|d | jt|dd|d |d j	S )NclszNo errors were raised for )msgr=   z"Expected exactly one error, found r   )
rL   r   _LATEST_VERSIONr   r6   r7   r   r%   r>   r   )r,   r   r   argskwargsr   r   r   r   r   r   message_for3  s   

z'TestValidationErrorMessages.message_forc                 C  "   | j dddid}| |d d S Nr=   rr   r~   r   r   1 is not of type 'string'r   r%   r,   r   r   r   r   test_single_type_failure@     z4TestValidationErrorMessages.test_single_type_failurec                 C  s$   | j dddgid}| |d d S r   r   r   r   r   r   test_single_type_list_failureD     z9TestValidationErrorMessages.test_single_type_list_failurec                 C  s*   d}| j ddt|id}| |d d S )N)r~   r}   r=   rr   r   z#1 is not of type 'string', 'object')r   r6   r%   )r,   typesr   r   r   r   test_multiple_type_failureH  s   z6TestValidationErrorMessages.test_multiple_type_failurec                 C  s2   ddddgi}| j d|tjd}| |d d S )Nrr   FoorE   )nameminimumr=   r   r   r   z1 is not of type 'Foo'r   r   Draft3Validatorr%   r,   r   r   r   r   r   #test_object_with_named_type_failureM  s   z?TestValidationErrorMessages.test_object_with_named_type_failurec                 C  r   )Nr=   r      r   z1 is less than the minimum of 2r   r   r   r   r   test_minimumV  r   z(TestValidationErrorMessages.test_minimumc                 C  r   )Nr=   r   r   r   z"1 is greater than the maximum of 0r   r   r   r   r   test_maximumZ  r   z(TestValidationErrorMessages.test_maximumc                 C  s:   d\}}d||ii}| j ddi|tjd}| |d d S Nr   r   dependenciesr   r   r   z'foo' is a dependency of 'bar'r   r,   dependonr   r   r   r   r    test_dependencies_single_element^  s   z<TestValidationErrorMessages.test_dependencies_single_elementc                 C  s6   dddigi}| j dd|gitjd}| |d d S )Nrr   r   rE   r=   r   z+1 is not of type {'type': [{'minimum': 3}]}r   )r,   rr   r   r   r   r   -test_object_without_title_type_failure_draft3h  s   zITestValidationErrorMessages.test_object_without_title_type_failure_draft3c                 C  <   d\}}d||gii}| j ddi|tjd}| |d d S r   r   r   r   r   r   test_dependencies_list_draft3t     z9TestValidationErrorMessages.test_dependencies_list_draft3c                 C  r   r   r   r   Draft7Validatorr%   r   r   r   r   test_dependencies_list_draft7~  r   z9TestValidationErrorMessages.test_dependencies_list_draft7c                 C  s*   | j dgg ddtjd}| d| d S )Nr   FitemsadditionalItemsr   z(2 was unexpected)r   r   r   rj   r   r   r   r   #test_additionalItems_single_failure  s   z?TestValidationErrorMessages.test_additionalItems_single_failurec                 C  s,   | j g dg ddtjd}| d| d S )Nr=   r   rE   Fr   r   z(1, 2, 3 were unexpected)r   r   r   r   r   &test_additionalItems_multiple_failures  s   zBTestValidationErrorMessages.test_additionalItems_multiple_failuresc                 C  s.   d}ddi}| j |di|d}| d| d S )Nr   additionalPropertiesFr   r   z('foo' was unexpected)r   rj   )r,   
additionalr   r   r   r   r   (test_additionalProperties_single_failure  s   zDTestValidationErrorMessages.test_additionalProperties_single_failurec                 C  sP   ddi}| j tddg|d}| td| | td| | d| d S )Nr   Fr   r   r   zwere unexpected))r   r'   fromkeysrj   rQ   r   r   r   r   +test_additionalProperties_multiple_failures  s   zGTestValidationErrorMessages.test_additionalProperties_multiple_failuresc                 C  s*   ddi}| j ddi|d}| d| d S )Nr   rz   r   r   r   z12 was expectedr   r   r   r   r   
test_const  s   z&TestValidationErrorMessages.test_constc                 C  s4   dddii}| j di g g|tjd}| |d d S )Ncontainsr   rz   r   r   z4None of [2, {}, []] are valid under the given schema)r   r   Draft6Validatorr%   r   r   r   r   test_contains_draft_6  s   z1TestValidationErrorMessages.test_contains_draft_6c                 C  sd   t dd}|ddd  ddi}| jd||d}| td| | td| | d	| d S )
Nr   )formatsthingc                 S  s   dS NFr   valuer   r   r   re     s    zQTestValidationErrorMessages.test_invalid_format_default_message.<locals>.<lambda>formatbla)r   r   format_checkerzis not a)r   checksr   rj   rQ   )r,   checkerr   r   r   r   r   #test_invalid_format_default_message  s   
z?TestValidationErrorMessages.test_invalid_format_default_messagec              
   C  s   ddddiddidd}| j ddi|tjd	}| |d
tdtdtd | j ddd|tjd	}| |dtdtdtdtd d S )Nr}   Frr   r~   )^abc$^def$)rr   r   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   r   r   r%   r   rQ   r   r   r   r   1test_additionalProperties_false_patternProperties  s8   zMTestValidationErrorMessages.test_additionalProperties_false_patternPropertiesc                 C  s   | j ddd}| |d d S )NrG   Fr   z'False schema does not allow 'something'r   r   r   r   r   test_False_schema  s
   z-TestValidationErrorMessages.test_False_schemac                 C  r   )NrE   
multipleOfr   r   z3 is not a multiple of 2r   r   r   r   r   test_multipleOf  
   z+TestValidationErrorMessages.test_multipleOfc                 C  "   | j g ddid}| |d d S )NminItemsr   r   z[] is too shortr   r   r   r   r   test_minItems  r   z)TestValidationErrorMessages.test_minItemsc                 C  &   | j g dddid}| |d d S )Nr   maxItemsr   r   z[1, 2, 3] is too longr   r   r   r   r   test_maxItems     z)TestValidationErrorMessages.test_maxItemsc                 C  r   )Nr   r=   r   z[] should be non-emptyr   r   r   r   r   test_minItems_1   r   z+TestValidationErrorMessages.test_minItems_1c                 C  r   )Nr   r   r   r   z![1, 2, 3] is expected to be emptyr   r   r   r   r   test_maxItems_0  r   z+TestValidationErrorMessages.test_maxItems_0c                 C  r   )Nr`   	minLengthr   r   z'' is too shortr   r   r   r   r   test_minLength  r   z*TestValidationErrorMessages.test_minLengthc                 C  r   )Nabc	maxLengthr   r   z'abc' is too longr   r   r   r   r   test_maxLength  r   z*TestValidationErrorMessages.test_maxLengthc                 C  r   )Nr`   r  r=   r   z'' should be non-emptyr   r   r   r   r   test_minLength_1  r   z,TestValidationErrorMessages.test_minLength_1c                 C  r   )Nr  r  r   r   z'abc' is expected to be emptyr   r   r   r   r   test_maxLength_0  r   z,TestValidationErrorMessages.test_maxLength_0c                 C  "   | j i ddid}| |d d S )NminPropertiesr   r   z"{} does not have enough propertiesr   r   r   r   r   test_minProperties  r   z.TestValidationErrorMessages.test_minPropertiesc                 C  s*   | j i i i dddid}| |d d S )N)rS   bcmaxPropertiesr   r   z3{'a': {}, 'b': {}, 'c': {}} has too many propertiesr   r   r   r   r   test_maxProperties"  s   
z.TestValidationErrorMessages.test_maxPropertiesc                 C  r	  )Nr
  r=   r   z{} should be non-emptyr   r   r   r   r   test_minProperties_1,  r   z0TestValidationErrorMessages.test_minProperties_1c                 C  s&   | j ddiddid}| |d d S )Nr=   r   r  r   r   z{1: 2} is expected to be emptyr   r   r   r   r   test_maxProperties_00  s
   z0TestValidationErrorMessages.test_maxProperties_0c                 C  ,   | j g ddi i gdd}| |d d S )N)r=   r   r   Fr   prefixItemsr   z1Expected at most 2 items but found 1 extra: 'foo'r   r   r   r   r   test_prefixItems_with_items7     z7TestValidationErrorMessages.test_prefixItems_with_itemsc                 C  r  )Nr=   r   r      Fr  r   z6Expected at most 2 items but found 2 extra: ['foo', 5]r   r   r   r   r   *test_prefixItems_with_multiple_extra_itemsA  r  zFTestValidationErrorMessages.test_prefixItems_with_multiple_extra_itemsc                 C  r   )Nbbbpatternz^a*$r   z'bbb' does not match '^a*$'r   r   r   r   r   test_patternK  r   z(TestValidationErrorMessages.test_patternc                 C  s&   | j g dddiid}| |d d S )Nr   rr   r~   r   z3[] does not contain items matching the given schemar   r   r   r   r   test_does_not_containR  s   
z1TestValidationErrorMessages.test_does_not_containc                 C  s,   | j ddgddiddd}| |d d S )	Nr   r=   rr   r~   r   r   minContainsr   MToo few items match the given schema (expected at least 2 but only 1 matched)r   r   r   r   r   test_contains_too_few\  r  z1TestValidationErrorMessages.test_contains_too_fewc                 C  s.   | j ddgddidddd}| |d	 d S )
Nr   r=   rr   r~   r      r   r  maxContainsr   r   r   r   r   r   r   &test_contains_too_few_both_constrainedg  s   zBTestValidationErrorMessages.test_contains_too_few_both_constrainedc                 C  s,   | j g dddiddd}| |d d S )Nr   r   bazrr   r~   r   r   r$  r   :Too many items match the given schema (expected at most 2)r   r   r   r   r   test_contains_too_manyv  r  z2TestValidationErrorMessages.test_contains_too_manyc                 C  s0   | j dgd ddidddd}| |d	 d S )
Nr   r  rr   r~   r   r"  r#  r   z:Too many items match the given schema (expected at most 4)r   r   r   r   r   'test_contains_too_many_both_constrained  s   zCTestValidationErrorMessages.test_contains_too_many_both_constrainedc                 C  r   )NrE   exclusiveMinimumr  r   z+3 is less than or equal to the minimum of 5r   r   r   r   r   test_exclusiveMinimum  s   z1TestValidationErrorMessages.test_exclusiveMinimumc                 C  r   )NrE   exclusiveMaximumr   r   z.3 is greater than or equal to the maximum of 2r   r   r   r   r   test_exclusiveMaximum  s
   z1TestValidationErrorMessages.test_exclusiveMaximumc                 C  $   | j i ddgid}| |d d S )Nrequiredr   r   z'foo' is a required propertyr   r   r   r   r   test_required  r   z)TestValidationErrorMessages.test_requiredc                 C  s,   | j di idddgiid}| |d d S )Nr   dependentRequiredr   r   z'bar' is a dependency of 'foo'r   r   r   r   r   test_dependentRequired  s
   z2TestValidationErrorMessages.test_dependentRequiredc                 C  r0  )NoneOfFr   z.{} is not valid under any of the given schemasr   r   r   r   r   test_oneOf_matches_none  s
   z3TestValidationErrorMessages.test_oneOf_matches_nonec                 C  s&   | j i dddgid}| |d d S )Nr5  Tr   z${} is valid under each of True, Truer   r   r   r   r   test_oneOf_matches_too_many  r   z7TestValidationErrorMessages.test_oneOf_matches_too_manyc                 C  s,   ddd}| j ddg|d}| |d d S )Nrw   Frr   unevaluatedItemsr   r   r   z@Unevaluated items are not allowed ('foo', 'bar' were unexpected)r   r   r   r   r   test_unevaluated_items  s   
z2TestValidationErrorMessages.test_unevaluated_itemsc                 C  (   ddd}| j d|d}| |d d S )Nrw   Fr8  r   r   z'foo' is not of type 'array'r   r   r   r   r   &test_unevaluated_items_on_invalid_type     
zBTestValidationErrorMessages.test_unevaluated_items_on_invalid_typec                 C  s<   dddiiddid}| j dddd|d	}| |d
 d S )Nr   rr   r~   r   rz   
propertiesunevaluatedPropertiesr   r&  r   z_Unevaluated properties are not valid under the given schema ('bar' was unevaluated and invalid)r   r   r   r   r   5test_unevaluated_properties_invalid_against_subschema  s   
zQTestValidationErrorMessages.test_unevaluated_properties_invalid_against_subschemac                 C  s.   ddd}| j ddd|d}| |d d S )	Nr}   Frr   r@  r   r   r   r   r   zEUnevaluated properties are not allowed ('bar', 'foo' were unexpected)r   r   r   r   r   &test_unevaluated_properties_disallowed  s   
zBTestValidationErrorMessages.test_unevaluated_properties_disallowedc                 C  r;  )Nr}   FrB  r   r   z'foo' is not of type 'object'r   r   r   r   r   +test_unevaluated_properties_on_invalid_type  r=  zGTestValidationErrorMessages.test_unevaluated_properties_on_invalid_typec                 C  .   i gdd}| j g d|d}| |d d S )NFr  r   r&  r   z9Expected at most 1 item but found 2 extra: ['bar', 'baz']r   r   r   r   r   test_single_item     z,TestValidationErrorMessages.test_single_itemc                 C  s2   i gdd}| j g d|tjd}| |d d S )NFr   r   r   r   r   z<Additional items are not allowed ('bar', 37 were unexpected)r   r   r   r   r   -test_heterogeneous_additionalItems_with_Items  s   zITestValidationErrorMessages.test_heterogeneous_additionalItems_with_Itemsc                 C  rF  )NFrG  rJ  r   z6Expected at most 1 item but found 2 extra: ['bar', 37]r   r   r   r   r   $test_heterogeneous_items_prefixItems   rI  z@TestValidationErrorMessages.test_heterogeneous_items_prefixItemsc                 C  rF  )NF)r  r9  rJ  r   z=Unevaluated items are not allowed ('bar', 37 were unexpected)r   r   r   r   r   /test_heterogeneous_unevaluatedItems_prefixItems  rI  zKTestValidationErrorMessages.test_heterogeneous_unevaluatedItems_prefixItemsc                 C  4   di idd}| j i ddd|d}| |d d	S )
K
        Not valid deserialized JSON, but this should not blow up.
        r   F)r?  r   r'  rz   r   rS   r   r   z?Additional properties are not allowed (37, 'a' were unexpected)Nr   r   r   r   r   2test_heterogeneous_properties_additionalProperties     
zNTestValidationErrorMessages.test_heterogeneous_properties_additionalPropertiesc                 C  rN  )
rO  r   Fr>  r'  rz   rP  r   z@Unevaluated properties are not allowed (37, 'a' were unexpected)Nr   r   r   r   r   3test_heterogeneous_properties_unevaluatedProperties$  rR  zOTestValidationErrorMessages.test_heterogeneous_properties_unevaluatedPropertiesN)=rM   r   rN   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  r!  r%  r*  r+  r-  r/  r2  r4  r6  r7  r:  r<  rA  rD  rE  rH  rK  rL  rM  rQ  rS  r   r   r   r   r   2  sv    	








r   c                   @  r   )*TestValidationErrorDetailsc                 C  s  d}dddiddigi}t |}t||}| t|d |d }| |jd | |j|d  | |j| | |j	| | 
|j | |jtg  | |jtg  | |jtg  | |jd	 | |jtdg | |jtdg | |jtdg | t|jd
 t|j\}}| |jd | |j|d d d  | |j| | |j	|d d  | |j| | |jtg  | |jtg  | |jtg  | |jd	 | |jtddg | |jtddg | |jtg d | |j | |jd | |j|d d d  | |j| | |j	|d d  | |j| | |jtg  | |jtg  | |jtg  | |jd	 | |jtddg | |jtddg | |jtg d | t|jd d S )Nr  anyOfr      rr   r~   r=   r   $r   )rU  r   r   )rU  r=   rr   )r   r   r6   r7   r%   r>   r   r;   r   r   assertIsNoneparentpathr   relative_pathabsolute_path	json_pathr<   relative_schema_pathabsolute_schema_pathcontextsorted_errorsassertIsassertFalser,   r   r   r   r   ee1e2r   r   r   
test_anyOf6  sh   
z%TestValidationErrorDetails.test_anyOfc                 C  s  ddi}dddiddddgiidgi}t |}t||}| t|d |d	 }| |jd | |j|d  | |j| | |j	| | 
|j | |jtg  | |jtg  | |jtg  | |jd
 | |jtdg | |jtdg | |jtdg | t|jd t|j\}}| |jd | |j|d d	 d  | |j| | |j	|d d	  | |j| | |jtg  | |jtg  | |jtg  | |jd
 | |jtd	dg | |jtd	dg | |jtg d | |j | |jd | |jdg | |jd | |j	ddgi | |j| | |jtdg | |jtdg | |jtdg | |jd | |jtg d | |jtg d | |jtg d | |j d S )Nr   r=   rr   ry   r}   enumr   rr   r?  r   rW  )rr   r   rr   $.foo)r=   r?  r   ri  )rr   r=   r?  r   ri  )r   r   r6   r7   r%   r>   r   r;   r   r   rX  rY  rZ  r   r[  r\  r]  r<   r^  r_  r`  ra  rb  rc  rd  r   r   r   	test_type{  sv   


z$TestValidationErrorDetails.test_typec           	      C  s  ddgddd}dddid	did
g dddi}t |}||}t|\}}}}| |jtdg | |jtdg | |jtdg | |jtdg | |jtdg | |jtdg | |jtdg | |jtdg | |jtdg | |jtdg | |jtdg | |jtdg | |j	d | |j	d | |j	d | |j	d | |j
d	 | |j
d | |j
d | |j
d d S )Nr   r=      spam)r   r   r'  quuxr?  rr   r~   r   
   )r   r"        )r   ri  r&  r   r'  r   $.barz$.bazrk  ri  r   )r   r   r7   ra  r%   rZ  r   r[  r\  r]  r   )	r,   r   r   r   r   rf  rg  e3e4r   r   r   test_single_nesting  s<   

z.TestValidationErrorDetails.test_single_nestingc                 C  s   ddddgiddg}dddgddd	gid
ddiddiddddd}t |}||}t|\}}}}}	}
| |jtg  | |jtdg | |jtddg | |jtg d | |	jtg d | |
jtddg | |jd | |jd | |jd | |jd | |	jd | |
jd | |jtdg | |jtddg | t	|jg d | t	|jg d | t	|	jg d  | t	|
jg d! | |j
d | |j
d | |j
d | |j
d | |	j
d | |
j
d d S )"Nr=   r   r'  rC  ro  r~   r}   ri  rE   rw   r1  Tr   )r   r'  rj  )rr   r   r   r   )r=   r   r   )r=   r   r'  r   rW  $[0]z$[1].barz$[1].bar.barz$[1].bar.bazz$[1].foorr   r   )r   r?  r   rr   )r   r?  r   r?  r   r1  )r   r?  r   r?  r'  r   )r   r?  r   ri  )r   r   r7   ra  r%   rZ  r   r]  r<   r6   r   )r,   r   r   r   r   rf  rg  rt  ru  e5e6r   r   r   test_multiple_nesting  sb   


z0TestValidationErrorDetails.test_multiple_nestingc              	   C  s<  dddddgddiddd	d
iidddgiiddgdd	d
iid}dddddddiididi}t |}||\}| |jtdg | |jtg d | |jd |j\}| |jtg d | |jtg d | |jd |j\}| |jtg d | |jtg d | |jd d S )NnoderU  r}   r   childrenrr   r~   ^.*$r   z#/definitions/node)rr   r   )r   r|  )rr   r1  r?  root)definitionsrr   r1  r?  rS   ab)r?  r~  rU  z$.root)r~  r|  rS   )	r?  r~  rU  r   r?  r|  r   r}  rU  z$.root.children.a)r~  r|  rS   r|  r  )r?  r~  rU  r   r?  r|  r   r}  rU  r   r?  r|  r   r}  rU  z$.root.children.a.children.ab)	r   r   r7   r%   r\  r   r_  r]  r`  )r,   r   r   r   re  rf  rg  r   r   r   test_recursive,  sv   

z)TestValidationErrorDetails.test_recursivec                 C  s   ddd}ddddi}t |}||}t|\}}| |jtdg | |jtdg | |jd	 | |jd
 | |jd | |jd d S )Nr   r   r   r   ry   r  rr   r   r   rs  rk  rr   r   	r   r   r7   ra  r%   rZ  r   r]  r   r,   r   r   r   r   rf  rg  r   r   r   test_additionalProperties  s   


z4TestValidationErrorDetails.test_additionalPropertiesc                 C  s   ddd}dddiddidi}t |}||}t|\}}| |jtd	g | |jtd
g | |jd | |jd | |jd | |jd d S )Nr=   r   r   r   rr   r~   r   r  r   r   rs  rk  r  r  r   r   r   test_patternProperties  s   


z1TestValidationErrorDetails.test_patternPropertiesc                 C  s   ddg}g dddd}t |}||}t|\}}| |jtdg | |jtdg | |jd | |jd	 | |jd
 | |jd d S )Nr   r=   ry   r  r  r   r   rw  $[1]rr   r   r  r  r   r   r   test_additionalItems  s   

z/TestValidationErrorDetails.test_additionalItemsc                 C  s   g d}i gdddd}t |}||}t|\}}| |jtdg | |jtdg | |jd | |jd	 | |jd
 | |jd d S )N)r   r   r=   ry   r  r  r   r=   r   r  z$[2]rr   r   r  r  r   r   r   test_additionalItems_with_items  s   

z:TestValidationErrorDetails.test_additionalItems_with_itemsc                 C  s   ddi}ddddiii}t |}||\}| |jd | |jd | |jtg  | |jd | |j	tddg d S )Nr   rz   propertyNamesr   r   z0'foo' should not be valid under {'const': 'foo'}rW  
r   r   r7   r%   r   r   rZ  r   r]  r<   )r,   r   r   r   errorr   r   r   test_propertyNames  s   
z-TestValidationErrorDetails.test_propertyNamesc                 C  s~   ddiddid}t |}|d\}| |jd | |jd | |jtg  | |jd | |j	tddg d S )Nr   rz      )ifthen13 was expectedrW  r  r  r,   r   r   r  r   r   r   test_if_then     
z'TestValidationErrorDetails.test_if_thenc                 C  s~   ddiddid}t |}|d\}| |jd | |jd | |jtg  | |jd | |j	tddg d S )	Nr   rz   r  )r  elserm  r  rW  r  r  r  r   r   r   test_if_else  r  z'TestValidationErrorDetails.test_if_elsec              
   C  sT   t d}|d\}| |j|j|j|j|j|j	|j
fdd d ddtg df d S )NFrz   zFalse schema does not allow 12rW  )r   r   r7   r%   r   r   r;   r   r   r<   r]  r   )r,   r   r  r   r   r   test_boolean_schema_False  s(   

z4TestValidationErrorDetails.test_boolean_schema_Falsec                 C  s   ddddii}}t jd|it jdi ||idd}|d	d
i\}| |j|j|j|j|j	|j
|j|jfdddd
td	gdditddgdf d S )NsomeRefr   rr   ry   r   r`   storeresolverr   notAnIntegerz''notAnInteger' is not of type 'integer'rk  )r   r   _RefResolverr7   r%   r   r   r;   r   r\  r   r<   r]  r   )r,   refr   r   r  r   r   r   test_ref'  s4   
z#TestValidationErrorDetails.test_refc                 C  s   dddii i ddigi}t |}|g d\}}| |j|j|j|j|j|j	|j
|jfddddtd	gdditg d
df | |j|j|j|j|j|j	|j
|jfddddtdgdditg ddf d S )Nr  rr   r~   r   rE   r  r   r=   r   )r  r   rr   rw  z"5 is greater than the maximum of 3r  )r  rE   r   $[3]r   r   r7   r%   r   r   r;   r   r\  r   r<   r]  r   )r,   r   r   
type_error	min_errorr   r   r   test_prefixItemsF  sV   


z+TestValidationErrorDetails.test_prefixItemsc                 C  s   ddii gd}t |}|g d\}}| |j|j|j|j|j|j	|j
|jfddddtdgdditddgd	f | |j|j|j|j|j|j	|j
|jfd
dddtdgdditddgdf d S )Nrr   r~   r  )r   r   r   r"  r'  z2 is not of type 'string'r   r=   r   r  z4 is not of type 'string'r"  rE   r  r  r,   r   r   rf  rg  r   r   r   r  w  sZ   


z6TestValidationErrorDetails.test_prefixItems_with_itemsc                 C  s   ddidd}t |}|g d\}| |j|j|j|j|j|j	|j
|jfdddg dtg ddiddtdgd	f d
S )z
        `contains` + `maxContains` produces only one error, even if there are
        many more incorrectly matching elements.
        rr   r~   r   r(  )r   r   r   r"  r'  ro  r)  r$  r   rW  Nr  r  r   r   r   r*    s.   
z1TestValidationErrorDetails.test_contains_too_manyc                 C  s   ddidd}t |}|g d\}| |j|j|j|j|j|j	|j
|jfdddg dtg ddiddtdgd	f d S )
Nrr   r~   r   r  )r   r   r"  r   r  r   rW  r  r  r   r   r   r!    s.   
z0TestValidationErrorDetails.test_contains_too_fewc                 C  s   ddidd}t |}|ddg\}| |j|j|j|j|j|j	|j
|jfddddiddgtg ddiddtdgdf d S )	Nrr   r~   r   r  r"  z7[2, 4] does not contain items matching the given schemar   rW  r  r  r   r   r   test_contains_none  s.   
z-TestValidationErrorDetails.test_contains_nonec                 C  s  dddgiidddgdid}t |}|di i\}}| |j|j|j|j|j|j	|j
|j|jf	d	ddgi tdgddgitg d
tg d
df	 | |j|j|j|j|j|j	|j
|j|jf	dddgi tdgddgdtg d
tg d
df	 d S )Nr   r1  r   apropz#/$defs/foor'  )r   r1  )r   r?  z'bar' is a required property)r?  r  r1  z$.apropz'baz' is a required property)r   r   r7   r%   r   r   r;   r   r\  r   r<   r^  r]  r   r  r   r   r   test_ref_sibling  sj   






z+TestValidationErrorDetails.test_ref_siblingN)rM   r   rN   rh  rl  rv  rz  r  r  r  r  r  r  r  r  r  r  r  r  r*  r!  r  r  r   r   r   r   rT  3  s*    EM'=e14rT  c                   @  s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )MetaSchemaTestsMixinc                 C  B   |  tj | jddi W d    d S 1 sw   Y  d S )Nr?  rz   r   r   r   r*   r   r+   r   r   r   test_invalid_propertiesD     "z,MetaSchemaTestsMixin.test_invalid_propertiesc                 C  r  )Nr   1r  r+   r   r   r   test_minItems_invalid_stringH  s   "z1MetaSchemaTestsMixin.test_minItems_invalid_stringc                 C  sh   | j tjtjhv r*| tj | j dg i W d   dS 1 s#w   Y  dS | j dg i dS )z
        Technically, all the spec says is they SHOULD have elements, not MUST.

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

        See #529.
        ri  Nr*   r   r   r   r   r   r   r   r+   r   r   r   test_enum_allows_empty_arraysM  s   "z2MetaSchemaTestsMixin.test_enum_allows_empty_arraysc                 C  sp   | j tjtjhv r,| tj | j dddgi W d   dS 1 s%w   Y  dS | j dddgi dS )z
        Technically, all the spec says is they SHOULD be unique, not MUST.

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

        See #529.
        ri  rz   Nr  r+   r   r   r   !test_enum_allows_non_unique_items^  s   "z6MetaSchemaTestsMixin.test_enum_allows_non_unique_itemsc                 C  r  )Nr  
*notaregexr  r+   r   r   r   test_schema_with_invalid_regexo  r  z3MetaSchemaTestsMixin.test_schema_with_invalid_regexc                 C  s   | j jddid d d S )Nr  r  r   )r*   r   r+   r   r   r   >test_schema_with_invalid_regex_with_disabled_format_validations  s   
zSMetaSchemaTestsMixin.test_schema_with_invalid_regex_with_disabled_format_validationN)	rM   r   rN   r  r  r  r  r  r  r   r   r   r   r  B  s    r  c                   @  s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'S )(ValidatorTestMixinc                 C  s   |  | i tj d S r.   )assertIsInstancer*   r   r+   r   r   r   )test_it_implements_the_validator_protocol{     z<ValidatorTestMixin.test_it_implements_the_validator_protocolc                 C  $   | j \}}| | || d S r.   )validr   r*   r   r,   r   r   r   r   r   test_valid_instances_are_valid~     
z1ValidatorTestMixin.test_valid_instances_are_validc                 C  r  r.   )invalidrc  r*   r   r  r   r   r   $test_invalid_instances_are_not_valid  r  z7ValidatorTestMixin.test_invalid_instances_are_not_validc                 C  s    |  t t ijt d d S )Nr   )r*   r}   r   r+   r   r   r   (test_non_existent_properties_are_ignored      z;ValidatorTestMixin.test_non_existent_properties_are_ignoredc                 C  sj   ddit  }}| j||d}|jddi| jjd}| jddi| jj|jd}| || | || d S )Nrr   ry   r  r~   )r   r   )r   	_resolver)r   r*   evolveFORMAT_CHECKERr  r%   assertNotEqual)r,   r   r   r[   r   expectedr   r   r   test_evolve  s    zValidatorTestMixin.test_evolvec                 C  s   |  t tG dd d| j}W d   n1 sw   Y  |i dd}| |jg d |jddid	}| |jg d | |jd dS )
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$   e Zd Zedd dZeddZdS )z:ValidatorTestMixin.test_evolve_with_subclass.<locals>.OhNoc                   S  s   g dS )Nr   r   r   r   r   r   re     s    zCValidatorTestMixin.test_evolve_with_subclass.<locals>.OhNo.<lambda>)factoryr   defaultN)rM   r   rN   r   r   _barr   r   r   r   OhNo  s    r  Nrz   )r   r   rr   ry   r   )assertWarnsDeprecationWarningr   r*   r%   r   r  r  )r,   r  r   r   r   r   r   test_evolve_with_subclass  s   
z,ValidatorTestMixin.test_evolve_with_subclassc                 C     |  | i dd d S )Nr   r~   )r   r*   rs   r+   r   r   r   #test_is_type_is_true_for_valid_type     z6ValidatorTestMixin.test_is_type_is_true_for_valid_typec                 C  r  )Nr   rw   rc  r*   rs   r+   r   r   r   &test_is_type_is_false_for_invalid_type  r  z9ValidatorTestMixin.test_is_type_is_false_for_invalid_typec                 C  s4   |  | i dd |  | i dd d S )NTry   r|   r  r+   r   r   r   ,test_is_type_evades_bool_inheriting_from_int  s   z?ValidatorTestMixin.test_is_type_evades_bool_inheriting_from_intc                 C  s~   dddii}t j| j| jjddd d}||}|ddtdtd	 g d
i g dd g}| dd ||D | d S )Nr   rr   r|   c                 S  s   t |tttfot |t S r.   )
isinstanceintfloatr   boolr   r   r   r   r   re     s    
zGValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<lambda>r#   r=   g?rr  r   Tc                 S  s   g | ]}|j qS r   r  )rt   r  r   r   r   
<listcomp>  s    zIValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<listcomp>)	r   r   r*   r1   redefiner   r   r%   r7   )r,   r   r*   r   r  r   r   r   "test_it_can_validate_with_decimals  s   
z5ValidatorTestMixin.test_it_can_validate_with_decimalsc                 C  s"   | j ddit d}|d d S )Nr   carrotr  bugs)r*   r   r   r,   r   r   r   r   7test_it_returns_true_for_formats_it_does_not_know_about  s   
zJValidatorTestMixin.test_it_returns_true_for_formats_it_does_not_know_aboutc                 C  s   |  i }| |j d S r.   )r*   rX  r   r  r   r   r   ,test_it_does_not_validate_formats_by_default  s   
z?ValidatorTestMixin.test_it_does_not_validate_formats_by_defaultc                   s   t  }td |jdtd fdd}jddi|d}|d tj}|d	 W d    n1 s9w   Y  |j	j
  d S )
NzBad!r   )raisesc                   s.   | dkrdS | dkr  d|  d d S )NgoodTbadzWhat is z? [Baby Don't Hurt Me])r   r   r  r,   r   r   check  s
   zTValidatorTestMixin.test_it_validates_formats_if_a_checker_is_provided.<locals>.checkr   r  r  r  )r   
ValueErrorr   r*   r   r   r   r   rb  	exceptioncause)r,   r   r  r   cmr   r  r   2test_it_validates_formats_if_a_checker_is_provided  s   
zEValidatorTestMixin.test_it_validates_formats_if_a_checker_is_providedc                 C  sB   t  }d|gi}tj| j| jj|dd d}||d d S )Nrr   c                 S  
   t |tS r.   r  r  r  r   r   r   re        
 z@ValidatorTestMixin.test_non_string_custom_type.<locals>.<lambda>r  rm  )r}   r   r   r*   r1   r  r   )r,   non_string_typer   Crazyr   r   r   test_non_string_custom_type  s   
z.ValidatorTestMixin.test_non_string_custom_typec                 C  st   t j| j| jjddd d}| tj}|ddid W d   n1 s*w   Y  | 	d	t
|j dS )
zh
        A tuple instance properly formats validation errors for uniqueItems.

        See #224
        rw   c                 S  r  r.   )r  tupler  r   r   r   re     r  zNValidatorTestMixin.test_it_properly_formats_tuples_in_errors.<locals>.<lambda>r  uniqueItemsT)r=   r=   Nz(1, 1) has non-unique elements)r   r   r*   r1   r  r   r   r   r   rj   strr  )r,   TupleValidatorre  r   r   r   )test_it_properly_formats_tuples_in_errors  s   z<ValidatorTestMixin.test_it_properly_formats_tuples_in_errorsc                   s  ddd}t dd tj| j| jjdd  fddd	d
}||}tg dtdgdggtdgtdggtdggtdgggtdgggggtdggggggttdggttdggg dd ddg dtdgg dtdggg d dtdgg d dtdgggtttdgtttdggg
}|D ]}|| qtg dtdgdggtdgtdggtdggtdgggtdgggggtdggggggttdggttdggg dd ddg dtdgg dtdggg d dtdgg d dtdgggtttdgtttdggg
}|D ]}| t	j
 || W d   n	1 sQw   Y  q8dS )zO
        Allow array to validate against another defined sequence type
        rw   T)rr   r  	MyMappingza, bc                 S  s   t |ttfS r.   )r  r6   r   r  r   r   r   re         zBValidatorTestMixin.test_check_redefined_sequence.<locals>.<lambda>c                   s   t |t fS r.   )r  r'   r  r  r   r   re     r  )rw   r}   r  )rS   Nr  r`   TFr   rS   )rS   r  rS   N)r   r   r   r*   r1   redefine_manyr   r   r   r   r   )r,   r   r*   r   valid_instancesr   invalid_instancesr   r  r   test_check_redefined_sequence  sb   



""
""z0ValidatorTestMixin.test_check_redefined_sequencec                 C  sH   |  t | i j}W d    n1 sw   Y  | |tj d S r.   )r  r  r*   r  r  r   r  )r,   r  r   r   r   .test_it_creates_a_ref_resolver_if_not_providedT  s   zAValidatorTestMixin.test_it_creates_a_ref_resolver_if_not_providedc                 C  sp   dddi}}t jdi ||id}| jd|i|d}| tj |d  W d    d S 1 s1w   Y  d S )NsomeCoolRefrr   ry   r`   r  r   r  )r   r  r*   r   r   r   r   r,   r  r   r  r   r   r   r   /test_it_upconverts_from_deprecated_RefResolversY  s   "zBValidatorTestMixin.test_it_upconverts_from_deprecated_RefResolversc                   sf   G  fddd}| }ddi}  tj  j||dd W d   dS 1 s,w   Y  dS )zb
        Legacy RefResolvers support only the context manager form of
        resolution.
        c                      s   e Zd Ze fddZdS )znValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolvers.<locals>.LegacyRefResolverc                 3  s      |d ddiV  d S )Nthe refrr   ry   r%   )thisr  r+   r   r   	resolvingh  s   zxValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolvers.<locals>.LegacyRefResolver.resolvingN)rM   r   rN   r   r  r   r+   r   r   LegacyRefResolverg  s    r  r   r  r  N)r   r   r   r*   r   )r,   r  r  r   r   r+   r   @test_it_upconverts_from_yet_older_deprecated_legacy_RefResolversa  s   "zSValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolversN)rM   r   rN   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  z  s(    Br  c                   @  s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )AntiDraft6LeakMixinzN
    Make sure functionality from draft 6 doesn't leak backwards in time.
    c                 C  N   |  tj}| jd W d    n1 sw   Y  | dt|j d S )NTzTrue is not of typer   r   r   r*   r   rj   r  r  r,   re  r   r   r   test_True_is_not_a_schemay     z-AntiDraft6LeakMixin.test_True_is_not_a_schemac                 C  r  )NFzFalse is not of typer  r  r   r   r   test_False_is_not_a_schema~  r  z.AntiDraft6LeakMixin.test_False_is_not_a_schemac                 C  N   |  t}| dd W d    n1 sw   Y  | |jtj d S )NTrz   r   	Exceptionr*   r   assertNotIsInstancer  r   r   r  r   r   r   5test_True_is_not_a_schema_even_if_you_forget_to_check     zIAntiDraft6LeakMixin.test_True_is_not_a_schema_even_if_you_forget_to_checkc                 C  r  )NFrz   r  r  r   r   r   6test_False_is_not_a_schema_even_if_you_forget_to_check  r  zJAntiDraft6LeakMixin.test_False_is_not_a_schema_even_if_you_forget_to_checkN)rM   r   rN   __doc__r  r  r  r  r   r   r   r   r  t  s    r  c                   @  sP   e Zd ZU ejZi i fZded< ddidfZdd Z	dd	 Z
d
d Zdd ZdS )TestDraft3Validatortuple[dict, dict]r  rr   ry   r   c                 C  s   |  ddi}|t  d S Nrr   any)r*   r   r}   r  r   r   r   #test_any_type_is_valid_for_type_any  s   z7TestDraft3Validator.test_any_type_is_valid_for_type_anyc                 C  sr   t j| j| jjddd d}|ddi}|d | tj |d W d   dS 1 s2w   Y  dS )	z(
        Sigh, because why not.
        r   c                 S  r  r.   r  r  r   r   r   re     r  zBTestDraft3Validator.test_any_type_is_redefinable.<locals>.<lambda>r  rr   rz   r   N)	r   r   r*   r1   r  r   r   r   r   )r,   r  r   r   r   r   test_any_type_is_redefinable  s   
"z0TestDraft3Validator.test_any_type_is_redefinablec                 C  s    |  | ddit  d S r  )r   r*   r   r}   r+   r   r   r   !test_is_type_is_true_for_any_type  r  z5TestDraft3Validator.test_is_type_is_true_for_any_typec                 C  s6   |  | i dd |  | ddid d S )NTrx   rr   r   )r   r*   rs   r   r+   r   r   r   6test_is_type_does_not_evade_bool_if_it_is_being_tested  s   zJTestDraft3Validator.test_is_type_does_not_evade_bool_if_it_is_being_testedN)rM   r   rN   r   r   r*   r  __annotations__r  r!  r"  r#  r$  r   r   r   r   r    s   
 r  c                   @  0   e Zd ZU ejZi i fZded< ddidfZdS )TestDraft4Validatorr  r  rr   ry   r   N)	rM   r   rN   r   r   r*   r  r%  r  r   r   r   r   r'       
 r'  c                   @  r&  )TestDraft6Validatorr  r  rr   ry   r   N)	rM   r   rN   r   r   r*   r  r%  r  r   r   r   r   r)    r(  r)  c                   @  r&  )TestDraft7Validatorr  r  rr   ry   r   N)	rM   r   rN   r   r   r*   r  r%  r  r   r   r   r   r*    r(  r*  c                   @  r&  )TestDraft201909Validatorr  r  rr   ry   r   N)	rM   r   rN   r   Draft201909Validatorr*   r  r%  r  r   r   r   r   r+    r(  r+  c                   @  r&  )TestDraft202012Validatorr  r  rr   ry   r   N)	rM   r   rN   r   r   r*   r  r%  r  r   r   r   r   r-    r(  r-  c                   @     e Zd ZdZdd ZdS )TestLatestValidatorzQ
    These really apply to multiple versions but are easiest to test on one.
    c                 C  sj   d}d|i}t jdi |did}t j||d}| tj |d  W d    d S 1 s.w   Y  d S )Nr  r   r`   Fr  r  )r   r  r   r   r   r   r   r  r   r   r   2test_ref_resolvers_may_have_boolean_schemas_stored  s   "zFTestLatestValidator.test_ref_resolvers_may_have_boolean_schemas_storedN)rM   r   rN   r  r0  r   r   r   r   r/    s    r/  c                   @  s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS ) TestValidatorForc                 C  <   ddi}|  t|tj ddi}|  t|tj d S )Nr   &http://json-schema.org/draft-03/schema'http://json-schema.org/draft-03/schema#)rb  r   validator_forr   r3   r   r   r   test_draft_3     zTestValidatorFor.test_draft_3c                 C  r2  )Nr   &http://json-schema.org/draft-04/schema'http://json-schema.org/draft-04/schema#)rb  r   r5  r   r3   r   r   r   test_draft_4  r7  zTestValidatorFor.test_draft_4c                 C  r2  )Nr   &http://json-schema.org/draft-06/schema'http://json-schema.org/draft-06/schema#)rb  r   r5  r   r3   r   r   r   test_draft_6  r7  zTestValidatorFor.test_draft_6c                 C  r2  )Nr   &http://json-schema.org/draft-07/schema'http://json-schema.org/draft-07/schema#)rb  r   r5  r   r3   r   r   r   test_draft_7  r7  zTestValidatorFor.test_draft_7c                 C  r2  )Nr   z,https://json-schema.org/draft/2019-09/schemaz-https://json-schema.org/draft/2019-09/schema#)rb  r   r5  r,  r3   r   r   r   test_draft_201909  r7  z"TestValidatorFor.test_draft_201909c                 C  r2  )Nr   ,https://json-schema.org/draft/2020-12/schema-https://json-schema.org/draft/2020-12/schema#)rb  r   r5  r   r3   r   r   r   test_draft_202012  r7  z"TestValidatorFor.test_draft_202012c                 C     |  tdtj d S )NTrb  r   r5  r   r+   r   r   r   	test_True*     zTestValidatorFor.test_Truec                 C  rE  r   rF  r+   r   r   r   
test_False0  rH  zTestValidatorFor.test_Falsec                 C  s6   t jddiddd d}ddi}| t || d S )NrZ   r]   12c                 S  r^   r_   ra   rc   r   r   r   re   :  rf   z8TestValidatorFor.test_custom_validator.<locals>.<lambda>rg   r   r   r)   rb  r5  r,   r*   r   r   r   r   test_custom_validator6  s   z&TestValidatorFor.test_custom_validatorc                 C  s0   t jddidd}ddi}| t || d S )Nr!   ro   13rI   r   rK  rL  r   r   r   test_custom_validator_draft6B  s   z-TestValidatorFor.test_custom_validator_draft6c                 C  s   |  ti tj d S r.   rF  r+   r   r   r   %test_validator_for_jsonschema_defaultM  r  z6TestValidatorFor.test_validator_for_jsonschema_defaultc                 C  s   |  tji d dd  d S )Nr  )rb  r   r5  r+   r   r   r   !test_validator_for_custom_defaultP  s   z2TestValidatorFor.test_validator_for_custom_defaultc                 C  s^   |  t}tjddid W d    n1 sw   Y  | |jt | t|jd d S )Nr   unknownSchemar   zThe metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future.)	r  r  r   r5  r%   filename__file__r  warning)r,   r  r   r   r   1test_warns_if_meta_schema_specified_was_not_foundS  s   zBTestValidatorFor.test_warns_if_meta_schema_specified_was_not_foundc                 C  sR   t jdd}t d tji i d W d    n1 sw   Y  | | d S )NTrecordalways)r   r  )warningscatch_warningssimplefilterr   r5  rc  )r,   wr   r   r   0test_does_not_warn_if_meta_schema_is_unspecified_  s
   
zATestValidatorFor.test_does_not_warn_if_meta_schema_is_unspecifiedc                 C  s(   ddit  }}| t||| d S )Nr   zmailto:foo@example.com)r}   rb  r   r5  )r,   r   r  r   r   r   -test_validator_for_custom_default_with_schemae  s   z>TestValidatorFor.test_validator_for_custom_default_with_schemaN)rM   r   rN   r6  r:  r=  r@  rA  rD  rG  rI  rM  rO  rP  rQ  rV  r^  r_  r   r   r   r   r1    s     r1  c                   @  s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )TestValidatec                 C  sT   g }t j|d|j ti | W d    n1 sw   Y  | ||g d S )Nr   )r
   patchr}   appendr   r   r%   )r,   r   r*   resultr   r   r   
assertUsesk  s
   zTestValidate.assertUsesc                 C  ,   | j dditjd | j dditjd d S )Nr   r4  r   r*   r3  )rd  r   r   r+   r   r   r   test_draft3_validator_is_chosenq     
z,TestValidate.test_draft3_validator_is_chosenc                 C  re  )Nr   r9  rf  r8  )rd  r   r   r+   r   r   r   test_draft4_validator_is_chosen|  rh  z,TestValidate.test_draft4_validator_is_chosenc                 C  re  )Nr   r<  rf  r;  )rd  r   r   r+   r   r   r   test_draft6_validator_is_chosen  rh  z,TestValidate.test_draft6_validator_is_chosenc                 C  re  )Nr   r?  rf  r>  )rd  r   r   r+   r   r   r   test_draft7_validator_is_chosen  rh  z,TestValidate.test_draft7_validator_is_chosenc                 C  re  )Nr   rC  rf  rB  rd  r   r   r+   r   r   r   $test_draft202012_validator_is_chosen  s   
z1TestValidate.test_draft202012_validator_is_chosenc                 C  s   | j i tjd d S )Nrf  rl  r+   r   r   r   )test_draft202012_validator_is_the_default  r   z6TestValidate.test_draft202012_validator_is_the_defaultc                 C  sR   |  tj}tdddi W d    n1 sw   Y  | t|jd d S )Nrz   rr   r~   z1(?s)Failed validating '.*' in schema.*On instance)r   r   r   r   r   assertRegexr  r  r  r   r   r   test_validation_error_message     z*TestValidate.test_validation_error_messagec                 C  sR   |  tj}tdddi W d    n1 sw   Y  | t|jd d S )Nrz   rr   z3(?s)Failed validating '.*' in metaschema.*On schema)r   r   r   r   r   ro  r  r  r  r   r   r   test_schema_error_message  rq  z&TestValidate.test_schema_error_messagec                 C  sd   ddddddigi}|  tj}td| W d    n1 s"w   Y  | dt|j d S )	Nr5  r|   rV  r  rr   rw   rz   z!12 is less than the minimum of 20)r   r   r   r   r   rj   r  r  )r,   r   re  r   r   r   test_it_uses_best_match  s   z$TestValidate.test_it_uses_best_matchN)rM   r   rN   rd  rg  ri  rj  rk  rm  rn  rp  rr  rs  r   r   r   r   r`  j  s    r`  c                   @  r.  )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.
    c                   sX   g   fdd}|  ddl m} ||d}|  |  | |  fdg f d S )Nc                     s0   z
t jddd W d S     t  Y d S )Nr   Tr   )r   r   rb  sysexc_infor   failedr   r   r     s   zFTestThreading.test_validation_across_a_second_thread.<locals>.validater   )Thread)targetF)	threadingry  startjoinr%   is_alive)r,   r   ry  threadr   rw  r   &test_validation_across_a_second_thread  s   
z4TestThreading.test_validation_across_a_second_threadN)rM   r   rN   r  r  r   r   r   r   rt    s    rt  c                   @  s   e Zd Zdd Zdd ZdS )TestReferencingc                 C  sJ   dd }t j|d}ddi}tj||d}| |d|dfd	 d S )
Nc                 S  s   t ddiS )Nrr   ry   )r   create_resourceurir   r   r   retrieve  s   z=TestReferencing.test_registry_with_retrieve.<locals>.retrieve)r  r   https://example.com/registryrz   r   )TF)referencingRegistryr   r   r%   r   )r,   r  r  r   r   r   r   r   test_registry_with_retrieve  s   z+TestReferencing.test_registry_with_retrievec              	   C  s   t  }ddi}tj||d}tjdd)}td | t jj	 |
d W d    n1 s2w   Y  W d    n1 sAw   Y  | | d S )Nr   r  r  TrW  rY  rz   )r  r  r   r   rZ  r[  r\  r   r   Unresolvabler   rc  )r,   r  r   r   r]  r   r   r   ;test_custom_registries_do_not_autoretrieve_remote_resources  s   
zKTestReferencing.test_custom_registries_do_not_autoretrieve_remote_resourcesN)rM   r   rN   r  r  r   r   r   r   r    s    r  c                   @  s   e Zd ZdZdZddiZdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)S )*TestRefResolverr`   zfoo://storedstoredr   c                 C  s.   i | _ | j| ji| _t| j| j | j| _d S r.   )referrer
stored_uristored_schemar  r   r  base_urir  r+   r   r   r   r-   
	  s
   
zTestRefResolver.setUpc              	   C  s   t jjd }tj| jd}| j|}W d    n1 s w   Y  W d    n1 s/w   Y  | |t jj | 	|j
 d S )NrZ   resolve_remote)r   r   r0   r
   ra  r}   r  r  r%   rc  called)r,   r  patchedresolvedr   r   r   6test_it_does_not_retrieve_schema_urls_from_the_network	  s   zFTestRefResolver.test_it_does_not_retrieve_schema_urls_from_the_networkc                 C  s\   d}dt  i| jd< | j|}| || jd d  W d    d S 1 s'w   Y  d S )Nz#/properties/foor   r?  )r}   r  r  r  r%   )r,   r  r  r   r   r   test_it_resolves_local_refs	  s
   "z+TestRefResolver.test_it_resolves_local_refsc                 C  s   dddid}t jj|dd d}|d}| ||d	  W d    n1 s)w   Y  |d
}| ||d	  W d    d S 1 sGw   Y  d S )Nzhttp://bar/schema#r   r   )rZ   rS   c                 S  r^   r_   ra   r   r   r   r   re   #	  rf   zETestRefResolver.test_it_resolves_local_refs_with_id.<locals>.<lambda>rh   z#/arS   zhttp://bar/schema#/a)r   r  from_schemar  r%   r,   r   r  r  r   r   r   #test_it_resolves_local_refs_with_id	  s   "z3TestRefResolver.test_it_resolves_local_refs_with_idc                 C  s   | j | j}| || j W d    n1 sw   Y  ddi| j jd< | j d}| |d W d    d S 1 s>w   Y  d S )Nr   rz   
cached_refzcached_ref#/foo)r  r  r  rb  r  r  r%   )r,   r  r   r   r   test_it_retrieves_stored_refs*	  s   "z-TestRefResolver.test_it_retrieves_stored_refsc                 C  s~   d}ddi}dt jv r| t jjdt jd  td|it jd< | j|}| |d W d    d S 1 s8w   Y  d S )Nhttp://bar#bazr'  rz   requests
http://bar)ru  modulesr$   __setitem__ReallyFakeRequestsr  r  r%   )r,   r  r   r  r   r   r   ,test_it_retrieves_unstored_refs_via_requests2	  s   
"z<TestRefResolver.test_it_retrieves_unstored_refs_via_requestsc                   s   d}ddi dt jv rt jjdt jd  d t jd< t fdd}ttdtj |t_j	|}W d    n1 sBw   Y  
|d d S )Nr  r'  rz   r  c                 3  s(     | d tt dV  d S )Nr  utf8)r%   r   jsondumpsencodeurlr   r,   r   r   fake_urlopenI	  s   zQTestRefResolver.test_it_retrieves_unstored_refs_via_urlopen.<locals>.fake_urlopenurlopen)ru  r  r$   r  r   setattrr   r  r  r  r%   )r,   r  r  r  r   r  r   +test_it_retrieves_unstored_refs_via_urlopen?	  s   

z;TestRefResolver.test_it_retrieves_unstored_refs_via_urlopenc                 C  s   t jddd}| tj|j tddi| W d    n1 s"w   Y  dt|j d}| j	
|}| |d W d    d S 1 sHw   Y  d S )NFwt)deletemoder   r   zfile://z#foo)tempfileNamedTemporaryFiler$   osremover   r  dumpr   r  r  r%   )r,   tempfr  r  r   r   r   (test_it_retrieves_local_refs_via_urlopenU	  s   "z8TestRefResolver.test_it_retrieves_local_refs_via_urlopenc                 C  s  ddi}t jj|dd d}| |jd | |jd |d}| || W d    n1 s2w   Y  |d}| || W d    n1 sMw   Y  |d}| || W d    n1 shw   Y  |d}| || W d    d S 1 sw   Y  d S )	NrZ   r   c                 S  r^   r_   ra   r   r   r   r   re   b	  rf   zPTestRefResolver.test_it_can_construct_a_base_uri_from_a_schema.<locals>.<lambda>r  r`   #zfoo#r   r  r  r%   r  resolution_scoper  r  r   r   r   .test_it_can_construct_a_base_uri_from_a_schema^	  s&   "z>TestRefResolver.test_it_can_construct_a_base_uri_from_a_schemac                 C  s   i }t j|}| |jd | |jd |d}| || W d    n1 s,w   Y  |d}| || W d    d S 1 sHw   Y  d S )Nr`   r  r  r  r   r   r   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_idc                   sl    fdd}ddid t jdi d|id}| }| W d    d S 1 s/w   Y  d S )Nc                   s    |   S r.   r	  r  r  r   r,   r   r   handlerz	  s   z@TestRefResolver.test_custom_uri_scheme_handlers.<locals>.handlerr   r   	foo://barr`   handlers)r   r  r  r%   )r,   r  r  r  r   r  r   test_custom_uri_scheme_handlersy	  s   "z/TestRefResolver.test_custom_uri_scheme_handlersc                   s   t  g  fdd}d}tjdi dd|id}|| W d    n1 s(w   Y  ||	 W d    d S 1 s>w   Y  d S )Nc                   *   z   W S  ty   d Y d S w )Nz#Response must not have been cached!rL   
IndexErrorr   r  responser,   r   r   r  	  
   
z5TestRefResolver.test_cache_remote_on.<locals>.handlerr  r`   Tr   cache_remoter  r}   r   r  r  r,   r  r  r  r   r  r   test_cache_remote_on	  s   "z$TestRefResolver.test_cache_remote_onc                   s`   t  g  fdd}d}tjdi dd|id}||	 W d    d S 1 s)w   Y  d S )Nc                   r  )NzHandler called twice!r  r  r  r   r   r  	  r  z6TestRefResolver.test_cache_remote_off.<locals>.handlerr  r`   Fr   r  r  r  r   r  r   test_cache_remote_off	  s   "z%TestRefResolver.test_cache_remote_offc              	     s   t d  fdd}d}tjdi d|id}| tj"}|| | d W d    n1 s2w   Y  W d    n1 sAw   Y  | |j	t  d S )	NzOh no! What's this?c                   s    r.   r   r  r  r   r   r  	  s   zTTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_error.<locals>.handlerr  r`   r   r  zShouldn't get this far!)
r  r   r  r   r   _RefResolutionErrorr  r   r%   r  )r,   r  r  r  errr   r  r   3test_if_you_give_it_junk_you_get_a_resolution_error	  s   zCTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_errorc                 C  s^   t di }|  | tj}|  W d    n1 sw   Y  | dt|j d S )Nr`   zFailed to pop the scope)	r   r  	pop_scoper   r   r  rj   r  r  )r,   r  excr   r   r   .test_helpful_error_message_on_failed_pop_scope	  s   
z>TestRefResolver.test_helpful_error_message_on_failed_pop_scopec                 C  s~   t jj}t d|}t j||d}| |ddi ddt jjd igi}t d|}t j||d}| |ddi dS )	z
        See #1085.
        r`   r  r  r   allOfr   r!   N)r   r   r0   r  rc  r   )r,   r   oner   anothertwor   r   r   ,test_pointer_within_schema_with_different_id	  s   z<TestRefResolver.test_pointer_within_schema_with_different_idc                   sh    fdd}t jdi d|id}t ji t jjd}ddd	}|||d
} |i |dfd dS )zj
        See https://github.com/python-jsonschema/jsonschema/issues/1061#issuecomment-1624266555.
        c                   s     | d ddiS )Nzhttp://example.com/foorr   ry   r	  r  r+   r   r   handle	  s   zNTestRefResolver.test_newly_created_validator_with_ref_resolver.<locals>.handler`   httpr  rq   zhttp://example.com/barr   )r!   r   r  r   FTN)r   r  r)   r   r/   r%   r   )r,   r  r  r*   r   r   r   r+   r   .test_newly_created_validator_with_ref_resolver	  s   
z>TestRefResolver.test_newly_created_validator_with_ref_resolverc                 C  sX   dddiidddiid}t j|t d|d}| |dd	i|dd
ifd dS )zj
        See https://github.com/python-jsonschema/jsonschema/issues/1124#issuecomment-1632574249.
        xr   z#/definitions/xrr   ry   )r?  r  r`   r  yr   r  N)r   r   r  r%   r   )r,   r   r   r   r   r   2test_refresolver_with_pointer_in_schema_with_no_id	  s   


zBTestRefResolver.test_refresolver_with_pointer_in_schema_with_no_idN)rM   r   rN   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  	  s,    	
r  c                 C  s   dd }t | |dS )Nc                 S  s    dd | j D dd | jD fS )Nc                 S     g | ]}t |qS r   r  rt   re  r   r   r   r  	      z.sorted_errors.<locals>.key.<locals>.<listcomp>c                 S  r  r   r  r  r   r   r   r  	  r  )rZ  r<   r  r   r   r   key	  s   zsorted_errors.<locals>.key)r  )sorted)r   r  r   r   r   ra  	  s   ra  c                   @     e Zd ZU ded< dd ZdS )r  zdict[str, Any]
_responsesc                 C  s2   | j |}|d u rtdt| tt|S )NzUnknown URL: )r  rb   r  rQ   _ReallyFakeJSONResponser  r  )r,   r  r  r   r   r   rb   
  s   zReallyFakeRequests.getN)rM   r   rN   r%  rb   r   r   r   r   r  	     
 r  c                   @  r  )r  r  	_responsec                 C  s   t | jS r.   )r  loadsr  r+   r   r   r   r  
  s   z_ReallyFakeJSONResponse.jsonN)rM   r   rN   r%  r  r   r   r   r   r  	
  r  r  ):
__future__r   collectionsr   r   
contextlibr   decimalr   ior   typingr   unittestr	   r
   urllib.requestr   r  r  ru  r  rZ  attrsr   r   referencing.jsonschemar   referencing.exceptionsr  
jsonschemar   r   r   r   r   r   r    r   rT  r  r  r  r  r'  r)  r*  r+  r-  r/  r1  r`  rt  r  r  ra  r  r  r   r   r   r   <module>   sp    	            8 {  a q	