o
    i3                    @  s  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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Zd dlZd d	lmZmZmZmZmZ d d
l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"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Z+G d%d& d&eZ,G d'd( d(eZ-G d)d* d*eZ.G d+d, d,eZ/d-d. Z0ej1G d/d0 d0Z2ej1G d1d2 d2Z3dS )3    )annotations)deque
namedtuple)contextmanager)Decimal)BytesIO)TestCasemock)pathname2urlN)FormatCheckerTypeChecker
exceptions	protocols
validators)bugc                 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   [/var/www/edux/Edux_v2/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'S )(TestCreateAndExtendc                 C  sP   |  | 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dictr   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_attrs3   s   zTestCreateAndExtend.test_attrsc                 C  s    dg i}|  | |j| d S )Nr   )r"   r&   r   r(   r   r   r   r   	test_init@   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_successfulD   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   r2   r3   r"   len	_contents)r(   r   r   expected_errorr   r   r   r   test_iter_errors_one_errorK   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   Thirdr6      )r&   r2   r3   r"   r:   r4   r   r   r    test_iter_errors_multiple_errors\   s   
z4TestCreateAndExtend.test_iter_errors_multiple_errorsc                 C  sB   t jddidd}| t jjd | |jd | |jd d S )Nr   	something
my versionr   versionMyVersionValidator)r   r%   r!   r#   popr"   __name____qualname__r(   r&   r   r   r   .test_if_a_version_is_provided_it_is_registeredi   s   zBTestCreateAndExtend.test_if_a_version_is_provided_it_is_registeredc                 C  s:   t jddidd}| t jjd | t|i d d S )Nr   rC   rD   rE   z2MyVersionValidator(schema={}, format_checker=None))r   r%   r!   r#   rH   r"   reprrK   r   r   r   	test_reprr   s   
zTestCreateAndExtend.test_reprc                 C  sF   t jddidd}| t jjd | t|dttdid d S )Nr   rC   rD   rE   ai  zNMyVersionValidator(schema={'a': [0, 1, 2, 3, 4, 5, ...]}, format_checker=None))	r   r%   r!   r#   rH   r"   rM   r2   rangerK   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"   rM   rK   r   r   r   test_repr_no_version   s
   
z(TestCreateAndExtend.test_repr_no_versionc                 C  s4   t jddidd}| t jjd | |jd d S )Nr   rC   zfoo-barrE   FooBarValidator)r   r%   r!   r#   rH   r"   rJ   rK   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idrR   )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  sB   d}d|i}t j|ddd d | t jj| | |t j d S )Nmeta schema idrV   rD   c                 S     |  ddS NrV    getsr   r   r   <lambda>       zMTestCreateAndExtend.test_validates_registers_meta_schema_id.<locals>.<lambda>r   rF   id_ofr   r%   r!   r#   rH   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  s<   d}d|i}t j|dd | t jj| | |t j d S )Nmeta schema $idr   rD   rE   re   rg   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).0rn   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   rq   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notrR   r{   barN)	r   r%   Draft202012Validatorr,   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!rm   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+   ry   r   extendr"   r,   r-   )r(   rW   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__)r^   r&   ID_OFr   r'   r   r   rd        z3TestCreateAndExtend.test_extend_idof.<locals>.id_ofzthe://correct/id/zthe://wrong/id/)r   r   )r   r   r    rd   N)r   r%   r    r"   r   r,   r   )r(   rd   
correct_idr   OriginalDerivedr   r'   r   test_extend_idof   s   
z$TestCreateAndExtend.test_extend_idofN)rI   
__module__rJ   r)   r.   r0   r5   r=   rB   rL   rN   rQ   rS   rU   rX   rj   rl   r~   r   r   r   r   r   r   r   r   r   "   s(    	r   c                   @  st  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[S )\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 )msgr9   z"Expected exactly one error, found r   )
rH   r   _LATEST_VERSIONr   r2   r3   r|   r"   r:   r   )r(   r   r   argskwargsr   r   r   r   r   r   message_for  s   

