U
    kufW                    @  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f |V  qd S )NmessagezYou told me to fail!)
setdefaultr   ValidationError)	validatorerrorsinstanceschemaZeach r   D/tmp/pip-unpacked-wheel-k94ccfep/jsonschema/tests/test_validators.pyfail   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 )*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   r3   r4   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Thirdr7      )r(   r3   r4   r#   r;   r5   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?   r@   rA   z2MyVersionValidator(schema={}, format_checker=None))r   r'   r"   r$   rC   r&   r#   reprrF   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?   r@   rA   ai  zNMyVersionValidator(schema={'a': [0, 1, 2, 3, 4, 5, ...]}, format_checker=None))
r   r'   r"   r$   rC   r&   r#   rH   r3   rangerF   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#   rH   rF   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-barrA   ZFooBarValidator)r   r'   r"   r$   rC   r&   r#   rE   rF   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idrM   )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 idrP   r@   c                 S  s   |  ddS NrP    getsr   r   r   <lambda>       zMTestCreateAndExtend.test_validates_registers_meta_schema_id.<locals>.<lambda>r    rB   id_ofr   r'   r"   r$   rC   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   r@   rA   r^   r`   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).0re   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   rh   r   test_create_default_types   s    z-TestCreateAndExtend.test_create_default_typesc              	   C  sd   t jt jjd di idd}|ddi | tj |i  W 5 Q R X |ddid dS )zq
        One can create a validator class whose metaschema uses a different
        dialect than itself.
        r   const)$schemanotrM   rr   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  sB   t jdddigidtid}| tj |i  W 5 Q R X 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!rd   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-   rp   r   extendr#   r.   r/   )r*   rQ   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__)rW   r(   ID_OFr   r)   r   r   r]     s    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.
        testre   ro   z#/$defs/testr:   )$defs$refmaximum%   N)r   Draft4Validatorrs   is_validr   )r*   r   Zdraft4r   r   r   r   !test_extend_applicable_validators   s    

z5TestCreateAndExtend.test_extend_applicable_validatorsN)rD   
__module__rE   r+   r0   r2   r6   r<   r>   rG   rI   rL   rN   rO   rR   ra   rc   ru   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  sn   | dtj}|| ||f||}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   )
rC   r   _LATEST_VERSIONr{   r3   r4   rs   r#   r;   r   )r*   r   r   argskwargsr   r   r   r   r   r   message_for3  s    
z'TestValidationErrorMessages.message_forc                 C  s"   | j dddid}| |d d S Nr:   re   rq   r   r   1 is not of type 'string'r   r#   r*   r   r   r   r   test_single_type_failure@  s    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  s    z9TestValidationErrorMessages.test_single_type_list_failurec                 C  s*   d}| j ddt|id}| |d d S )N)rq   rp   r:   re   r   z#1 is not of type 'string', 'object')r   r3   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 )Nre   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  s"   | j dddid}| |d d S )Nr:   r      r   z1 is less than the minimum of 2r   r   r   r   r   test_minimumV  s    z(TestValidationErrorMessages.test_minimumc                 C  s"   | j dddid}| |d d S )Nr:   r   r   r   z"1 is greater than the maximum of 0r   r   r   r   r   test_maximumZ  s    z(TestValidationErrorMessages.test_maximumc                 C  s:   d\}}d||ii}| j ddi|tjd}| |d d S Nry   rr   Zdependenciesry   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 )Nre   r   r=   r:   r   z+1 is not of type {'type': [{'minimum': 3}]}r   )r*   re   r   r   r   r   -test_object_without_title_type_failure_draft3h  s    zITestValidationErrorMessages.test_object_without_title_type_failure_draft3c                 C  s<   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  s    z9TestValidationErrorMessages.test_dependencies_list_draft3c                 C  s<   d\}}d||gii}| j ddi|tjd}| |d d S r   r   r   Draft7Validatorr#   r   r   r   r   test_dependencies_list_draft7~  s    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   r_   r   r   r   r   #test_additionalItems_single_failure  s    z?TestValidationErrorMessages.test_additionalItems_single_failurec                 C  s.   | j dddgg ddtjd}| d| d S )Nr:   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 )Nrr   additionalPropertiesFr   r   z('foo' was unexpected)r   r_   )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   Frr   ry   r   zwere unexpected))r   r%   fromkeysr_   rH   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 )Nrv   rm   rr   ry   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containsrv   rm   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   rZ     r[   zQTestValidationErrorMessages.test_invalid_format_default_message.<locals>.<lambda>formatZbla)r   r   format_checkerzis not a)r   checksr   r_   rH   )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 )Nrp   Fre   rq   )^abc$^def$)re   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   rH   r   r   r   r   1test_additionalProperties_false_patternProperties  sB         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  s"   | j dddid}| |d d S )Nr=   Z
multipleOfr   r   z3 is not a multiple of 2r   r   r   r   r   test_multipleOf  s
    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  s    z)TestValidationErrorMessages.test_minItemsc                 C  s(   | j dddgddid}| |d d S )Nr:   r   r=   maxItemsr   z[1, 2, 3] is too longr   r   r   r   r   test_maxItems  s    z)TestValidationErrorMessages.test_maxItemsc                 C  s"   | j g ddid}| |d d S )Nr   r:   r   z[] should be non-emptyr   r   r   r   r   test_minItems_1   s    z+TestValidationErrorMessages.test_minItems_1c                 C  s(   | j dddgddid}| |d d S )Nr:   r   r=   r   r   r   z![1, 2, 3] is expected to be emptyr   r   r   r   r   test_maxItems_0  s    z+TestValidationErrorMessages.test_maxItems_0c                 C  s"   | j dddid}| |d d S )NrU   	minLengthr   r   z'' is too shortr   r   r   r   r   test_minLength  s
    z*TestValidationErrorMessages.test_minLengthc                 C  s"   | j dddid}| |d d S )Nabc	maxLengthr   r   z'abc' is too longr   r   r   r   r   test_maxLength  s
    z*TestValidationErrorMessages.test_maxLengthc                 C  s"   | j dddid}| |d d S )NrU   r   r:   r   z'' should be non-emptyr   r   r   r   r   test_minLength_1  s    z,TestValidationErrorMessages.test_minLength_1c                 C  s"   | j dddid}| |d d S )Nr   r   r   r   z'abc' is expected to be emptyr   r   r   r   r   test_maxLength_0  s    z,TestValidationErrorMessages.test_maxLength_0c                 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_minProperties  s    z.TestValidationErrorMessages.test_minPropertiesc                 C  s*   | j i i i dddid}| |d d S )N)rJ   bcmaxPropertiesr   r   z3{'a': {}, 'b': {}, 'c': {}} has too many propertiesr   r   r   r   r   test_maxProperties"  s    
z.TestValidationErrorMessages.test_maxPropertiesc                 C  s"   | j i ddid}| |d d S )Nr   r:   r   z{} should be non-emptyr   r   r   r   r   test_minProperties_1,  s    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  s.   | j dddgdi i gdd}| |d d S )Nr:   r   rr   Fr   prefixItemsr   z1Expected at most 2 items but found 1 extra: 'foo'r   r   r   r   r   test_prefixItems_with_items7  s    z7TestValidationErrorMessages.test_prefixItems_with_itemsc                 C  s0   | j ddddgdi i gdd}| |d d S )	Nr:   r   rr      Fr   r   z6Expected at most 2 items but found 2 extra: ['foo', 5]r   r   r   r   r   *test_prefixItems_with_multiple_extra_itemsA  s    
zFTestValidationErrorMessages.test_prefixItems_with_multiple_extra_itemsc                 C  s"   | j dddid}| |d d S )Nbbbpatternz^a*$r   z'bbb' does not match '^a*$'r   r   r   r   r   test_patternK  s
    z(TestValidationErrorMessages.test_patternc                 C  s&   | j g dddiid}| |d d S )Nr   re   rq   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 )	Nrr   r:   re   rq   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\  s    z1TestValidationErrorMessages.test_contains_too_fewc                 C  s.   | j ddgddidddd}| |d	 d S )
Nrr   r:   re   rq   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 dddgddiddd}| |d	 d S )
Nrr   ry   bazre   rq   r   r   r   r   :Too many items match the given schema (expected at most 2)r   r   r   r   r   test_contains_too_manyv  s    z2TestValidationErrorMessages.test_contains_too_manyc                 C  s0   | j dgd ddidddd}| |d	 d S )
Nrr   r   re   rq   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  s"   | j dddid}| |d d S )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  s"   | j dddid}| |d d S )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  s$   | j i ddgid}| |d d S )Nrequiredrr   r   z'foo' is a required propertyr   r   r   r   r   test_required  s    z)TestValidationErrorMessages.test_requiredc                 C  s,   | j di idddgiid}| |d d S )Nrr   ZdependentRequiredry   r   z'bar' is a dependency of 'foo'r   r   r   r   r   test_dependentRequired  s
    z2TestValidationErrorMessages.test_dependentRequiredc                 C  s$   | j i ddgid}| |d d S )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  s    z7TestValidationErrorMessages.test_oneOf_matches_too_manyc                 C  s,   ddd}| j ddg|d}| |d d S )Nrj   Fre   unevaluatedItemsrr   ry   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  s(   ddd}| j d|d}| |d d S )Nrj   Fr  rr   r   z'foo' is not of type 'array'r   r   r   r   r   &test_unevaluated_items_on_invalid_type  s    
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 )Nrr   re   rq   rv   rm   
propertiesunevaluatedPropertiesry   rr   ry   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 )	Nrp   Fre   r  rr   ry   rr   ry   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  s(   ddd}| j d|d}| |d d S )Nrp   Fr  rr   r   z'foo' is not of type 'object'r   r   r   r   r   +test_unevaluated_properties_on_invalid_type  s    
zGTestValidationErrorMessages.test_unevaluated_properties_on_invalid_typec                 C  s0   i gdd}| j dddg|d}| |d d S )NFr   r   rr   ry   r   r   z9Expected at most 1 item but found 2 extra: ['bar', 'baz']r   r   r   r   r   test_single_item  s    z,TestValidationErrorMessages.test_single_itemc                 C  s4   i gdd}| j dddg|tjd}| |d d S )NFr   rr   ry   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  s0   i gdd}| j dddg|d}| |d d S )NFr  rr   ry   r   r   z6Expected at most 1 item but found 2 extra: ['bar', 37]r   r   r   r   r   $test_heterogeneous_items_prefixItems   s    z@TestValidationErrorMessages.test_heterogeneous_items_prefixItemsc                 C  s0   i gdd}| j dddg|d}| |d d S )NF)r   r  rr   ry   r   r   z=Unevaluated items are not allowed ('bar', 37 were unexpected)r   r   r   r   r   /test_heterogeneous_unevaluatedItems_prefixItems  s    zKTestValidationErrorMessages.test_heterogeneous_unevaluatedItems_prefixItemsc                 C  s4   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.
        rr   F)r  r   r   rm   rr   rJ   r   r   z?Additional properties are not allowed (37, 'a' were unexpected)Nr   r   r   r   r   2test_heterogeneous_properties_additionalProperties  s    
zNTestValidationErrorMessages.test_heterogeneous_properties_additionalPropertiesc                 C  s4   di idd}| j i ddd|d}| |d d	S )
r  rr   Fr  r   rm   r  r   z@Unevaluated properties are not allowed (37, 'a' were unexpected)Nr   r   r   r   r   3test_heterogeneous_properties_unevaluatedProperties$  s    
zOTestValidationErrorMessages.test_heterogeneous_properties_unevaluatedPropertiesN)=rD   r   rE   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  r  r  r  r  r   r!  r   r   r   r   r   2  st   	








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dddg | |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dddg | t|jd d S )Nr   anyOfr      re   rq   r:   r   $r   )r   r   r3   r4   r#   r;   r   r8   r   r   assertIsNoneparentpathr   relative_pathabsolute_path	json_pathr9   relative_schema_pathabsolute_schema_pathcontextsorted_errorsassertIsassertFalser*   r   r   r   r   ee1e2r   r   r   
test_anyOf6  sj    
 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dd	dg | |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ddddg | |jtddddg | |jtdddddg | |j d S )Nrr   r:   re   rl   rp   enumr   re   r  r   r%  $.foor  )r   r   r3   r4   r#   r;   r   r8   r   r   r&  r'  r(  r   r)  r*  r+  r9   r,  r-  r.  r/  r0  r1  r2  r   r   r   	test_type{  sz    

  z$TestValidationErrorDetails.test_typec           	      C  s  ddgddd}dddid	did
ddddg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)rr   ry   r   quuxr  re   rq   r   
   r         )r   r7  r  ry   r   rr   $.barz$.bazr9  r7  r   )r   r   r4   r/  r#   r(  r   r)  r*  r+  r   )	r*   r   r   r   r   r4  r5  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dddg | |	jtdddg | |
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ddddg | t	|jddddddg | t	|	jddddddg | t	|
jddddg | |j
d | |j
d | |j
d | |j
d | |	j
d | |
j
d d S )Nr:   r   r   r  r<  rq   rp   r7  r=   rj   r  Tr   )ry   r   r8  )re   r   r   ry   rr   r%  $[0]z$[1].barz$[1].bar.barz$[1].bar.bazz$[1].foore   r   r  )r   r   r4   r/  r#   r(  r   r+  r9   r3   r   )r*   r   r   r   r   r4  r5  rA  rB  Ze5Ze6r   r   r   test_multiple_nesting  sf    


 
 
z0TestValidationErrorDetails.test_multiple_nestingc                 C  sn  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dddg | |jd |j\}| |jtdddg | |jtdddddddddg	 | |jd |j\}| |jtdddddg | |jtdddddddddddddddg | |jd d S )Nnoder#  rp   r   childrenre   rq   z^.*$r   z#/definitions/node)re   r   )r   rG  )re   r  r  root)definitionsre   r  r  rJ   abr  z$.rootr   r   z$.root.children.az$.root.children.a.children.ab)	r   r   r4   r#   r*  r   r-  r+  r.  )r*   r   r   r   r3  r4  r5  r   r   r   test_recursive,  s      
 
    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 )Nry   r   r   r   rl   r   re   r   rr   r@  r9  re   r   	r   r   r4   r/  r#   r(  r   r+  r   r*   r   r   r   r   r4  r5  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   re   rq   r   r   ry   rr   r@  r9  rM  rN  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 )Nrr   r:   rl   r   rL  r   r   rD  $[1]re   r   rM  rN  r   r   r   test_additionalItems  s    

z/TestValidationErrorDetails.test_additionalItemsc                 C  s   dddg}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 )Nrr   ry   r:   rl   r   rL  r   r   rQ  z$[2]re   r   rM  rN  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 )Nrr   rm   ZpropertyNamesrx   rv   z0'foo' should not be valid under {'const': 'foo'}r%  
r   r   r4   r#   r   r   r(  r   r+  r9   )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 )Nrv   rm      )ifthen13 was expectedr%  rY  rT  r*   r   r   rU  r   r   r   test_if_then  s    
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 )	Nrv   rm   rW  )rX  elser;  rZ  r%  r]  rT  r[  r   r   r   test_if_else  s    
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 )NFrm   zFalse schema does not allow 12r%  )r   r   r4   r#   r   r   r8   r   r   r9   r+  r   )r*   r   rU  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   re   rl   r   rU   storeresolverrr   ZnotAnIntegerz''notAnInteger' is not of type 'integer'r9  )r   r   _RefResolverr4   r#   r   r   r8   r   r*  r   r9   r+  r   )r*   refr   r   rU  r   r   r   test_ref'  s4    
z#TestValidationErrorDetails.test_refc                 C  s   dddii i ddigi}t |}|dddd	g\}}| |j|j|j|j|j|j	|j
|jfd
dddtdgdditd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dgdf d S )Nr   re   rq   r   r=   r:   r   rr   r   r   r   rD  z"5 is greater than the maximum of 3$[3]r   rz   r4   r#   r   r   r8   r   r*  r   r9   r+  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 |}|dddddg\}}| |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 )Nre   rq   r   rr   r   ry   r   r   z2 is not of type 'string'r:   r   rQ  z4 is not of type 'string'r=   rg  rh  r*   r   r   r4  r5  r   r   r   r   w  sZ    


z6TestValidationErrorDetails.test_prefixItems_with_itemsc                 C  s   ddidd}t |}|dddddd	g\}| |j|j|j|j|j|j	|j
|jfd
dddddddd	g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.
        re   rq   r   r   rr   ry   r   r   r<  r  r   r   r%  Nrh  r[  r   r   r   r    s.    
z1TestValidationErrorDetails.test_contains_too_manyc                 C  s   ddidd}t |}|dddg\}| |j|j|j|j|j|j	|j
|jfddddddgtg ddiddtd	gd
f d S )Nre   rq   r   r   rr   r   r   r   r   r%  rh  r[  r   r   r   r     s.    
z0TestValidationErrorDetails.test_contains_too_fewc                 C  s   ddidd}t |}|ddg\}| |j|j|j|j|j|j	|j
|jfddddiddgtg ddiddtdgdf d S )	Nre   rq   r   r   r   z7[2, 4] does not contain items matching the given schemar   r%  rh  r[  r   r   r   test_contains_none  s.    
z-TestValidationErrorDetails.test_contains_nonec                 C  s
  dddgiidddgdid}t |}|di i\}}| |j|j|j|j|j|j	|j
|j|jf	d	ddgi tdgddgitd
ddgtd
ddg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d
ddgtd
ddgdf	 d S )Nrr   r  ry   Zapropz#/$defs/foor   )r   r  )r   r  z'bar' is a required propertyr  z$.apropz'baz' is a required property)r   rz   r4   r#   r   r   r8   r   r*  r   r9   r,  r+  r   rj  r   r   r   test_ref_sibling  sj    


z+TestValidationErrorDetails.test_ref_siblingN)rD   r   rE   r6  r:  rC  rE  rK  rO  rP  rR  rS  rV  r\  r^  r_  rf  ri  r   r  r   rk  rl  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  s,   |  tj | jddi W 5 Q R X d S )Nr  rm   r|   r   r}   r(   r{   r)   r   r   r   test_invalid_propertiesD  s    z,MetaSchemaTestsMixin.test_invalid_propertiesc              	   C  s,   |  tj | jddi W 5 Q R X d S )Nr   1rn  r)   r   r   r   test_minItems_invalid_stringH  s    z1MetaSchemaTestsMixin.test_minItems_invalid_stringc              	   C  sP   | j tjtjhkr<| tj | j dg i W 5 Q R X n| 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.
        r7  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  sX   | j tjtjhkr@| tj | j dddgi W 5 Q R X n| 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.
        r7  rm   Nrr  r)   r   r   r   !test_enum_allows_non_unique_items^  s     z6MetaSchemaTestsMixin.test_enum_allows_non_unique_itemsc              	   C  s,   |  tj | jddi W 5 Q R X d S )Nr   
*notaregexrn  r)   r   r   r   test_schema_with_invalid_regexo  s    z3MetaSchemaTestsMixin.test_schema_with_invalid_regexc                 C  s   | j jddid d d S )Nr   ru  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)	rD   r   rE   ro  rq  rs  rt  rv  rx  r   r   r   r   rm  B  s   rm  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{  s    z<ValidatorTestMixin.test_it_implements_the_validator_protocolc                 C  s$   | j \}}| | || d S r,   )validrs   r(   r   r*   r   r   r   r   r   test_valid_instances_are_valid~  s    
z1ValidatorTestMixin.test_valid_instances_are_validc                 C  s$   | j \}}| | || d S r,   )invalidr1  r(   r   r}  r   r   r   $test_invalid_instances_are_not_valid  s    
z7ValidatorTestMixin.test_invalid_instances_are_not_validc                 C  s    |  t t ijt d d S )Nr   )r(   rp   r~   r)   r   r   r   (test_non_existent_properties_are_ignored  s    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 )Nre   rl   rw  rq   )r   r   )r   	_resolver)r   r(   evolveZFORMAT_CHECKERr  r#   ZassertNotEqual)r*   r   r   rQ   r   expectedr   r   r   test_evolve  s     zValidatorTestMixin.test_evolvec              	   C  s   |  t tG dd d| j}W 5 Q R X |i dd}| |jdddg |jdd	id
}| |jdddg | |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
   dddgS )Nr:   r   r=   r   r   r   r   r   rZ     r[   zCValidatorTestMixin.test_evolve_with_subclass.<locals>.OhNo.<lambda>)factoryr   defaultN)rD   r   rE   r   rr   _barr   r   r   r   OhNo  s   r  rm   )ry   r:   r   r=   re   rl   r   N)assertWarnsDeprecationWarningr   r(   r#   rr   r  r  )r*   r  r   r   r   r   r   test_evolve_with_subclass  s    
z,ValidatorTestMixin.test_evolve_with_subclassc                 C  s   |  | i dd d S )Nrr   rq   )rs   r(   rf   r)   r   r   r   #test_is_type_is_true_for_valid_type  s    z6ValidatorTestMixin.test_is_type_is_true_for_valid_typec                 C  s   |  | i dd d S )Nrr   rj   r1  r(   rf   r)   r   r   r   &test_is_type_is_false_for_invalid_type  s    z9ValidatorTestMixin.test_is_type_is_false_for_invalid_typec                 C  s4   |  | i dd |  | i dd d S )NTrl   ro   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   re   ro   c                 S  s   t |tttfot |t S r,   )
isinstanceintfloatr   boolr   r   r   r   r   rZ     s    zGValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<lambda>r!   r:   g?r?  rr   Tc                 S  s   g | ]
}|j qS r   r  )rg   rU  r   r   r   
<listcomp>  s     zIValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<listcomp>)	r   r   r(   r/   redefiner~   r   r#   r4   )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   Zcarrotrw  Z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(   r&  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 5 Q R X |j	j
  d S )
NzBad!rr   )Zraisesc                   s0   | dkrdS | dkr n 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   rw  r  r  )r   
ValueErrorr   r(   r~   r|   r   r   r0  	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 )Nre   c                 S  s
   t |tS r,   r  r  r  r   r   r   rZ     r[   z@ValidatorTestMixin.test_non_string_custom_type.<locals>.<lambda>r  r;  )rp   r   r   r(   r/   r  r~   )r*   Znon_string_typer   Crazyr   r   r   test_non_string_custom_type  s    
z.ValidatorTestMixin.test_non_string_custom_typec              	   C  s`   t j| j| jjddd d}| tj}|ddid W 5 Q R X | 	dt
|j d	S )
zh
        A tuple instance properly formats validation errors for uniqueItems.

        See #224
        rj   c                 S  s
   t |tS r,   )r  tupler  r   r   r   rZ     r[   zNValidatorTestMixin.test_it_properly_formats_tuples_in_errors.<locals>.<lambda>r  uniqueItemsT)r:   r:   z(1, 1) has non-unique elementsN)r   r   r(   r/   r  r|   r   r   r~   r_   strr  )r*   ZTupleValidatorr3  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dddddg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 ]}|| qZtdddg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 5 Q R X qzdS )zO
        Allow array to validate against another defined sequence type
        rj   T)re   r  	MyMappingza, bc                 S  s   t |ttfS r,   )r  r3   r   r  r   r   r   rZ     s    zBValidatorTestMixin.test_check_redefined_sequence.<locals>.<lambda>c                   s   t |t fS r,   )r  r%   r  r  r   r   rZ     s    )rj   rp   r  rJ   Nrp  rU   Fr   r   )r   r   r   r(   r/   Zredefine_manyr   r~   r|   r   r   )r*   r   r(   r   Zvalid_instancesr   Zinvalid_instancesr   r  r   test_check_redefined_sequence  s\    


""""z0ValidatorTestMixin.test_check_redefined_sequencec              	   C  s4   |  t | i j}W 5 Q R X | |tj d S r,   )r  r  r(   rc  rz  r   rd  )r*   rc  r   r   r   .test_it_creates_a_ref_resolver_if_not_providedT  s    zAValidatorTestMixin.test_it_creates_a_ref_resolver_if_not_providedc              	   C  sZ   dddi }}t jdi ||id}| jd|i|d}| tj |d  W 5 Q R X d S )NsomeCoolRefre   rl   rU   r`  r   rb  )r   rd  r(   r|   r   r   r~   r*   re  r   rc  r   r   r   r   /test_it_upconverts_from_deprecated_RefResolversY  s
    zBValidatorTestMixin.test_it_upconverts_from_deprecated_RefResolversc              	     sP   G  fddd}| }ddi}  tj  j||dd W 5 Q R X 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 refre   rl   r#   )thisre  r)   r   r   	resolvingh  s    zxValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolvers.<locals>.LegacyRefResolver.resolvingN)rD   r   rE   r   r  r   r)   r   r   LegacyRefResolverg  s   r  r   r  rb  N)r|   r   r   r(   r~   )r*   r  rc  r   r   r)   r   @test_it_upconverts_from_yet_older_deprecated_legacy_RefResolversa  s
    zSValidatorTestMixin.test_it_upconverts_from_yet_older_deprecated_legacy_RefResolversN)rD   r   rE   r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   ry  z  s&   Bry  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  s:   |  tj}| jd W 5 Q R X | dt|j d S )NTzTrue is not of typer|   r   r}   r(   r{   r_   r  r  r*   r3  r   r   r   test_True_is_not_a_schemay  s    z-AntiDraft6LeakMixin.test_True_is_not_a_schemac              	   C  s:   |  tj}| jd W 5 Q R X | dt|j d S )NFzFalse is not of typer  r  r   r   r   test_False_is_not_a_schema~  s    z.AntiDraft6LeakMixin.test_False_is_not_a_schemac              	   C  s:   |  t}| dd W 5 Q R X | |jtj d S )NTrm   r|   	Exceptionr(   r~   ZassertNotIsInstancer  r   r   r  r   r   r   5test_True_is_not_a_schema_even_if_you_forget_to_check  s    zIAntiDraft6LeakMixin.test_True_is_not_a_schema_even_if_you_forget_to_checkc              	   C  s:   |  t}| dd W 5 Q R X | |jtj d S )NFrm   r  r  r   r   r   6test_False_is_not_a_schema_even_if_you_forget_to_check  s    zJAntiDraft6LeakMixin.test_False_is_not_a_schema_even_if_you_forget_to_checkN)rD   r   rE   __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|  re   rl   rr   c                 C  s   |  ddi}|t  d S Nre   any)r(   r~   rp   r  r   r   r   #test_any_type_is_valid_for_type_any  s    z7TestDraft3Validator.test_any_type_is_valid_for_type_anyc              	   C  s\   t j| j| jjddd d}|ddi}|d | tj |d W 5 Q R X dS )	z(
        Sigh, because why not.
        r  c                 S  s
   t |tS r,   r  r  r   r   r   rZ     r[   zBTestDraft3Validator.test_any_type_is_redefinable.<locals>.<lambda>r  re   rm   rr   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  )rs   r(   r   rp   r)   r   r   r   !test_is_type_is_true_for_any_type  s    z5TestDraft3Validator.test_is_type_is_true_for_any_typec                 C  s6   |  | i dd |  | ddid d S )NTrk   re   r  )rs   r(   rf   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)rD   r   rE   r   r   r(   r|  __annotations__r  r  r  r  r  r   r   r   r   r    s   
r  c                   @  s0   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|  re   rl   rr   N)	rD   r   rE   r   r   r(   r|  r  r  r   r   r   r   r    s   
r  c                   @  s0   e Zd ZU ejZi i fZded< ddidfZdS )TestDraft6Validatorr  r|  re   rl   rr   N)	rD   r   rE   r   r   r(   r|  r  r  r   r   r   r   r    s   
r  c                   @  s0   e Zd ZU ejZi i fZded< ddidfZdS )TestDraft7Validatorr  r|  re   rl   rr   N)	rD   r   rE   r   r   r(   r|  r  r  r   r   r   r   r    s   
r  c                   @  s0   e Zd ZU ejZi i fZded< ddidfZdS )TestDraft201909Validatorr  r|  re   rl   rr   N)	rD   r   rE   r   Draft201909Validatorr(   r|  r  r  r   r   r   r   r    s   
r  c                   @  s0   e Zd ZU ejZi i fZded< ddidfZdS )TestDraft202012Validatorr  r|  re   rl   rr   N)	rD   r   rE   r   rz   r(   r|  r  r  r   r   r   r   r    s   
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  sT   d}d|i}t jdi |did}t j||d}| tj |d  W 5 Q R X d S )Nr  r   rU   Fr`  rb  )r   rd  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)rD   r   rE   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  s<   ddi}|  t|tj ddi}|  t|tj d S )Nrw   &http://json-schema.org/draft-03/schema'http://json-schema.org/draft-03/schema#)r0  r   validator_forr   r1   r   r   r   test_draft_3  s    zTestValidatorFor.test_draft_3c                 C  s<   ddi}|  t|tj ddi}|  t|tj d S )Nrw   &http://json-schema.org/draft-04/schema'http://json-schema.org/draft-04/schema#)r0  r   r  r   r1   r   r   r   test_draft_4  s    zTestValidatorFor.test_draft_4c                 C  s<   ddi}|  t|tj ddi}|  t|tj d S )Nrw   &http://json-schema.org/draft-06/schema'http://json-schema.org/draft-06/schema#)r0  r   r  r   r1   r   r   r   test_draft_6  s    zTestValidatorFor.test_draft_6c                 C  s<   ddi}|  t|tj ddi}|  t|tj d S )Nrw   &http://json-schema.org/draft-07/schema'http://json-schema.org/draft-07/schema#)r0  r   r  r   r1   r   r   r   test_draft_7  s    zTestValidatorFor.test_draft_7c                 C  s<   ddi}|  t|tj ddi}|  t|tj d S )Nrw   z,https://json-schema.org/draft/2019-09/schemaz-https://json-schema.org/draft/2019-09/schema#)r0  r   r  r  r1   r   r   r   test_draft_201909  s    z"TestValidatorFor.test_draft_201909c                 C  s<   ddi}|  t|tj ddi}|  t|tj d S )Nrw   ,https://json-schema.org/draft/2020-12/schema-https://json-schema.org/draft/2020-12/schema#)r0  r   r  rz   r1   r   r   r   test_draft_202012  s    z"TestValidatorFor.test_draft_202012c                 C  s   |  tdtj d S )NTr0  r   r  r   r)   r   r   r   	test_True*  s    zTestValidatorFor.test_Truec                 C  s   |  tdtj d S r   r  r)   r   r   r   
test_False0  s    zTestValidatorFor.test_Falsec                 C  s6   t jddiddd d}ddi}| t || d S )NrP   rS   Z12c                 S  s   |  ddS rT   rV   rX   r   r   r   rZ   :  r[   z8TestValidatorFor.test_custom_validator.<locals>.<lambda>r\   rw   r   r'   r0  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   rb   Z13rA   rw   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  s    z6TestValidatorFor.test_validator_for_jsonschema_defaultc                 C  s   |  tji d dd  d S )Nr  )r0  r   r  r)   r   r   r   !test_validator_for_custom_defaultP  s    z2TestValidatorFor.test_validator_for_custom_defaultc              	   C  sJ   |  t}tjddid W 5 Q R X | |jt | t|jd d S )Nrw   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  s>   t jdd}t d tji i d W 5 Q R X | | d S )NTrecordalways)r   r  )warningscatch_warningssimplefilterr   r  r1  )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 )Nrw   zmailto:foo@example.com)rp   r0  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)rD   r   rE   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S )TestValidatec              	   C  s@   g }t j|d|j ti | W 5 Q R X | ||g d S )Nr{   )r
   patchrp   appendr   r~   r#   )r*   r   r(   resultr   r   r   
assertUsesk  s    zTestValidate.assertUsesc                 C  s,   | j dditjd | j dditjd d S )Nrw   r  r   r(   r  )r  r   r   r)   r   r   r   test_draft3_validator_is_chosenq  s    z,TestValidate.test_draft3_validator_is_chosenc                 C  s,   | j dditjd | j dditjd d S )Nrw   r  r  r  )r  r   r   r)   r   r   r   test_draft4_validator_is_chosen|  s    z,TestValidate.test_draft4_validator_is_chosenc                 C  s,   | j dditjd | j dditjd d S )Nrw   r  r  r  )r  r   r   r)   r   r   r   test_draft6_validator_is_chosen  s    z,TestValidate.test_draft6_validator_is_chosenc                 C  s,   | j dditjd | j dditjd d S )Nrw   r  r  r  )r  r   r   r)   r   r   r   test_draft7_validator_is_chosen  s    z,TestValidate.test_draft7_validator_is_chosenc                 C  s,   | j dditjd | j dditjd d S )Nrw   r  r  r  r  r   rz   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  r	  r)   r   r   r   )test_draft202012_validator_is_the_default  s    z6TestValidate.test_draft202012_validator_is_the_defaultc              	   C  s>   |  tj}tdddi W 5 Q R X | t|jd d S )Nrm   re   rq   z1(?s)Failed validating '.*' in schema.*On instance)r|   r   r   r   r~   assertRegexr  r  r  r   r   r   test_validation_error_message  s    z*TestValidate.test_validation_error_messagec              	   C  s>   |  tj}tdddi W 5 Q R X | t|jd d S )Nrm   re   z3(?s)Failed validating '.*' in metaschema.*On schema)r|   r   r}   r   r~   r  r  r  r  r   r   r   test_schema_error_message  s    z&TestValidate.test_schema_error_messagec              	   C  sP   ddddddigi}|  tj}td| W 5 Q R X | dt|j d S )	Nr	  ro   r$  rL  re   rj   rm   z!12 is less than the minimum of 20)r|   r   r   r   r~   r_   r  r  )r*   r   r3  r   r   r   test_it_uses_best_match  s    z$TestValidate.test_it_uses_best_matchN)rD   r   rE   r  r  r  r  r  r
  r  r  r  r  r   r   r   r   r  j  s   r  c                   @  s   e Zd ZdZdd ZdS )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                     s2   zt jddd W n    t  Y nX d S )Nr   Tr   )r   r~   r  sysexc_infor   failedr   r   r~     s    zFTestThreading.test_validation_across_a_second_thread.<locals>.validater   )Thread)targetF)	threadingr  startjoinr#   is_alive)r*   r~   r  threadr   r  r   &test_validation_across_a_second_thread  s    
z4TestThreading.test_validation_across_a_second_threadN)rD   r   rE   r  r  r   r   r   r   r    s   r  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 )Nre   rl   )r   Zcreate_resourceurir   r   r   retrieve  s    z=TestReferencing.test_registry_with_retrieve.<locals>.retrieve)r   r   https://example.com/registryrm   rr   )TF)referencingRegistryr   rz   r#   r   )r*   r   r#  r   r   r   r   r   test_registry_with_retrieve  s    z+TestReferencing.test_registry_with_retrievec              
   C  sr   t  }ddi}tj||d}tjdd4}td | t jj	 |
d W 5 Q R X W 5 Q R X | | d S )Nr   r!  r"  Tr  r  rm   )r$  r%  r   rz   r  r  r  r|   r   ZUnresolvabler~   r1  )r*   r#  r   r   r  r   r   r   ;test_custom_registries_do_not_autoretrieve_remote_resources  s    
zKTestReferencing.test_custom_registries_do_not_autoretrieve_remote_resourcesN)rD   r   rE   r&  r'  r   r   r   r   r    s   r  c                   @  s   e Zd ZdZdZddiZdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)S )*TestRefResolverrU   zfoo://storedZstoredr   c                 C  s.   i | _ | j| ji| _t| j| j | j| _d S r,   )referrer
stored_uristored_schemara  r   rd  base_urirc  r)   r   r   r   r+   
	  s      zTestRefResolver.setUpc              
   C  s`   t jjd }tj| jd}| j|}W 5 Q R X W 5 Q R X | |t jj | 	|j
 d S )NrP   Zresolve_remote)r   r   r.   r
   r   rp   rc  r  r#   r1  called)r*   re  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  sF   d}dt  i| jd< | j|}| || jd d  W 5 Q R X d S )Nz#/properties/foorr   r  )rp   r)  rc  r  r#   )r*   re  r.  r   r   r   test_it_resolves_local_refs	  s    z+TestRefResolver.test_it_resolves_local_refsc              	   C  sr   dddid}t jj|dd d}|d}| ||d	  W 5 Q R X |d
}| ||d	  W 5 Q R X d S )Nzhttp://bar/schema#rr   ry   )rP   rJ   c                 S  s   |  ddS rT   rV   r   r   r   r   rZ   #	  r[   zETestRefResolver.test_it_resolves_local_refs_with_id.<locals>.<lambda>r]   z#/arJ   zhttp://bar/schema#/a)r   rd  from_schemar  r#   r*   r   rc  r.  r   r   r   #test_it_resolves_local_refs_with_id	  s    z3TestRefResolver.test_it_resolves_local_refs_with_idc              	   C  s`   | j | j}| || j W 5 Q R X ddi| j jd< | j d}| |d W 5 Q R X d S )Nrr   rm   Z
cached_refzcached_ref#/foo)rc  r  r*  r0  r+  ra  r#   )r*   r.  r   r   r   test_it_retrieves_stored_refs*	  s
    z-TestRefResolver.test_it_retrieves_stored_refsc              	   C  sh   d}ddi}dt jkr.| t jjdt jd  td|it jd< | j|}| |d W 5 Q R X d S )Nhttp://bar#bazr   rm   requests
http://bar)r  modulesr"   __setitem__ReallyFakeRequestsrc  r  r#   )r*   re  r   r.  r   r   r   ,test_it_retrieves_unstored_refs_via_requests2	  s    
  z<TestRefResolver.test_it_retrieves_unstored_refs_via_requestsc              	     s   d}ddi dt jkr.t jjdt jd  d t jd< t fdd}ttdtj |t_j	|}W 5 Q R X 
|d d S )Nr6  r   rm   r7  c                 3  s&    | d tt dV  d S )Nr8  utf8)r#   r   jsondumpsencodeurlr   r*   r   r   fake_urlopenI	  s    zQTestRefResolver.test_it_retrieves_unstored_refs_via_urlopen.<locals>.fake_urlopenurlopen)r  r9  r"   r:  r   setattrr   rE  rc  r  r#   )r*   re  rD  r.  r   rC  r   +test_it_retrieves_unstored_refs_via_urlopen?	  s     
  

z;TestRefResolver.test_it_retrieves_unstored_refs_via_urlopenc              	   C  st   t jddd&}| tj|j tddi| W 5 Q R X dt|j d}| j	
|}| |d W 5 Q R X d S )NFwt)deletemoderr   ry   zfile://z#foo)tempfileNamedTemporaryFiler"   osremover   r>  dumpr   rc  r  r#   )r*   Ztempfre  r.  r   r   r   (test_it_retrieves_local_refs_via_urlopenU	  s    z8TestRefResolver.test_it_retrieves_local_refs_via_urlopenc              	   C  s   ddi}t jj|dd d}| |jd | |jd |d}| || W 5 Q R X |d}| || W 5 Q R X |d}| || W 5 Q R X |d}| || W 5 Q R X d S )	NrP   rr   c                 S  s   |  ddS rT   rV   r   r   r   r   rZ   b	  r[   zPTestRefResolver.test_it_can_construct_a_base_uri_from_a_schema.<locals>.<lambda>r1  rU   #zfoo#r   rd  r2  r#   r,  Zresolution_scoper  r3  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  st   i }t j|}| |jd | |jd |d}| || W 5 Q R X |d}| || W 5 Q R X d S )NrU   rQ  rR  r3  r   r   r   9test_it_can_construct_a_base_uri_from_a_schema_without_ido	  s    zITestRefResolver.test_it_can_construct_a_base_uri_from_a_schema_without_idc              	     sV    fdd}ddid t jdi d|id}| }| W 5 Q R X d S )Nc                   s    |   S r,   r  rA  re  r   r*   r   r   handlerz	  s    z@TestRefResolver.test_custom_uri_scheme_handlers.<locals>.handlerrr   ry   	foo://barrU   handlers)r   rd  r  r#   )r*   rV  rc  r.  r   rU  r   test_custom_uri_scheme_handlersy	  s    z/TestRefResolver.test_custom_uri_scheme_handlersc              	     s`   t  g  fdd}d}tjdi dd|id}|| W 5 Q R X || W 5 Q R X d S )Nc                   s.   z
   W S  tk
r(   d Y nX d S )Nz#Response must not have been cached!rC   
IndexErrorr   rA  responser*   r   r   rV  	  s    
z5TestRefResolver.test_cache_remote_on.<locals>.handlerrW  rU   Trr   Zcache_remoterY  rp   r   rd  r  r*   rV  re  rc  r   r]  r   test_cache_remote_on	  s       
z$TestRefResolver.test_cache_remote_onc              	     sJ   t  g  fdd}d}tjdi dd|id}|| W 5 Q R X d S )Nc                   s.   z
   W S  tk
r(   d Y nX d S )NzHandler called twice!r[  rA  r]  r   r   rV  	  s    
z6TestRefResolver.test_cache_remote_off.<locals>.handlerrW  rU   Frr   r_  r`  ra  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 5 Q R X W 5 Q R X | |j	t  d S )	NzOh no! What's this?c                   s    d S r,   r   rA  rU  r   r   rV  	  s    zTTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_error.<locals>.handlerrW  rU   rr   rX  zShouldn't get this far!)
r  r   rd  r|   r   _RefResolutionErrorr  r   r#   r  )r*   rV  re  rc  errr   rd  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  sJ   t di }|  | tj}|  W 5 Q R X | dt|j d S )NrU   zFailed to pop the scope)	r   rd  Z	pop_scoper|   r   re  r_   r  r  )r*   rc  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.
        rU   rb  r   rr   ZallOfr   r   N)r   r   r.   rd  r1  r   )r*   r   Zoner   ZanotherZ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/foore   rl   r  r  r)   r   r   handle	  s    zNTestRefResolver.test_newly_created_validator_with_ref_resolver.<locals>.handlerU   httprX  rd   zhttp://example.com/barrr   )r   r   rb  r   FTN)r   rd  r'   r   r-   r#   r   )r*   rk  rc  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/xre   rl   )r  rI  rU   rb  yr   rm  N)r   rz   rd  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)rD   r   rE   r,  r*  r+  r+   r/  r0  r4  r5  r<  rG  rP  rS  rT  rZ  rb  rc  rg  ri  rj  rn  rq  r   r   r   r   r(  	  s*   	
r(  c                 C  s   dd }t | |dS )Nc                 S  s    dd | j D dd | jD fS )Nc                 S  s   g | ]}t |qS r   r  rg   r3  r   r   r   r  	  s     z.sorted_errors.<locals>.key.<locals>.<listcomp>c                 S  s   g | ]}t |qS r   rr  rs  r   r   r   r  	  s     )r(  r9   rd  r   r   r   key	  s    zsorted_errors.<locals>.key)rt  )sorted)r   rt  r   r   r   r/  	  s    r/  c                   @  s   e Zd ZU ded< dd ZdS )r;  zdict[str, Any]
_responsesc                 C  s2   | j |}|d kr$tdt| tt|S )NzUnknown URL: )rv  rW   r  rH   _ReallyFakeJSONResponser>  r?  )r*   rB  r^  r   r   r   rW   
  s    zReallyFakeRequests.getN)rD   r   rE   r  rW   r   r   r   r   r;  	  s   
r;  c                   @  s   e Zd ZU ded< dd ZdS )rw  r  	_responsec                 C  s   t | jS r,   )r>  loadsrx  r)   r   r   r   r>  
  s    z_ReallyFakeJSONResponse.jsonN)rD   r   rE   r  r>  r   r   r   r   rw  	
  s   
rw  ):
__future__r   collectionsr   r   
contextlibr   decimalr   ior   typingr   Zunittestr	   r
   urllib.requestr   r>  rM  r  rK  r  attrsr   r   Zreferencing.jsonschemar   Zreferencing.exceptionsr$  Z
jsonschemar   r   r   r   r   r   r   r   r"  rm  ry  r  r  r  r  r  r  r  r  r  r  r  r  r(  r/  r;  rw  r   r   r   r   <module>   sn   	            8 {  a q	