o
    miW                    @  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schemaZeachr   r   Z/home/kim/smarthome/.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   Z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   r4   r5   r$   lenZ	_contents)r+   r   r   Z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   ZFirstzSecond!Zasdf)r   r   ZThirdr8      )r)   r4   r5   r$   r<   r6   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!   versionZ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    r@   rA   rB   z2MyVersionValidator(schema={}, format_checker=None))r   r(   r#   r%   rD   r'   r$   reprrG   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    r@   rA   rB   ai  zNMyVersionValidator(schema={'a': [0, 1, 2, 3, 4, 5, ...]}, format_checker=None))
r   r(   r#   r%   rD   r'   r$   rI   r4   rangerG   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$   rI   rG   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    r@   zfoo-barrB   ZFooBarValidator)r   r(   r#   r%   rD   r'   r$   rF   rG   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idrN   )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 idrQ   rA   c                 S     |  ddS NrQ    getsr   r   r   <lambda>       zMTestCreateAndExtend.test_validates_registers_meta_schema_id.<locals>.<lambda>r!   rC   id_ofr   r(   r#   r%   rD   r'   assertInr+   Zmeta_schema_keyZ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    rA   rB   r`   rb   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).0rg   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   rj   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notrN   rt   barN)	r   r(   Draft202012Validatorr/   check_schemaassertRaisesr   SchemaErrorvalidater+   Z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!rf   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.   rr   r   extendr$   r/   r0   )r+   rR   r   Z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__)rY   r)   ID_OFr   r*   r   r   r_        z3TestCreateAndExtend.test_extend_idof.<locals>.id_ofzthe://correct/id/zthe://wrong/id/)r    r   )r!   r   r"   r_   N)r   r(   r"   r$   r   r/   r   )r+   r_   Z
correct_idr!   Z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.
        testrg   rq   z#/$defs/testr;   )$defs$refmaximum%   N)r   Draft4Validatorru   is_validr   )r+   r   Zdraft4r   r   r   r   !test_extend_applicable_validators   s   

z5TestCreateAndExtend.test_extend_applicable_validatorsN)rE   
__module__rF   r,   r1   r3   r7   r=   r?   rH   rJ   rM   rO   rP   rS   rc   re   rw   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   )
rD   r   _LATEST_VERSIONr}   r4   r5   ru   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;   rg   rs   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)rs   rr   r;   rg   r   z#1 is not of type 'string', 'object')r   r4   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 )Nrg   ZFoor>   )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{   rt   dependenciesr{   r   r   z'foo' is a dependency of 'bar'r   r+   Z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 )Nrg   r   r>   r;   r   z+1 is not of type {'type': [{'minimum': 3}]}r   )r+   rg   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itemsZadditionalItemsr   z(2 was unexpected)r   r   r   ra   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   r>   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 )Nrt   additionalPropertiesFr   r   z('foo' was unexpected)r   ra   )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   Frt   r{   r   zwere unexpected))r   r&   fromkeysra   rI   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 )Nrx   ro   rt   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containsrx   ro   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   r\     s    zQTestValidationErrorMessages.test_invalid_format_default_message.<locals>.<lambda>formatZbla)r   r   format_checkerzis not a)r   checksr   ra   rI   )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 )Nrr   Frg   rs   )^abc$^def$)rg   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   rI   r   r   r   r   1test_additionalProperties_false_patternProperties  s8   zMTestValidationErrorMessages.test_additionalProperties_false_patternPropertiesc                 C  s   | j ddd}| |d d S )Nr@   Fr   z'False schema does not allow 'something'r   r   r   r   r   test_False_schema  s
   z-TestValidationErrorMessages.test_False_schemac                 C  r   )Nr>   Z
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   )NrW   	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   )NrW   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)rK   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   rt   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   rt      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   rg   rs   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 )	Nrt   r;   rg   rs   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 )
Nrt   r;   rg   rs   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rt   r{   bazrg   rs   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 )
Nrt   r  rg   rs   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   )Nr>   Z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   )Nr>   Z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requiredrt   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 )Nrt   ZdependentRequiredr{   r   z'bar' is a dependency of 'foo'r   r   r   r   r   test_dependentRequired  s
   z2TestValidationErrorMessages.test_dependentRequiredc                 C  r  )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 )Nr  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 )Nrl   Frg   unevaluatedItemsrt   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 )Nrl   Fr!  rt   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 )Nrt   rg   rs   rx   ro   
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 )	Nrr   Frg   r)  rt   r{   rt   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$  )Nrr   Fr+  rt   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   rt   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  r/  )NFr0  r3  r   z6Expected at most 1 item but found 2 extra: ['bar', 37]r   r   r   r   r   $test_heterogeneous_items_prefixItems   r2  z@TestValidationErrorMessages.test_heterogeneous_items_prefixItemsc                 C  r/  )NF)r   r"  r3  r   z=Unevaluated items are not allowed ('bar', 37 were unexpected)r   r   r   r   r   /test_heterogeneous_unevaluatedItems_prefixItems  r2  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.
        rt   F)r(  r   r  ro   rt   rK   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  r7  )