z'TestValidationErrorMessages.message_forc                 C  "   | j dddid}| |d d S Nr9   rn   rz   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_failure'     z9TestValidationErrorMessages.test_single_type_list_failurec                 C  s*   d}| j ddt|id}| |d d S )N)rz   ry   r9   rn   r   z#1 is not of type 'string', 'object')r   r2   r"   )r(   typesr   r   r   r   test_multiple_type_failure+  s   z6TestValidationErrorMessages.test_multiple_type_failurec                 C  s2   ddddgi}| j d|tjd}| |d d S )Nrn   FoorA   )nameminimumr9   r   r   r   z1 is not of type 'Foo'r   r   Draft3Validatorr"   r(   r   r   r   r   r   #test_object_with_named_type_failure0  s   z?TestValidationErrorMessages.test_object_with_named_type_failurec                 C  r   )Nr9   r      r   z1 is less than the minimum of 2r   r   r   r   r   test_minimum9  r   z(TestValidationErrorMessages.test_minimumc                 C  r   )Nr9   maximumr   r   z"1 is greater than the maximum of 0r   r   r   r   r   test_maximum=  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_elementA  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 )Nrn   r   rA   r9   r   z+1 is not of type {'type': [{'minimum': 3}]}r   )r(   rn   r   r   r   r   -test_object_without_title_type_failure_draft3K  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_draft3W     z9TestValidationErrorMessages.test_dependencies_list_draft3c                 C  r   r   )r   r   Draft7Validatorr"   r   r   r   r   test_dependencies_list_draft7a  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   rf   r   r   r   r   #test_additionalItems_single_failurek  s   z?TestValidationErrorMessages.test_additionalItems_single_failurec                 C  s,   | j g dg ddtjd}| d| d S )Nr9   r   rA   Fr   r   z(1, 2, 3 were unexpected)r   r   r   r   r   &test_additionalItems_multiple_failuress  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   rf   )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$   fromkeysrf   rM   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   rv   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   rv   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   ra     s    zQTestValidationErrorMessages.test_invalid_format_default_message.<locals>.<lambda>formatbla)r   r   format_checkerzis not a)r   checksr   rf   rM   )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 )Nry   Frn   rz   )^abc$^def$)rn   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   Draft4Validatorr"   r   rM   r   r   r   r   1test_additionalProperties_false_patternProperties  s8   zMTestValidationErrorMessages.test_additionalProperties_false_patternPropertiesc                 C  s   | j ddd}| |d d S )NrC   Fr   z'False schema does not allow 'something'r   r   r   r   r   test_False_schema  s
   z-TestValidationErrorMessages.test_False_schemac                 C  r   )NrA   
multipleOfr   r   z3 is not a multiple of 2r   r   r   r   r   test_multipleOf  
   z+TestValidationErrorMessages.test_multipleOfc                 C  s"   | 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  s&   | 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  s,   | j g ddi i gdd}| |d d S )Nr9   r   r{      Fr   prefixItemsr   z%Expected at most 2 items, but found 4r   r   r   r   r   test_prefixItems_with_items  
   z7TestValidationErrorMessages.test_prefixItems_with_itemsc                 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   )Nbbbpatternz^a*$r   z'bbb' does not match '^a*$'r   r   r   r   r   test_pattern  r   z(TestValidationErrorMessages.test_patternc                 C  s&   | j g dddiid}| |d d S )Nr   rn   rz   r   z3[] does not contain items matching the given schemar   r   r   r   r   test_does_not_contain  s   
z1TestValidationErrorMessages.test_does_not_containc                 C  s,   | j ddgddiddd}| |d d S )	Nr{   r9   rn   rz   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	     z1TestValidationErrorMessages.test_contains_too_fewc                 C  s.   | j ddgddidddd}| |d	 d S )
Nr{   r9   rn   rz   r      r   r  maxContainsr   r  r   r   r   r   r   &test_contains_too_few_both_constrained  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   bazrn   rz   r   r   r  r   :Too many items match the given schema (expected at most 2)r   r   r   r   r   test_contains_too_many#  r  z2TestValidationErrorMessages.test_contains_too_manyc                 C  s0   | j dgd ddidddd}| |d	 d S )
Nr{   r   rn   rz   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   )NrA   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   )NrA   exclusiveMaximumr   r   z.3 is greater than or equal to the maximum of 2r   r   r   r   r   test_exclusiveMaximumE  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_requiredL  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_dependentRequiredP  r   z2TestValidationErrorMessages.test_dependentRequiredc                 C  s"   | j i ddid}| |d d S )NminPropertiesr   r   z"{} does not have enough propertiesr   r   r   r   r   test_minPropertiesW  r   z.TestValidationErrorMessages.test_minPropertiesc                 C  s*   | j i i i dddid}| |d d S )N)rO   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  )NoneOfFr   z.{} is not valid under any of the given schemasr   r   r   r   r   test_oneOf_matches_nonee  s
   z3TestValidationErrorMessages.test_oneOf_matches_nonec                 C  s&   | j i dddgid}| |d d S )Nr  Tr   z${} is valid under each of True, Truer   r   r   r   r   test_oneOf_matches_too_manyl  r   z7TestValidationErrorMessages.test_oneOf_matches_too_manyc                 C  s,   ddd}| j ddg|d}| |d d S )Nrs   Frn   unevaluatedItemsr{   r   r   z@Unevaluated items are not allowed ('bar', 'foo' were unexpected)r   r   r   r   r   test_unevaluated_itemsp  s   
z2TestValidationErrorMessages.test_unevaluated_itemsc                 C  (   ddd}| j d|d}| |d d S )Nrs   Fr"  r{   r   z'foo' is not of type 'array'r   r   r   r   r   &test_unevaluated_items_on_invalid_typex     
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{   rn   rz   r   rv   )
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 )	Nry   Frn   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%  )Nry   Fr+  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_typeN)0rI   r   rJ   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*  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)S )*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      rn   rz   r9   r   $r   )r0  r   r   )r0  r9   rn   )r   r   r2   r3   r"   r:   r   r7   r   r   assertIsNoneparentpathr   relative_pathabsolute_path	json_pathr8   relative_schema_pathabsolute_schema_pathcontextsorted_errorsassertIsassertFalser(   r   r   r   r   ee1e2r   r   r   
test_anyOf  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{   r9   rn   ru   ry   enumr   rn   r(  r   r2  )rn   r   rn   $.foo)r9   r(  r{   rD  )rn   r9   r(  r{   rD  )r   r   r2   r3   r"   r:   r   r7   r   r   r3  r4  r5  r   r6  r7  r8  r8   r9  r:  r;  r<  r=  r>  r?  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   r9      spam)r{   r   r  quuxr(  rn   rz   r   
   )r   r        )r   rD  r
  r   r  r{   $.barz$.bazrF  rD  r   )r   r   r3   r<  r"   r5  r   r6  r7  r8  r   )	r(   r   r   r   r   rA  rB  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 )"Nr9   r   r  r,  rJ  rz   ry   rD  rA   rs   r  Tr   )r   r  rE  )rn   r   r   r   )r9   r   r   )r9   r   r  r{   r2  $[0]z$[1].barz$[1].bar.barz$[1].bar.bazz$[1].foorn   r   )r   r(  r   rn   )r   r(  r   r(  r   r  )r   r(  r   r(  r  r   )r   r(  r{   rD  )r   r   r3   r<  r"   r5  r   r8  r8   r2   r   )r(   r   r   r   r   rA  rB  rO  rP  e5e6r   r   r   test_multiple_nestinga  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noder0  ry   r   childrenrn   rz   ^.*$$refz#/definitions/node)rn   r   )r   rW  )rn   r  r(  root)definitionsrn   r  r(  rO   ab)r(  rZ  r0  z$.root)rZ  rW  rO   )	r(  rZ  r0  r   r(  rW  r   rX  r0  z$.root.children.a)rZ  rW  rO   rW  r\  )r(  rZ  r0  r   r(  rW  r   rX  r0  r   r(  rW  r   rX  r0  z$.root.children.a.children.ab)	r   r   r3   r"   r7  r   r:  r8  r;  )r(   r   r   r   r@  rA  rB  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   ru   r   rn   r   r{   rN  rF  rn   r   	r   r   r3   r<  r"   r5  r   r8  r   r(   r   r   r   r   rA  rB  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 )Nr9   r   r   r   rn   rz   r   r   r   r{   rN  rF  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{   r9   ru   r   r^  r   r   rR  $[1]rn   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   r9   ru   r   r^  r   r9   r   rc  z$[2]rn   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{   rv   propertyNamesr   r   z0'foo' should not be valid under {'const': 'foo'}r2  
r   r   r3   r"   r   r   r5  r   r8  r8   )r(   r   r   r   errorr   r   r   test_propertyNamesR  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   rv      )ifthen13 was expectedr2  rl  rg  r(   r   r   rh  r   r   r   test_if_thenb     
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   rv   rj  )rk  elserH  rm  r2  rq  rg  rn  r   r   r   test_if_elseq  rp  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 )NFrv   zFalse schema does not allow 12r2  )r   r   r3   r"   r   r   r7   r   r   r8   r8  r   )r(   r   rh  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   rn   ru   rY  r\   storeresolverr{   notAnIntegerz''notAnInteger' is not of type 'integer'rF  )r   r   RefResolverr3   r"   r   r   r7   r   r7  r   r8   r8  r   )r(   refr   r   rh  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   rn   rz   r   rA   r   r   r9   r   )r   r   rn   rR  z"5 is greater than the maximum of 3r   )r   rA   r   $[3]r   r   r3   r"   r   r   r7   r   r7  r   r8   r8  r   )r(   r   r   
type_error	min_errorr   r   r   test_prefixItems  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 )Nrn   rz   r   )r{   r   r   r  r  z2 is not of type 'string'r   r9   r   rc  z4 is not of type 'string'r  rA   r}  r~  r(   r   r   rA  rB  r   r   r   r     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.
        rn   rz   r   r  )r{   r   r   r  r  rJ  r  r  r   r2  Nr~  rn  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 )