r8  rt   Fr'  r  ro   r9  r   z@Unevaluated properties are not allowed (37, 'a' were unexpected)Nr   r   r   r   r   3test_heterogeneous_properties_unevaluatedProperties$  r;  zOTestValidationErrorMessages.test_heterogeneous_properties_unevaluatedPropertiesN)=rE   r   rF   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*  r-  r.  r1  r4  r5  r6  r:  r<  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      rg   rs   r;   r   $r   )r>  r   r   )r>  r;   rg   )r   r   r4   r5   r$   r<   r   r9   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 )Nrt   r;   rg   rn   rr   enumr   rg   r(  r   r@  )rg   r   rg   $.foo)r;   r(  rt   rR  )rg   r;   r(  rt   rR  )r   r   r4   r5   r$   r<   r   r9   r   r   rA  rB  rC  r   rD  rE  rF  r:   rG  rH  rI  rJ  rK  rL  rM  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;      Zspam)rt   r{   r  quuxr(  rg   rs   r   
   )r   r        )r   rR  r  r{   r  rt   $.barz$.bazrT  rR  r   )r   r   r5   rJ  r$   rC  r   rD  rE  rF  r   )	r+   r   r   r   r   rO  rP  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  r,  rW  rs   rr   rR  r>   rl   r  Tr   )r{   r  rS  )rg   r   r   r{   )r;   r{   r{   )r;   r{   r  rt   r@  $[0]z$[1].barz$[1].bar.barz$[1].bar.bazz$[1].foorg   r   )r   r(  r{   rg   )r   r(  r{   r(  r{   r  )r   r(  r{   r(  r  r   )r   r(  rt   rR  )r   r   r5   rJ  r$   rC  r   rF  r:   r4   r   )r+   r   r   r   r   rO  rP  r\  r]  Ze5Z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noder>  rr   r   childrenrg   rs   ^.*$r   z#/definitions/node)rg   r   )r   rb  )rg   r  r(  root)definitionsrg   r  r(  rK   ab)r(  rd  r>  z$.root)rd  rb  rK   )	r(  rd  r>  r   r(  rb  r   rc  r>  z$.root.children.a)rd  rb  rK   rb  rf  )r(  rd  r>  r   r(  rb  r   rc  r>  r   r(  rb  r   rc  r>  z$.root.children.a.children.ab)	r   r   r5   r$   rE  r   rH  rF  rI  )r+   r   r   r   rN  rO  rP  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   rn   r  rg   r   rt   r[  rT  rg   r   	r   r   r5   rJ  r$   rC  r   rF  r   r+   r   r   r   r   rO  rP  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   rg   rs   r   r  r{   rt   r[  rT  ri  rj  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 )Nrt   r;   rn   r  rh  r   r   r_  $[1]rg   r   ri  rj  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)rt   r{   r;   rn   r  rh  r   r;   r   rm  z$[2]rg   r   ri  rj  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 )Nrt   ro   ZpropertyNamesrz   rx   z0'foo' should not be valid under {'const': 'foo'}r@  
r   r   r5   r$   r   r   rC  r   rF  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 )Nrx   ro      )ifthen13 was expectedr@  ru  rp  r+   r   r   rq  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 )	Nrx   ro   rs  )rt  elserV  rv  r@  rz  rp  rw  r   r   r   test_if_else  ry  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 )NFro   zFalse schema does not allow 12r@  )r   r   r5   r$   r   r   r9   r   r   r:   rF  r   )r+   r   rq  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 )NZsomeRefr   rg   rn   r   rW   storeresolverrt   ZnotAnIntegerz''notAnInteger' is not of type 'integer'rT  )r   r   _RefResolverr5   r$   r   r   r9   r   rE  r   r:   rF  r   )r+   refr   r   rq  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   rg   rs   r   r>   r  r   r;   r   )r   r   rg   r_  z"5 is greater than the maximum of 3r  )r   r>   r   $[3]r   r|   r5   r$   r   r   r9   r   rE  r   r:   rF  r   )r+   r   r   Z
type_errorZ	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 )Nrg   rs   r   )rt   r   r{   r  r  z2 is not of type 'string'r   r;   r   rm  z4 is not of type 'string'r  r>   r  r  r+   r   r   rO  rP  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.
        rg   rs   r   r  )rt   r   r{   r  r  rW  r  r  r   r@  Nr  rw  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 )