Nrn   rz   r   r  )r{   r   r  r  r  r   r2  r~  rn  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 )	Nrn   rz   r   r  r  z7[2, 4] does not contain items matching the given schemar   r2  r~  rn  r   r   r   test_contains_noneZ  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{   r  r   apropz#/$defs/foor  )rY  r  )z$defsr(  z'bar' is a required property)r(  r  r  z$.apropz'baz' is a required property)r   r   r3   r"   r   r   r7   r   r7  r   r8   r9  r8  r   r  r   r   r   test_ref_siblingu  sj   






z+TestValidationErrorDetails.test_ref_siblingN)rI   r   rJ   rC  rG  rQ  rU  r]  ra  rb  rd  re  ri  ro  rr  rs  r|  r  r   r  r  r  r  r   r   r   r   r/    s*    EM'=e14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S )MetaSchemaTestsMixinc                 C  B   |  tj | jddi W d    d S 1 sw   Y  d S )Nr(  rv   r   r   r   r&   r   r'   r   r   r   test_invalid_properties     "z,MetaSchemaTestsMixin.test_invalid_propertiesc                 C  r  )Nr   1r  r'   r   r   r   test_minItems_invalid_string  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.
        rD  Nr&   r   r   r   r   r   r   r   r'   r   r   r   test_enum_allows_empty_arrays  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.
        rD  rv   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_regex  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_validation  s   
zSMetaSchemaTestsMixin.test_schema_with_invalid_regex_with_disabled_format_validationN)	rI   r   rJ   r  r  r  r  r  r  r   r   r   r   r    s    r  c                   @  r   )(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&   is_validr(   r   r   r   r   r   test_valid_instances_are_valid     
z1ValidatorTestMixin.test_valid_instances_are_validc                 C  r  r*   )invalidr>  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&   ry   r   r'   r   r   r   (test_non_existent_properties_are_ignored      z;ValidatorTestMixin.test_non_existent_properties_are_ignoredc                 C  s   |  | i jtj d S r*   )r  r&   rx  r   rz  r'   r   r   r   .test_it_creates_a_ref_resolver_if_not_provided  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someCoolRefrn   ru   r\   ru  rY  rw  )r   rz  r&   r   r   r   r   r(   r{  r   rx  r   r   r   r   #test_it_delegates_to_a_ref_resolver  s   "z6ValidatorTestMixin.test_it_delegates_to_a_ref_resolverc                 C  sn   dddi}}t jdi ||id}| j||d}|jddid}| jddi|d}| || | || d S )	Nr  rn   ru   r\   ru  rw  rz   r   )r   rz  r&   evolver"   assertNotEqual)r(   r{  r   rx  r   r   expectedr   r   r   test_evolve	  s   zValidatorTestMixin.test_evolvec                 C  s   |  t tj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jdd dZejddZdS )z:ValidatorTestMixin.test_evolve_with_subclass.<locals>.OhNoc                   S  s   g dS )Nr   r   r   r   r   r   ra   "  s    zCValidatorTestMixin.test_evolve_with_subclass.<locals>.OhNo.<lambda>)factory%   defaultN)rI   r   rJ   attribr{   _barr   r   r   r   OhNo   s    r  Nrv   )r   r   rn   ru   r   )	assertWarnsDeprecationWarningr  r`   r&   r"   r{   r  r  )r(   r  r   r   r   r   r   test_evolve_with_subclass  s   
z,ValidatorTestMixin.test_evolve_with_subclassc                   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 )zXValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolver.<locals>.LegacyRefResolverc                 3  s      |d ddiV  d S )Nthe refrn   ru   r"   )thisr{  r'   r   r   	resolving3  s   zbValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolver.<locals>.LegacyRefResolver.resolvingN)rI   r   rJ   r   r  r   r'   r   r   LegacyRefResolver2  s    r  rY  r  rw  N)r   r   r   r&   r   )r(   r  rx  r   r   r'   r   *test_it_delegates_to_a_legacy_ref_resolver,  s   "z=ValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolverc                 C     |  | i dd d S )Nr{   rz   )r|   r&   ro   r'   r   r   r   #test_is_type_is_true_for_valid_type>     z6ValidatorTestMixin.test_is_type_is_true_for_valid_typec                 C  r  )Nr{   rs   r>  r&   ro   r'   r   r   r   &test_is_type_is_false_for_invalid_typeA  r  z9ValidatorTestMixin.test_is_type_is_false_for_invalid_typec                 C  s4   |  | i dd |  | i dd d S )NTru   rx   r  r'   r   r   r   ,test_is_type_evades_bool_inheriting_from_intD  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   rn   rx   c                 S  s   t |tttfot |t S r*   )
isinstanceintfloatr   boolr   r   r   r   r   ra   N  s    
zGValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<lambda>r    r9   g?rM  r{   Tc                 S  s   g | ]}|j qS r   r  )rp   rh  r   r   r   
<listcomp>Y  s    zIValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<listcomp>)	r   r   r&   r-   redefiner   r   r"   r3   )r(   r   r&   r   r  r   r   r   "test_it_can_validate_with_decimalsH  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&   r3  r   r  r   r   r   ,test_it_does_not_validate_formats_by_defaultc  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 S )NgoodTbadz What is {}? [Baby Don't Hurt Me])r   r   r   r  r(   r   r   checkk  s
   zTValidatorTestMixin.test_it_validates_formats_if_a_checker_is_provided.<locals>.checkr   r  r  r  )r   