Nrg   rs   r   r
  )rt   r   r  r  r  r   r@  r  rw  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 )	Nrg   rs   r   r
  r  z7[2, 4] does not contain items matching the given schemar   r@  r  rw  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 )Nrt   r  r{   apropz#/$defs/foor  )r   r  )r   r(  z'bar' is a required property)r(  r  r  z$.apropz'baz' is a required property)r   r|   r5   r$   r   r   r9   r   rE  r   r:   rG  rF  r   r  r   r   r   test_ref_sibling  sj   






z+TestValidationErrorDetails.test_ref_siblingN)rE   r   rF   rQ  rU  r^  r`  rg  rk  rl  rn  ro  rr  rx  r{  r|  r  r  r  r  r  r  r  r   r   r   r   r=  3  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(  ro   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.
        rR  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.
        rR  ro   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)	rE   r   rF   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-   )validru   r)   r   r+   r   r   r   r   r   test_valid_instances_are_valid~     
z1ValidatorTestMixin.test_valid_instances_are_validc                 C  r  r-   )invalidrL  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)   rr   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 )Nrg   rn   r  rs   )r   r   )r   	_resolver)r   r)   evolveZFORMAT_CHECKERr  r$   ZassertNotEqual)r+   r   r   rR   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   r\     s    zCValidatorTestMixin.test_evolve_with_subclass.<locals>.OhNo.<lambda>)factoryr   defaultN)rE   r   rF   r   rt   _barr   r   r   r   OhNo  s    r  Nro   )r{   r   rg   rn   r   )assertWarnsDeprecationWarningr   r)   r$   rt   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 )Nrt   rs   )ru   r)   rh   r*   r   r   r   #test_is_type_is_true_for_valid_type     z6ValidatorTestMixin.test_is_type_is_true_for_valid_typec                 C  r  )Nrt   rl   rL  r)   rh   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 )NTrn   rq   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   rg   rq   c                 S  s   t |tttfot |t S r-   )
isinstanceintfloatr   boolr   r   r   r   r   r\     s    
zGValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<lambda>r"   r;   g?rZ  rt   Tc                 S  s   g | ]}|j qS r   r  )ri   rq  r   r   r   
<listcomp>  s    zIValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<listcomp>)	r   r   r)   r0   redefiner   r   r$   r5   )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)   rA  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!rt   )Z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   rK  	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 )Nrg   c                 S  
   t |tS r-   r  r  r  r   r   r   r\        
 z@ValidatorTestMixin.test_non_string_custom_type.<locals>.<lambda>r  rV  )rr   r   r   r)   r0   r  r   )r+   Z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
        rl   c                 S  r  r-   )r  tupler  r   r   r   r\     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)   r0   r  r~   r   r   r   ra   strr  )r+   ZTupleValidatorrN  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
        rl   T)rg   r  	MyMappingza, bc                 S  s   t |ttfS r-   )r  r4   r   r  r   r   r   r\         zBValidatorTestMixin.test_check_redefined_sequence.<locals>.<lambda>c                   s   t |t fS r-   )r  r&   r  r  r   r   r\     r  )rl   rr   r  )rK   Nr  rW   TFr   rK   )rK   r   rK   N)r   r   r   r)   r0   Zredefine_manyr   r   r~   r   r   )r+   r   r)   r   Zvalid_instancesr   Z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someCoolRefrg   rn   rW   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 refrg   rn   r$   )thisr  r*   r   r   	resolvingh  s   zxValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolvers.<locals>.LegacyRefResolver.resolvingN)rE   r   rF   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)rE   r   rF   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}   ra   r  r  r+   rN  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 )NTro   r~   	Exceptionr)   r   Z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  )NFro   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)rE   r   rF   __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  rg   rn   rt   c                 C  s   |  ddi}|t  d S Nrg   any)r)   r   rr   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   r\     r  zBTestDraft3Validator.test_any_type_is_redefinable.<locals>.<lambda>r  rg   ro   rt   N)	r   r   r)   r0   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  )ru   r)   r   rr   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 )NTrm   rg   r  )ru   r)   rh   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)rE   r   rF   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  rg   rn   rt   N)	rE   r   rF   r   r   r)   r  r  r  r   r   r   r   r       
 r  c                   @  r  )TestDraft6Validatorr  r  rg   rn   rt   N)	rE   r   rF   r   r   r)   r  r  r  r   r   r   r   r    r   r  c                   @  r  )TestDraft7Validatorr  r  rg   rn   rt   N)	rE   r   rF   r   r   r)   r  r  r  r   r   r   r   r    r   r  c                   @  r  )TestDraft201909Validatorr  r  rg   rn   rt   N)	rE   r   rF   r   Draft201909Validatorr)   r  r  r  r   r   r   r   r    r   r  c                   @  r  )TestDraft202012Validatorr  r  rg   rn   rt   N)	rE   r   rF   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   rW   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)rE   r   rF   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 )Nry   &http://json-schema.org/draft-03/schema'http://json-schema.org/draft-03/schema#)rK  r   validator_forr   r2   r   r   r   test_draft_3     zTestValidatorFor.test_draft_3c                 C  r
  )Nry   &http://json-schema.org/draft-04/schema'http://json-schema.org/draft-04/schema#)rK  r   r  r   r2   r   r   r   test_draft_4  r  zTestValidatorFor.test_draft_4c                 C  r
  )Nry   &http://json-schema.org/draft-06/schema'http://json-schema.org/draft-06/schema#)rK  r   r  r   r2   r   r   r   test_draft_6  r  zTestValidatorFor.test_draft_6c                 C  r
  )Nry   &http://json-schema.org/draft-07/schema'http://json-schema.org/draft-07/schema#)rK  r   r  r   r2   r   r   r   test_draft_7  r  zTestValidatorFor.test_draft_7c                 C  r
  )Nry   z,https://json-schema.org/draft/2019-09/schemaz-https://json-schema.org/draft/2019-09/schema#)rK  r   r  r  r2   r   r   r   test_draft_201909  r  z"TestValidatorFor.test_draft_201909c                 C  r
  )Nry   ,https://json-schema.org/draft/2020-12/schema-https://json-schema.org/draft/2020-12/schema#)rK  r   r  r|   r2   r   r   r   test_draft_202012  r  z"TestValidatorFor.test_draft_202012c                 C     |  tdtj d S )NTrK  r   r  r   r*   r   r   r   	test_True*     zTestValidatorFor.test_Truec                 C  r  r   r  r*   r   r   r   
test_False0  r   zTestValidatorFor.test_Falsec                 C  s6   t jddiddd d}ddi}| t || d S )NrQ   rT   Z12c                 S  rU   rV   rX   rZ   r   r   r   r\   :  r]   z8TestValidatorFor.test_custom_validator.<locals>.<lambda>r^   ry   r   r(   rK  r  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    rd   Z13rB   ry   r"  r#  r   r   r   test_custom_validator_draft6B  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_defaultM  r  z6TestValidatorFor.test_validator_for_jsonschema_defaultc                 C  s   |  tji d dd  d S )Nr  )rK  r   r  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 )Nry   Z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_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   r  rL  )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 )Nry   zmailto:foo@example.com)rr   rK  r   r  )r+   r   r  r   r   r   -test_validator_for_custom_default_with_schemae  s   z>TestValidatorFor.test_validator_for_custom_default_with_schemaN)rE   r   rF   r  r  r  r  r  r  r  r!  r$  r%  r&  r'  r+  r3  r4  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S )TestValidatec                 C  sT   g }t j|d|j ti | W d    n1 sw   Y  | ||g d S )Nr}   )r
   patchrr   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 )Nry   r  r   r)   r  )r9  r   r   r*   r   r   r   test_draft3_validator_is_chosenq     
z,TestValidate.test_draft3_validator_is_chosenc                 C  r:  )Nry   r  r;  r  )r9  r   r   r*   r   r   r   test_draft4_validator_is_chosen|  r=  z,TestValidate.test_draft4_validator_is_chosenc                 C  r:  )Nry   r  r;  r  )r9  r   r   r*   r   r   r   test_draft6_validator_is_chosen  r=  z,TestValidate.test_draft6_validator_is_chosenc                 C  r:  )Nry   r  r;  r  )r9  r   r   r*   r   r   r   test_draft7_validator_is_chosen  r=  z,TestValidate.test_draft7_validator_is_chosenc                 C  r:  )Nry   r  r;  r  r9  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 )Nr;  rA  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 )Nro   rg   rs   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 )Nro   rg   z3(?s)Failed validating '.*' in metaschema.*On schema)r~   r   r   r   r   rD  r  r  r  r   r   r   test_schema_error_message  rF  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  rq   r?  rh  rg   rl   ro   z!12 is less than the minimum of 20)r~   r   r   r   r   ra   r  r  )r+   r   rN  r   r   r   test_it_uses_best_match  s   z$TestValidate.test_it_uses_best_matchN)rE   r   rF   r9  r<  r>  r?  r@  rB  rC  rE  rG  rH  r   r   r   r   r5  j  s    r5  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   r7  sysexc_infor   failedr   r   r     s   zFTestThreading.test_validation_across_a_second_thread.<locals>.validater   )Thread)targetF)	threadingrN  startjoinr$   is_alive)r+   r   rN  threadr   rL  r   &test_validation_across_a_second_thread  s   
z4TestThreading.test_validation_across_a_second_threadN)rE   r   rF   r  rU  r   r   r   r   rI    s    rI  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 )Nrg   rn   )r   Zcreate_resourceurir   r   r   retrieve  s   z=TestReferencing.test_registry_with_retrieve.<locals>.retrieve)rY  r   https://example.com/registryro   rt   )TF)referencingRegistryr   r|   r$   r   )r+   rY  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   rZ  r[  Tr,  r.  ro   )r]  r^  r   r|   r/  r0  r1  r~   r   ZUnresolvabler   rL  )r+   r\  r   r   r2  r   r   r   ;test_custom_registries_do_not_autoretrieve_remote_resources  s   
zKTestReferencing.test_custom_registries_do_not_autoretrieve_remote_resourcesN)rE   r   rF   r_  r`  r   r   r   r   rV    s    rV  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 )*TestRefResolverrW   zfoo://storedZ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 )NrQ   Zresolve_remote)r   r   r/   r
   r6  rr   r  r  r$   rL  Zcalled)r+   r  Z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/foort   r(  )rr   rb  r  r  r$   )r+   r  rf  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#rt   r{   )rQ   rK   c                 S  rU   rV   rX   r   r   r   r   r\   #	  r]   zETestRefResolver.test_it_resolves_local_refs_with_id.<locals>.<lambda>r_   z#/arK   zhttp://bar/schema#/a)r   r  from_schemar  r$   r+   r   r  rf  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 )Nrt   ro   Z