ValueErrorr   r&   r   r   r   r   r=  	exceptioncause)r(   r   r  r   cmr   r  r   2test_it_validates_formats_if_a_checker_is_providedg  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 )Nrn   c                 S  
   t |tS r*   r  r  r  r   r   r   ra        
 z@ValidatorTestMixin.test_non_string_custom_type.<locals>.<lambda>r  rH  )ry   r   r   r&   r-   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
        rs   c                 S  r  r*   )r  tupler  r   r   r   ra     r  zNValidatorTestMixin.test_it_properly_formats_tuples_in_errors.<locals>.<lambda>r  uniqueItemsT)r9   r9   Nz(1, 1) has non-unique elements)r   r   r&   r-   r  r   r   r   r   rf   strr  )r(   TupleValidatorr@  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
        rs   T)rn   r  	MyMappingza, bc                 S  s   t |ttfS r*   )r  r2   r   r  r   r   r   ra         zBValidatorTestMixin.test_check_redefined_sequence.<locals>.<lambda>c                   s   t |t fS r*   )r  r$   r  r  r   r   ra     r  )rs   ry   r  )rO   Nr  r\   TFr   rO   )rO   r  rO   N)r   r   r   r&   r-   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_sequenceN)rI   r   rJ   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                   @  sL   e Zd ZdZdd Zdd Zeeddd Z	eed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   rf   r  r  r(   r@  r   r   r   test_True_is_not_a_schema     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_schemai  c                 C  ^   t di }| t}| jd|dd W d    n1 s w   Y  | |jtj	 d S )Nr\   Trw  rv   
r   rz  r   	Exceptionr&   r   assertNotIsInstancer  r   r   r(   rx  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  )Nr\   Frw  rv   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)rI   r   rJ   __doc__r  r  unittestskipr   r  r  r   r   r   r   r    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  rn   ru   r{   c                 C  s   |  ddi}|t  d S Nrn   any)r&   r   ry   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   ra     r  zBTestDraft3Validator.test_any_type_is_redefinable.<locals>.<lambda>r  rn   rv   r{   N)	r   r   r&   r-   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  ry   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 )NTrt   rn   r  )r|   r&   ro   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)rI   r   rJ   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  rn   ru   r{   N)	rI   r   rJ   r   r   r&   r  r  r  r   r   r   r   r       
 r  c                   @  r  )TestDraft6Validatorr  r  rn   ru   r{   N)	rI   r   rJ   r   r   r&   r  r  r  r   r   r   r   r
  #  r	  r
  c                   @  r  )TestDraft7Validatorr  r  rn   ru   r{   N)	rI   r   rJ   r   r   r&   r  r  r  r   r   r   r   r  )  r	  r  c                   @  r  )TestDraft201909Validatorr  r  rn   ru   r{   N)	rI   r   rJ   r   Draft201909Validatorr&   r  r  r  r   r   r   r   r  /  r	  r  c                   @  r  )TestDraft202012Validatorr  r  rn   ru   r{   N)	rI   r   rJ   r   r   r&   r  r  r  r   r   r   r   r  5  r	  r  c                   @  s   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  rY  r\   Fru  rw  )r   rz  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)rI   r   rJ   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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#)r=  r   validator_forr   r/   r   r   r   test_draft_3K     zTestValidatorFor.test_draft_3c                 C  r  )Nr   &http://json-schema.org/draft-04/schema'http://json-schema.org/draft-04/schema#)r=  r   r  r   r/   r   r   r   test_draft_4X  r  zTestValidatorFor.test_draft_4c                 C  r  )Nr   &http://json-schema.org/draft-06/schema'http://json-schema.org/draft-06/schema#)r=  r   r  r   r/   r   r   r   test_draft_6e  r  zTestValidatorFor.test_draft_6c                 C  r  )Nr   &http://json-schema.org/draft-07/schema'http://json-schema.org/draft-07/schema#)r=  r   r  r   r/   r   r   r   test_draft_7r  r  zTestValidatorFor.test_draft_7c                 C  r  )Nr   z,https://json-schema.org/draft/2019-09/schemaz-https://json-schema.org/draft/2019-09/schema#)r=  r   r  r  r/   r   r   r   test_draft_201909  r  z"TestValidatorFor.test_draft_201909c                 C  r  )Nr   ,https://json-schema.org/draft/2020-12/schema-https://json-schema.org/draft/2020-12/schema#)r=  r   r  r   r/   r   r   r   test_draft_202012  r  z"TestValidatorFor.test_draft_202012c                 C     |  tdtj d S )NTr=  r   r  r   r'   r   r   r   	test_True     zTestValidatorFor.test_Truec                 C  r%  r   r&  r'   r   r   r   
test_False  r(  zTestValidatorFor.test_Falsec                 C  s6   t jddiddd d}ddi}| t || d S )NrV   rY   12c                 S  rZ   r[   r]   r_   r   r   r   ra     rb   z8TestValidatorFor.test_custom_validator.<locals>.<lambda>rc   r   r   r%   r=  r  r(   r&   r   r   r   r   test_custom_validator  s   z&TestValidatorFor.test_custom_validatorc                 C  s0   t jddidd}ddi}| t || d S )Nr   rk   13rE   r   r+  r,  r   r   r   test_custom_validator_draft6  s   z-TestValidatorFor.test_custom_validator_draft6c                 C  s   |  ti tj d S r*   r&  r'   r   r   r   %test_validator_for_jsonschema_default  r  z6TestValidatorFor.test_validator_for_jsonschema_defaultc                 C  s   |  tji d dd  d S )Nr  )r=  r   r  r'   r   r   r   !test_validator_for_custom_default  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   r  r"   filename__file__r  warning)r(   r  r   r   r   1test_warns_if_meta_schema_specified_was_not_found  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   r  r>  )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)ry   r=  r   r  )r(   r   r  r   r   r   -test_validator_for_custom_default_with_schema  s   z>TestValidatorFor.test_validator_for_custom_default_with_schemaN)rI   r   rJ   r  r  r  r   r!  r$  r'  r)  r-  r/  r0  r1  r6  r=  r>  r   r   r   r   r  J  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S )TestValidatec                 C  sT   g }t j|d|j ti | W d    n1 sw   Y  | ||g d S )Nr   )r	   patchry   appendr   r   r"   )r(   r   r&   resultr   r   r   
assertUses  s
   zTestValidate.assertUsesc                 C  ,   | j dditjd | j dditjd d S )Nr   r  r   r&   r  )rC  r   r   r'   r   r   r   test_draft3_validator_is_chosen     