cached_refzcached_ref#/foo)r  r  rc  rK  rd  r~  r$   )r+   rf  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  ro   requests
http://bar)rJ  modulesr#   __setitem__ReallyFakeRequestsr  r  r$   )r+   r  r   rf  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jd|d j|}W d    n1 s>w   Y  W d    n1 sMw   Y  	|d d S )	Nrn  r  ro   ro  c                 3  s(     | d tt dV  d S )Nrp  utf8)r$   r   jsondumpsencodeurlr   r+   r   r   fake_urlopenI	  s   zQTestRefResolver.test_it_retrieves_unstored_refs_via_urlopen.<locals>.fake_urlopenzurllib.request.urlopenr   )
rJ  rq  r#   rr  r   r
   r6  r  r  r$   )r+   r  r|  rf  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 )NFZwt)deletemodert   r{   zfile://z#foo)tempfileNamedTemporaryFiler#   osremover   rv  dumpr   r  r  r$   )r+   Ztempfr  rf  r   r   r   (test_it_retrieves_local_refs_via_urlopenS	  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 )	NrQ   rt   c                 S  rU   rV   rX   r   r   r   r   r\   `	  r]   zPTestRefResolver.test_it_can_construct_a_base_uri_from_a_schema.<locals>.<lambda>ri  rW   #zfoo#r   r  rj  r$   re  Zresolution_scoper  rk  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 )NrW   r  r  rk  r   r   r   9test_it_can_construct_a_base_uri_from_a_schema_without_idm	  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  ry  r  r   r+   r   r   handlerx	  s   z@TestRefResolver.test_custom_uri_scheme_handlers.<locals>.handlerrt   r{   	foo://barrW   handlers)r   r  r  r$   )r+   r  r  rf  r   r  r   test_custom_uri_scheme_handlersw	  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!rD   
IndexErrorr   ry  responser+   r   r   r  	  
   
z5TestRefResolver.test_cache_remote_on.<locals>.handlerr  rW   Trt   Zcache_remoter  rr   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  ry  r  r   r   r  	  r  z6TestRefResolver.test_cache_remote_off.<locals>.handlerr  rW   Frt   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   ry  rq  r   r   r  	  s   zTTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_error.<locals>.handlerr  rW   rt   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 )NrW   zFailed to pop the scope)	r   r  Z	pop_scoper~   r   r  ra   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.
        rW   r  r   rt   ZallOfr   r    N)r   r   r/   r  rL  r   )r+   r   oner   Z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/foorg   rn   r  rW  r*   r   r   handle	  s   zNTestRefResolver.test_newly_created_validator_with_ref_resolver.<locals>.handlerW   httpr  rf   zhttp://example.com/barrt   )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/xrg   rn   )r(  re  rW   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)rE   r   rF   re  rc  rd  r,   rg  rh  rl  rm  rt  r}  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   ra  	  s,    	