z,TestValidate.test_draft3_validator_is_chosenc                 C  rD  )Nr   r  rE  r  )rC  r   r   r'   r   r   r   test_draft4_validator_is_chosen  rG  z,TestValidate.test_draft4_validator_is_chosenc                 C  rD  )Nr   r  rE  r  )rC  r   r   r'   r   r   r   test_draft6_validator_is_chosen  rG  z,TestValidate.test_draft6_validator_is_chosenc                 C  rD  )Nr   r  rE  r  )rC  r   r   r'   r   r   r   test_draft7_validator_is_chosen  rG  z,TestValidate.test_draft7_validator_is_chosenc                 C  rD  )Nr   r#  rE  r"  rC  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 )NrE  rK  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 )Nrv   rn   rz   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 )Nrv   rn   z3(?s)Failed validating '.*' in metaschema.*On schema)r   r   r   r   r   rN  r  r  r  r   r   r   test_schema_error_message&  rP  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 )	Nr  rx   r1  r^  rn   rs   rv   z!12 is less than the minimum of 20)r   r   r   r   r   rf   r  r  )r(   r   r@  r   r   r   test_it_uses_best_match.  s   z$TestValidate.test_it_uses_best_matchN)rI   r   rJ   rC  rF  rH  rI  rJ  rL  rM  rO  rQ  rR  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#S )$TestRefResolverr\   zfoo://storedstoredr   c                 C  s.   i | _ | j| ji| _t| j| j | j| _d S r*   )referrer
stored_uristored_schemarv  r   rz  base_urirx  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 )NrV   resolve_remote)r   r   r,   r	   r@  ry   rx  r  r"   r>  called)r(   r{  patchedresolvedr   r   r   6test_it_does_not_retrieve_schema_urls_from_the_networkG  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(  )ry   rU  rx  r  r"   )r(   r{  r\  r   r   r   test_it_resolves_local_refsO  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   )rV   rO   c                 S  rZ   r[   r]   r   r   r   r   ra   Y  rb   zETestRefResolver.test_it_resolves_local_refs_with_id.<locals>.<lambda>rd   z#/arO   zhttp://bar/schema#/a)r   rz  from_schemar  r"   r(   r   rx  r\  r   r   r   #test_it_resolves_local_refs_with_idU  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{   rv   
cached_refzcached_ref#/foo)rx  r  rV  r=  rW  rv  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  rv   requests
http://bar)sysmodulesr!   __setitem__ReallyFakeRequestsrx  r  r"   )r(   r{  r   r\  r   r   r   ,test_it_retrieves_unstored_refs_via_requestsh  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 )Nre  r  rv   rf  c                 3  s(     | d tt dV  d S )Nrg  utf8)r"   r   jsondumpsencodeurlr   r(   r   r   fake_urlopen  s   zQTestRefResolver.test_it_retrieves_unstored_refs_via_urlopen.<locals>.fake_urlopenurlopen)rh  ri  r!   rj  r   setattrr   ru  rx  r  r"   )r(   r{  rt  r\  r   rs  r   +test_it_retrieves_unstored_refs_via_urlopenu  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}| j
|}| |d W d    d S 1 sGw   Y  d S )NFwt)deletemoder{   r   zfile://{}#foo)tempfileNamedTemporaryFiler!   osremover   rn  dumpr   r
   rx  r  r"   )r(   tempfr{  r\  r   r   r   (test_it_retrieves_local_refs_via_urlopen  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 )	NrV   r{   c                 S  rZ   r[   r]   r   r   r   r   ra     rb   zPTestRefResolver.test_it_can_construct_a_base_uri_from_a_schema.<locals>.<lambda>r_  r\   #zfoo#r   rz  r`  r"   rX  resolution_scoper  ra  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  ra  r   r   r   9test_it_can_construct_a_base_uri_from_a_schema_without_id  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  rq  r{  r   r(   r   r   handler  s   z@TestRefResolver.test_custom_uri_scheme_handlers.<locals>.handlerr{   r   	foo://barr\   handlers)r   rz  r  r"   )r(   r  rx  r\  r   r  r   test_custom_uri_scheme_handlers  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!rH   
IndexErrorr   rq  responser(   r   r   r    
   
z5TestRefResolver.test_cache_remote_on.<locals>.handlerr  r\   Tr{   cache_remoter  ry   r   rz  r  r(   r  r{  rx  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  rq  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   rq  rh  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   rz  r   r   RefResolutionErrorr  r   r"   r  )r(   r  r{  rx  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   rz  	pop_scoper   r   r  rf   r  r  )r(   rx  excr   r   r   .test_helpful_error_message_on_failed_pop_scope  s   
z>TestRefResolver.test_helpful_error_message_on_failed_pop_scopeN)rI   r   rJ   rX  rV  rW  r)   r]  r^  rb  rd  rl  rw  r  r  r  r  r  r  r  r  r   r   r   r   rS  :  s&    	
rS  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  rp   r@  r   r   r   r        z.sorted_errors.<locals>.key.<locals>.<listcomp>c                 S  r  r   r  r  r   r   r   r    r  )r5  r8   r  r   r   r   key  s   zsorted_errors.<locals>.key)r  )sorted)r   r  r   r   r   r<    s   r<  c                   @     e Zd Ze Zdd ZdS )rk  c                 C  s2   | j |}|d u rtdt| tt|S )NzUnknown URL: )
_responsesr^   r  rM   _ReallyFakeJSONResponsern  ro  )r(   rr  r  r   r   r   r^     s   zReallyFakeRequests.getN)rI   r   rJ   r  r  r  r^   r   r   r   r   rk        rk  c                   @  r  )r  c                 C  s   t | jS r*   )rn  loads	_responser'   r   r   r   rn  	  s   z_ReallyFakeJSONResponse.jsonN)rI   r   rJ   r  r  r  rn  r   r   r   r   r  	  r  r  )4
__future__r   collectionsr   r   
contextlibr   decimalr   ior   r  r   r	   urllib.requestr
   rn  r}  rh  r{  r9  r  
jsonschemar   r   r   r   r   jsonschema.tests._helpersr   r   r   r   r/  r  ry   r  r  r  r  r
  r  r  r  r  r  r?  rS  r<  r`   rk  r  r   r   r   r   <module>   sf     t         8 t  a 8	