ra  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  ri   rN  r   r   r   r  	      z.sorted_errors.<locals>.key.<locals>.<listcomp>c                 S  r  r   r  r  r   r   r   r  	  r  )rC  r:   r  r   r   r   key	  s   zsorted_errors.<locals>.key)r  )sorted)r   r  r   r   r   rJ  	  s   rJ  c                   @     e Zd ZU ded< dd ZdS )rs  zdict[str, Any]
_responsesc                 C  s2   | j |}|d u rtdt| tt|S )NzUnknown URL: )r  rY   r  rI   _ReallyFakeJSONResponserv  rw  )r+   rz  r  r   r   r   rY    
  s   zReallyFakeRequests.getN)rE   r   rF   r  rY   r   r   r   r   rs  	     
 rs  c                   @  r  )r  r  	_responsec                 C  s   t | jS r-   )rv  loadsr  r*   r   r   r   rv  
  s   z_ReallyFakeJSONResponse.jsonN)rE   r   rF   r  rv  r   r   r   r   r  
  r  r  ):
__future__r   collectionsr   r   
contextlibr   decimalr   ior   typingr   Zunittestr	   r
   urllib.requestr   rv  r  rJ  r  r/  attrsr   r   Zreferencing.jsonschemar   Zreferencing.exceptionsr]  Z
jsonschemar   r   r   r   r   r   r   r   r=  r  r  r  r  r  r  r  r  r  r  r	  r5  rI  rV  ra  rJ  rs  r  r   r   r   r   <module>   sp    	            8 {  a o	