o
    >�Ò]êë  ã                   @   sê  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	 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 d dlZd dlmZmZmZmZ d d	lmZmZ d d
lmZ dd„ ZG dd„ deƒZG dd„ deƒZG dd„ de	ƒZG dd„ de	ƒZG dd„ de	ƒZ G dd„ de!ƒZ"G dd„ de"e!ƒZ#G dd„ de!ƒ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ƒZ)G d'd(„ d(eƒZ*G d)d*„ d*eƒZ+d+d,„ Z,ej-G d-d.„ d.e!ƒƒZ.ej-G d/d0„ d0e!ƒƒZ/dS )1é    )Údeque)Úcontextmanager)ÚDecimal)ÚBytesIO)ÚTestCaseN)ÚSynchronousTestCase)ÚFormatCheckerÚTypeCheckerÚ
exceptionsÚ
validators)ÚPY3Úpathname2url)Úbugc                 c   s    � |  |¡st d¡V  d S d S )NúWhoops!)Ú
startswithr
   ÚValidationError)Ú	validatorr   ÚinstanceÚschema© r   úB/usr/lib/python3/dist-packages/jsonschema/tests/test_validators.pyr      s   €
ÿr   c                   @   sd   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S )ÚTestCreateAndExtendc                 C   sP   |   | jtjttjƒ¡ ddi| _dti| _tƒ | _tj	| j| j| jd�| _
d S )Nú$idzsome://meta/schemar   ©Úmeta_schemar   Útype_checker)Ú
addCleanupÚassertEqualr   Úmeta_schemasÚdictr   r   r	   r   ÚcreateÚ	Validator©Úselfr   r   r   ÚsetUp   s   ý

ýzTestCreateAndExtend.setUpc                 C   s.   |   | jj| jj| jjf| j| j| jf¡ d S ©N)r   r!   Ú
VALIDATORSÚMETA_SCHEMAÚTYPE_CHECKERr   r   r   r"   r   r   r   Ú
test_attrs*   s   ýýûzTestCreateAndExtend.test_attrsc                 C   s    ddi}|   |  |¡j|¡ d S )Nr   Úfoo)r   r!   r   ©r#   r   r   r   r   Ú	test_init7   s   zTestCreateAndExtend.test_initc                 C   s€   ddi}|   |¡j}t|dƒƒ}|  |g ¡ tjdd|ddtdgƒd�}t|dƒƒ}|  t|ƒd¡ |  |d  ¡ | ¡ ¡ d S )	Nr   ÚhelÚhellor   Úgoodbye)r   r   r   Úvalidator_valueÚschema_pathé   r   )	r!   Úiter_errorsÚlistr   r
   r   r   ÚlenÚ	_contents)r#   r   r3   ÚerrorsÚexpected_errorr   r   r   Útest_iter_errors;   s   ú	z$TestCreateAndExtend.test_iter_errorsc                 C   s4   t jddidd�}|  t jjd¡ |  |jd¡ d S )Nr   Ú	somethingú
my version©r   ÚversionÚMyVersionValidator)r   r    r   r   Úpopr   Ú__name__©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   s,   t tjƒ}tjddid� |  tj|¡ d S )NÚid)r   )r   r   r   r    r   )r#   Úoriginalr   r   r   Ú6test_if_a_version_is_not_provided_it_is_not_registeredW   s   
zJTestCreateAndExtend.test_if_a_version_is_not_provided_it_is_not_registeredc                 C   sB   d}d|i}t j|ddd„ d� |  t jj|¡ |  |t j¡ d S )Númeta schema idrC   r;   c                 S   ó   |   dd¡S ©NrC   Ú ©Úget©Úsr   r   r   Ú<lambda>c   ó    zMTestCreateAndExtend.test_validates_registers_meta_schema_id.<locals>.<lambda>©r   r=   Úid_of©r   r    r   r   r?   ÚassertIn©r#   Úmeta_schema_keyÚmy_meta_schemar   r   r   Ú'test_validates_registers_meta_schema_id\   s   ýz;TestCreateAndExtend.test_validates_registers_meta_schema_idc                 C   s<   d}d|i}t j|dd� |  t jj|¡ |  |t j¡ d S )Númeta schema $idr   r;   r<   rR   rT   r   r   r   Ú.test_validates_registers_meta_schema_draft6_idi   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)Ú.0r[   r   ©r!   r   r   Ú	<genexpr>x   s
   € ÿ
ÿz@TestCreateAndExtend.test_create_default_types.<locals>.<genexpr>Úarray)ÚbooleanT)Úintegeré   )ÚnullN)Únumberg      (@Úobject)Ústringr*   )r   r    Ú
assertTrueÚallr"   r   r^   r   Útest_create_default_typesu   s   ùþÿz-TestCreateAndExtend.test_create_default_typesc                 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   ©rk   )	r   r!   r&   rf   r   Úextendr   r'   r(   )r#   rD   rk   Ú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__)rK   r!   ÚID_OF©r   r"   r   r   rQ       ó   z3TestCreateAndExtend.test_extend_idof.<locals>.id_ofzthe://correct/id/zthe://wrong/id/)r   rq   )r   r   r   rQ   N)r   r    r   r   rr   r'   rn   )r#   rQ   Ú
correct_idr   ÚOriginalÚDerivedr   r"   r   Útest_extend_idofœ   s   þü
z$TestCreateAndExtend.test_extend_idofN)r@   Ú
__module__Ú__qualname__r$   r)   r,   r9   rB   rE   rW   rY   rj   rp   rx   r   r   r   r   r      s    r   c                   @   st   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚTestLegacyTypeCheckingc                 C   s0   t ji dd�}|  t|jƒh d£¡ |  ¡  d S )Nr   rZ   >   rd   r`   re   rf   rg   ra   rb   )r   r    r   ÚsetÚDEFAULT_TYPESÚflushWarningsrA   r   r   r   rj   ´   s
   ÿ
z0TestLegacyTypeChecking.test_create_default_typesc                 C   s”   t ji dd�}t|jƒ}tƒ }t j|d|id�}|  |j|j|j|j|j	|i ƒj	|  
¡ d d ft||d�|j|j||j	|j	|  
¡ d d f¡ d S )Nr   rZ   rk   rl   r   Úmessagerm   )r   r    r   r&   rf   rn   r   r'   r(   r}   r~   )r#   r!   rD   rk   ro   r   r   r   rp   Â   s2   
þø

øöz"TestLegacyTypeChecking.test_extendc                 C   sP   ddi}|   t |¡ d¡¡ tj|dttfid�}|  | d¡¡ |  ¡  d S )Nr[   rg   rc   )Útypes)ÚassertFalser   ÚDraft7ValidatorÚis_validÚstrÚintrh   r~   )r#   r   r   r   r   r   Ú0test_types_redefines_the_validators_type_checkerá   s   
þzGTestLegacyTypeChecking.test_types_redefines_the_validators_type_checkerc              	   C   s.   | j tdtj| j j jtji i dtid� d S )NzPThe default_types argument is deprecated. Use the type_checker argument instead.r*   )Úcategoryr   ÚfilenameÚfr   r   Údefault_types)	ÚassertWarnsÚDeprecationWarningÚsysÚmodulesry   Ú__file__r   r    rf   r"   r   r   r   Ú"test_providing_default_types_warnsì   s   
ôz9TestLegacyTypeChecking.test_providing_default_types_warnsc                 C   sž   t ji i tƒ d�}|  t j¡�}|j W d  ƒ n1 sw   Y  |  dt|jƒ¡ |  t j¡� |i ƒj W d  ƒ n1 sAw   Y  |  	|  
¡ ¡ dS )aš  
        We raise an error when you ask a validator with non-default
        type checker for its DEFAULT_TYPES.

        The type checker argument is new, so no one but this library
        itself should be trying to use it, and doing so while then
        asking for DEFAULT_TYPES makes no sense (not to mention is
        deprecated), since type checkers are not strictly about Python
        type.
        r   Nz=DEFAULT_TYPES cannot be used on Validators using TypeCheckers)r   r    r	   ÚassertRaisesÚ_DontDoThatr}   rS   r„   Ú	exceptionr�   r~   ©r#   r!   Úer   r   r   Ú?test_cannot_ask_for_default_types_with_non_default_type_checkerü   s    ýÿþÿzVTestLegacyTypeChecking.test_cannot_ask_for_default_types_with_non_default_type_checkerc                 C   s:   t ji i tƒ d�}|  |  ¡ ¡ |i ƒ |  |  ¡ ¡ d S )Nr   )r   r    r	   r�   r~   rA   r   r   r   Ú2test_providing_explicit_type_checker_does_not_warn  s   ýzITestLegacyTypeChecking.test_providing_explicit_type_checker_does_not_warnc                 C   s6   t ji i d�}|  |  ¡ ¡ |i ƒ |  |  ¡ ¡ d S )NrZ   )r   r    r�   r~   rA   r   r   r   Ú$test_providing_neither_does_not_warn#  s   z;TestLegacyTypeChecking.test_providing_neither_does_not_warnc                 C   sf   |   t¡�}tji i dtitƒ d� W d   ƒ n1 sw   Y  |  dt|jƒ¡ |  	|  
¡ ¡ d S )Nr*   )r   r   rŠ   r   z:Do not specify default_types when providing a type checker)r‘   Ú	TypeErrorr   r    rf   r	   rS   r„   r“   r�   r~   ©r#   r•   r   r   r   Ú5test_providing_default_types_with_type_checker_errors*  s   üÿþzLTestLegacyTypeChecking.test_providing_default_types_with_type_checker_errorsc                 C   sn   t ji i dtid�}|  t¡�}t j|i tƒ d� W d   ƒ n1 s#w   Y  |  dt|j	ƒ¡ |  
¡  d S )Nr`   )r   r   rŠ   )r   r   z‚Cannot extend a validator created with default_types with a type_checker. Update the validator to use a type_checker when created.)r   r    r4   r‘   r™   rn   r	   rS   r„   r“   r~   r”   r   r   r   Ú<test_extending_a_legacy_validator_with_a_type_checker_errors9  s"   ýýÿúzSTestLegacyTypeChecking.test_extending_a_legacy_validator_with_a_type_checker_errorsc                 C   s8   t ji i d�}|  |  ¡ ¡ t  |¡ |  |  ¡ ¡ d S )N)r   rŠ   )r   r    rh   r~   rn   r�   rA   r   r   r   Ú1test_extending_a_legacy_validator_does_not_rewarnP  s   
zHTestLegacyTypeChecking.test_extending_a_legacy_validator_does_not_rewarnc                 C   s@   t ji i d�}|  |  ¡ ¡ |  tdtj| jj j	t
|d¡ d S ©NrZ   zcThe DEFAULT_TYPES attribute is deprecated. See the type checker attached to this validator instead.r}   ©r   r    r�   r~   r‹   rŒ   r�   rŽ   ry   r�   ÚgetattrrA   r   r   r   Ú"test_accessing_default_types_warnsW  s   õz9TestLegacyTypeChecking.test_accessing_default_types_warnsc                 C   sD   t ji i d�}|  |  ¡ ¡ |  tdtj| jj j	t
|i ƒd¡ d S rž   rŸ   rA   r   r   r   Ú2test_accessing_default_types_on_the_instance_warnsi  s   õzITestLegacyTypeChecking.test_accessing_default_types_on_the_instance_warnsc                 C   sF   t ji i d�}|  |  ¡ ¡ | jtdtj| jj j	|i dt
id� d S )NrZ   zaThe types argument is deprecated. Provide a type_checker to jsonschema.validators.extend instead.Úbar)r‡   r   rˆ   r‰   r   r€   )r   r    r�   r~   r‹   rŒ   r�   rŽ   ry   r�   rf   rA   r   r   r   Ú"test_providing_types_to_init_warns{  s   
ôz9TestLegacyTypeChecking.test_providing_types_to_init_warnsN)r@   ry   rz   rj   rp   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S )ÚTestIterErrorsc                 C   s   t  i ¡| _d S r%   )r   ÚDraft3Validatorr   r"   r   r   r   r$   �  s   zTestIterErrors.setUpc                 C   sn   ddg}dg d¢g d¢gddœ}dd	„ | j  ||¡D ƒ}d
|d f dd|d f g}|  t|ƒt|ƒ¡ d S )Nr2   é   r`   )ÚaÚbÚc)Údr•   r‰   é   )ÚdisallowÚenumÚminItemsc                 s   s   � | ]}|j V  qd S r%   )r   ©r]   r•   r   r   r   r_   ›  s   € z2TestIterErrors.test_iter_errors.<locals>.<genexpr>z%r is disallowed for [1, 2]r­   z[1, 2] is too shortz[1, 2] is not one of %rr®   )r   r3   r   Úsorted)r#   r   r   ÚgotÚexpectedr   r   r   r9   “  s   ýýzTestIterErrors.test_iter_errorsc                 C   sX   ddgdddœ}dddid	did
g d¢dœdœi}t | j ||¡ƒ}|  t|ƒd¡ d S )Nr§   r2   é   Úspam©r*   r£   ÚbazÚquuxÚ
propertiesr[   rg   r¯   é
   ©r§   é   é   é   ©Úmaximumr®   ©r*   r£   r·   r¼   )r4   r   r3   r   r5   )r#   r   r   r7   r   r   r   Ú0test_iter_errors_multiple_failures_one_validator£  s   ýÿz?TestIterErrors.test_iter_errors_multiple_failures_one_validatorN)r@   ry   rz   r$   r9   rÂ   r   r   r   r   r¥   �  s    r¥   c                   @   s¬   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)S )*ÚTestValidationErrorMessagesc                 O   sb   |  dtj¡ |  tj¡�}tj||g|¢R i |¤Ž W d   ƒ |jjS 1 s(w   Y  |jjS )NÚcls)	Ú
setdefaultr   r¦   r‘   r
   r   Úvalidater“   r   )r#   r   r   ÚargsÚkwargsr•   r   r   r   Úmessage_for²  s   
ÿþz'TestValidationErrorMessages.message_forc                 C   s&   | j dddid�}|  |dd ¡ d S ©Nr2   r[   rg   ©r   r   z1 is not of type %r©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 ¡ d S rÊ   rÌ   rÍ   r   r   r   Útest_single_type_list_failure¼  s   z9TestValidationErrorMessages.test_single_type_list_failurec                 C   s.   d}| j ddt|ƒid�}|  |d| ¡ d S )N)rg   rf   r2   r[   rË   z1 is not of type %r, %r)rÉ   r4   r   )r#   r€   r   r   r   r   Útest_multiple_type_failureÀ  s   z6TestValidationErrorMessages.test_multiple_type_failurec                 C   s2   dddigi}| j dd|gid�}|  |d¡ d S )Nr[   Úminimumr¬   r2   rË   ú1 is less than the minimum of 3rÌ   )r#   r[   r   r   r   r   Ú&test_object_without_title_type_failureÅ  s   zBTestValidationErrorMessages.test_object_without_title_type_failurec                 C   s.   ddddœgi}| j d|d�}|  |d¡ d S )Nr[   ÚFoor¬   )ÚnamerÑ   r2   rË   rÒ   rÌ   ©r#   r   r   r   r   r   Ú#test_object_with_named_type_failureÊ  s   z?TestValidationErrorMessages.test_object_with_named_type_failurec                 C   ó"   | j dddid�}|  |d¡ d S )Nr2   rÑ   r§   rË   z1 is less than the minimum of 2rÌ   rÍ   r   r   r   Útest_minimumÏ  ó   z(TestValidationErrorMessages.test_minimumc                 C   rØ   )Nr2   rÀ   r   rË   z"1 is greater than the maximum of 0rÌ   rÍ   r   r   r   Útest_maximumÓ  rÚ   z(TestValidationErrorMessages.test_maximumc                 C   sB   d\}}d||ii}| j ddi|tjd�}|  |d||f ¡ d S ©N©r£   r*   Údependenciesr£   r§   ©r   r   rÄ   z%r is a dependency of %r©rÉ   r   r¦   r   ©r#   ÚdependÚonr   r   r   r   r   Ú test_dependencies_single_element×  s   ýz<TestValidationErrorMessages.test_dependencies_single_elementc                 C   óD   d\}}d||gii}| j ddi|tjd�}|  |d||f ¡ d S rÜ   rà   rá   r   r   r   Útest_dependencies_list_draft3á  ó   ýz9TestValidationErrorMessages.test_dependencies_list_draft3c                 C   rå   rÜ   )rÉ   r   r‚   r   rá   r   r   r   Útest_dependencies_list_draft7ë  rç   z9TestValidationErrorMessages.test_dependencies_list_draft7c                 C   s&   | j dgg ddœd�}|  d|¡ d S )Nr§   F©ÚitemsÚadditionalItemsrË   z(2 was unexpected)©rÉ   rS   rÍ   r   r   r   Ú#test_additionalItems_single_failureõ  s
   þz?TestValidationErrorMessages.test_additionalItems_single_failurec                 C   s(   | j g d¢g ddœd�}|  d|¡ d S )N)r2   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   s4   d}ddi}| j |di|d�}|  d|f |¡ d S )Nr*   ÚadditionalPropertiesFr§   rË   z(%r was unexpected)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ï   Fr*   r£   rË   zwere unexpected))rÉ   r   ÚfromkeysrS   ÚreprrÖ   r   r   r   Ú+test_additionalProperties_multiple_failures	  s   þzGTestValidationErrorMessages.test_additionalProperties_multiple_failuresc                 C   s.   ddi}| j ddi|tjd�}|  d|¡ d S )NÚconstrc   r*   r£   rß   z12 was expected©rÉ   r   ÚDraft6ValidatorrS   rÖ   r   r   r   Ú
test_const  s   ýz&TestValidationErrorMessages.test_constc                 C   s4   dddii}| j di g g|tjd�}|  d|¡ d S )NÚcontainsrõ   rc   r§   rß   z4None of [2, {}, []] are valid under the given schemarö   rÖ   r   r   r   Útest_contains  s   ýþz)TestValidationErrorMessages.test_containsc                 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   rN   +  s    zQTestValidationErrorMessages.test_invalid_format_default_message.<locals>.<lambda>ÚformatÚbla)r   r   Úformat_checkerzis not a)r   ÚchecksrÉ   rS   ró   )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 )Nrf   Fr[   rg   )ú^abc$ú^def$)r[   rï   ÚpatternPropertiesÚzebraé{   rß   z,{} does not match any of the regexes: {}, {}r  r  iÈ  )r	  Úfishz.{}, {} do not match any of the regexes: {}, {}r  )rÉ   r   ÚDraft4Validatorr   r   ró   rÖ   r   r   r   Ú1test_additionalProperties_false_patternProperties8  s8   þþýÿþýÿþzMTestValidationErrorMessages.test_additionalProperties_false_patternPropertiesc                 C   s"   | j ddtjd�}|  d|¡ d S )Nr:   Frß   z'False schema does not allow 'something')rÉ   r   r‚   rS   rÍ   r   r   r   Útest_False_schemaV  s   ýz-TestValidationErrorMessages.test_False_schemaN)r@   ry   rz   rÉ   rÎ   rÏ   rÐ   rÓ   r×   rÙ   rÛ   rä   ræ   rè   rí   rî   rñ   rô   rø   rú   r  r  r  r   r   r   r   rÃ   ±  s*    


	rÃ   c                   @   s|   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd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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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tddgƒ¡ |  |jtddgƒ¡ |  |jtg d¢ƒ¡ |  t|jƒd¡ d S )Né   ÚanyOfrÑ   é   r[   rg   r2   r   r§   )r  r   rÑ   )r  r2   r[   )r   r  r4   r3   r   r5   r   r0   r   r   ÚassertIsNoneÚparentÚpathr   Úrelative_pathÚabsolute_pathr1   Úrelative_schema_pathÚabsolute_schema_pathÚcontextÚsorted_errorsÚassertIsr�   ©r#   r   r   r   r7   r•   Úe1Úe2r   r   r   Ú
test_anyOfb  sb   þÿ
ÿ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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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tg d¢ƒ¡ |  |jtg d¢ƒ¡ |  |jtg d¢ƒ¡ |  |j¡ d S )Nr*   r2   r[   rb   rf   r®   r§   ©r[   r¹   r   )r[   r   r[   )r2   r¹   r*   r®   )r[   r2   r¹   r*   r®   )r   r¦   r4   r3   r   r5   r   r0   r   r   r  r  r  r   r  r  r1   r  r  r  r  r  r�   r  r   r   r   Ú	test_type¤  sp   þþÿ

ÿÿ
þ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¡ d S )Nr§   r2   r´   rµ   r¶   r¹   r[   rg   r¯   rº   r»   r¿   rÁ   r£   r·   r*   r®   rÀ   )
r   r¦   r3   r  r   r  r   r  r  r   )	r#   r   r   r   r7   r  r  Úe3Úe4r   r   r   Útest_single_nestingî  s4   ýÿ

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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 )Nr2   r§   r·   )r*   r£   r¸   rg   rf   r®   r¬   r`   ÚrequiredTr¯   )r£   r·   r!  )r[   rê   r   r£   )r2   r£   r£   )r2   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¦   r3   r  r   r  r   r1   r4   r   )r#   r   r   r   r7   r  r  r#  r$  Úe5Úe6r   r   r   Útest_multiple_nesting  sV   
þþþþþ

ÿþþÿ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\}|  |jtg d¢ƒ¡ |  |jtg d¢ƒ¡ |j\}|  |jtg d¢ƒ¡ |  |jtg d¢ƒ¡ d S )NÚnoder  rf   rÕ   Úchildrenr[   rg   ú^.*$ú$refz#/definitions/node)r[   r  )rÕ   r+  )r[   r&  r¹   Úroot)Údefinitionsr[   r&  r¹   r¨   Úab)r¹   r.  r  )r.  r+  r¨   )	r¹   r.  r  r   r¹   r+  r  r,  r  )r.  r+  r¨   r+  r0  )r¹   r.  r  r   r¹   r+  r  r,  r  r   r¹   r+  r  r,  r  )r   r  r3   r   r  r   r  r  )r#   r   r   r   r•   r  r  r   r   r   Útest_recursiveF  sp   ÿÿÿþüýÿÿ
èÿÿþÿþÿ
ÿÿÿÿÿÿÿ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
¡ d S )Nr£   r§   rÝ   rï   rb   r  ©r[   rÑ   r*   r[   rÑ   ©r   r¦   r3   r  r   r  r   r   ©r#   r   r   r   r7   r  r  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¡ d S )Nr2   r§   rÝ   r  r[   rg   rÑ   r  r£   r*   r3  r4  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	¡ d S )
Nr*   r2   rb   r  r2  ré   r   r[   rÑ   r3  r4  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	¡ d S )
N)r*   r£   r2   rb   r  r2  ré   r2   r§   r[   rÑ   r3  r4  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ddidf ¡ |  |jtg ƒ¡ |  |jtddgƒ¡ d S )Nr*   rc   ÚpropertyNamesÚnotrõ   z%r is not allowed for %r©	r   r‚   r3   r   r   r   r  r   r1   )r#   r   r   r   Úerrorr   r   r   Útest_propertyNamesë  s   
þz-TestValidationErrorDetails.test_propertyNamesc                 C   sp   ddiddidœ}t  |¡}| d¡\}|  |jd¡ |  |jd¡ |  |jtg ƒ¡ |  |jtg d¢ƒ¡ d S )Nrõ   rc   é   )ÚifÚthenú13 was expected)r?  r@  rõ   r;  ©r#   r   r   r<  r   r   r   Útest_if_thenú  ó   þ
z'TestValidationErrorDetails.test_if_thenc                 C   sp   ddiddidœ}t  |¡}| d¡\}|  |jd¡ |  |jd¡ |  |jtg ƒ¡ |  |jtg d¢ƒ¡ d S )Nrõ   rc   r>  )r?  Úelser´   rA  )r?  rE  rõ   r;  rB  r   r   r   Útest_if_else  rD  z'TestValidationErrorDetails.test_if_elsec              
   C   sN   t  d¡}| d¡\}|  |j|j|j|j|j|j	fdd d ddt
g ƒf¡ d S )NFrc   zFalse schema does not allow 12)r   r‚   r3   r   r   r   r0   r   r   r1   r   )r#   r   r<  r   r   r   Útest_boolean_schema_False  s$   
ú	ú÷z4TestValidationErrorDetails.test_boolean_schema_Falsec                 C   s�   ddddii}}t jd|it jdi ||id�d�}| d	d
i¡\}|  |j|j|j|j|j	|j
|jfdddd
td	gƒdditddgƒf¡ d S )NÚsomeRefrï   r[   rb   r-  rI   ©Ústore©Úresolverr*   ÚnotAnIntegerz''notAnInteger' is not of type 'integer')r   r‚   ÚRefResolverr3   r   r   r   r0   r   r  r   r1   r   )r#   Úrefr   r   r<  r   r   r   Útest_ref-  s0   þù

ùöz#TestValidationErrorDetails.test_refN)r@   ry   rz   r   r"  r%  r)  r1  r5  r6  r7  r8  r=  rC  rF  rG  rP  r   r   r   r   r  _  s    BJ"6br  c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚMetaSchemaTestsMixinc                 C   sH   |   tj¡� | j ddtƒ ii¡ W d   ƒ d S 1 sw   Y  d S )Nr¹   Útest)r‘   r
   ÚSchemaErrorr!   Úcheck_schemarf   r"   r   r   r   Útest_invalid_propertiesM  s   "ÿz,MetaSchemaTestsMixin.test_invalid_propertiesc                 C   sB   |   tj¡� | j ddi¡ W d   ƒ d S 1 sw   Y  d S )Nr¯   Ú1)r‘   r
   rS  r!   rT  r"   r   r   r   Útest_minItems_invalid_stringQ  s   "þz1MetaSchemaTestsMixin.test_minItems_invalid_stringc                 C   s   | j  dg i¡ dS )z–
        Technically, all the spec says is they SHOULD have elements, not MUST.

        See https://github.com/Julian/jsonschema/issues/529.
        r®   N©r!   rT  r"   r   r   r   Útest_enum_allows_empty_arraysV  s   z2MetaSchemaTestsMixin.test_enum_allows_empty_arraysc                 C   s   | j  dddgi¡ dS )z’
        Technically, all the spec says is they SHOULD be unique, not MUST.

        See https://github.com/Julian/jsonschema/issues/529.
        r®   rc   NrX  r"   r   r   r   Ú!test_enum_allows_non_unique_items^  s   z6MetaSchemaTestsMixin.test_enum_allows_non_unique_itemsN)r@   ry   rz   rU  rW  rY  rZ  r   r   r   r   rQ  K  s
    rQ  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e ed¡d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   ó$   | j \}}|  |  |¡ |¡¡ d S r%   )Úvalidrh   r!   rƒ   ©r#   r   r   r   r   r   Útest_valid_instances_are_validh  ó   
z1ValidatorTestMixin.test_valid_instances_are_validc                 C   r\  r%   )Úinvalidr�   r!   rƒ   r^  r   r   r   Ú$test_invalid_instances_are_not_validl  r`  z7ValidatorTestMixin.test_invalid_instances_are_not_validc                 C   s    |   tƒ tƒ i¡jtƒ d� d S )N©r   )r!   rf   rÆ   r"   r   r   r   Ú(test_non_existent_properties_are_ignoredp  s    z;ValidatorTestMixin.test_non_existent_properties_are_ignoredc                 C   s   |   |  i ¡jtj¡ d S r%   )ÚassertIsInstancer!   rL  r   rN  r"   r   r   r   Ú.test_it_creates_a_ref_resolver_if_not_provideds  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ÚsomeCoolRefr[   rb   rI   rI  r-  rK  )r   rN  r!   r‘   r
   r   rÆ   )r#   rO  r   rL  r   r   r   r   Ú#test_it_delegates_to_a_ref_resolvery  s   "ÿz6ValidatorTestMixin.test_it_delegates_to_a_ref_resolverc                    sh   G ‡ fdd„dt ƒ}|ƒ }ddi}ˆ  tj¡� ˆ j||d� d¡ W d  ƒ dS 1 s-w   Y  dS )zb
        Legacy RefResolvers support only the context manager form of
        resolution.
        c                       s   e Zd Ze‡ fdd„ƒZdS )zXValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolver.<locals>.LegacyRefResolverc                 3   s   � ˆ   |d¡ ddiV  d S )Núthe refr[   rb   ©r   )ÚthisrO  r"   r   r   Ú	resolvingˆ  s   €zbValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolver.<locals>.LegacyRefResolver.resolvingN)r@   ry   rz   r   rl  r   r"   r   r   ÚLegacyRefResolver‡  s    rm  r-  ri  rK  N)rf   r‘   r
   r   r!   rÆ   )r#   rm  rL  r   r   r"   r   Ú*test_it_delegates_to_a_legacy_ref_resolver�  s   "ÿz=ValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolverc                 C   ó   |   |  i ¡ dd¡¡ d S )Nr*   rg   )rh   r!   r\   r"   r   r   r   Ú#test_is_type_is_true_for_valid_type“  ó   z6ValidatorTestMixin.test_is_type_is_true_for_valid_typec                 C   ro  )Nr*   r`   ©r�   r!   r\   r"   r   r   r   Ú&test_is_type_is_false_for_invalid_type–  rq  z9ValidatorTestMixin.test_is_type_is_false_for_invalid_typec                 C   s4   |   |  i ¡ dd¡¡ |   |  i ¡ dd¡¡ d S )NTrb   re   rr  r"   r   r   r   Ú,test_is_type_evades_bool_inheriting_from_int™  s   z?ValidatorTestMixin.test_is_type_evades_bool_inheriting_from_intz-In Python 3 json.load always produces unicodec                 C   s   |   ddi¡ d¡ d S )Nr[   rg   s   foo©r!   rÆ   r"   r   r   r   Ú$test_string_a_bytestring_is_a_string�  s   z7ValidatorTestMixin.test_string_a_bytestring_is_a_stringc                 C   s   |   ddi¡ d¡ dS )zF
        See https://github.com/Julian/jsonschema/issues/611.
        Úpatternr*   Nru  r"   r   r   r   Ú#test_patterns_can_be_native_strings¡  s   z6ValidatorTestMixin.test_patterns_can_be_native_stringsc                 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ê   r[   re   c                 S   s   t |tttfƒot |tƒ S r%   )Ú
isinstancer…   Úfloatr   Úbool©r  rü   r   r   r   rN   ­  s    
ÿzGValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<lambda>©r   r2   gš™™™™™ñ?r¾   r*   Tc                 S   s   g | ]}|j ‘qS r   rc  )r]   r<  r   r   r   Ú
<listcomp>¸  s    zIValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<listcomp>)	r   rn   r!   r(   ÚredefinerÆ   r   r   r3   )r#   r   r!   r   ra  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   Úcarrot©r  Ú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 d   ƒ n1 s9w   Y  ˆ |j	j
ˆ ¡ d S )
NzBad!r*   )Úraisesc                    s,   | dkrdS | dkrˆ ‚ˆ  d | ¡¡ d S )NÚgoodTÚbadz What is {}? [Baby Don't Hurt Me])Úfailr   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   r  r“   Ú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 )Nr[   c                 S   ó
   t |tƒS r%   ©ry  r…   r|  r   r   r   rN   å  ó   
 z@ValidatorTestMixin.test_non_string_custom_type.<locals>.<lambda>r}  r´   )rf   r   rn   r!   r(   r  rÆ   )r#   Únon_string_typer   ÚCrazyr   r   r   Útest_non_string_custom_typeÞ  s   
þþz.ValidatorTestMixin.test_non_string_custom_typec                 C   st   t j| j| jj ddd„ ¡d�}|  tj¡�}|ddiƒ d¡ W d  ƒ n1 s*w   Y  |  	d	t
|jƒ¡ dS )
z‘
        A tuple instance properly formats validation errors for uniqueItems.

        See https://github.com/Julian/jsonschema/pull/224
        r`   c                 S   r‘  r%   )ry  Útupler|  r   r   r   rN   ô  r“  zNValidatorTestMixin.test_it_properly_formats_tuples_in_errors.<locals>.<lambda>r}  ÚuniqueItemsT)r2   r2   Nz(1, 1) has non-unique elements)r   rn   r!   r(   r  r‘   r
   r   rÆ   rS   r„   r“   )r#   ÚTupleValidatorr•   r   r   r   Ú)test_it_properly_formats_tuples_in_errorsê  s   þþÿz<ValidatorTestMixin.test_it_properly_formats_tuples_in_errorsN)r@   ry   rz   r_  rb  rd  rf  rh  rn  rp  rs  rt  ÚunittestÚskipIfr   rv  rx  r€  r…  r†  r�  r–  rš  r   r   r   r   r[  g  s&    

r[  c                   @   sL   e Zd ZdZdd„ Zdd„ Ze edƒ¡dd„ ƒZ	e edƒ¡d	d
„ ƒZ
dS )ÚAntiDraft6LeakMixinzN
    Make sure functionality from draft 6 doesn't leak backwards in time.
    c                 C   óN   |   tj¡�}| j d¡ W d   ƒ n1 sw   Y  |  dt|jƒ¡ d S )NTzTrue is not of type©r‘   r
   rS  r!   rT  rS   r„   r“   rš   r   r   r   Útest_True_is_not_a_schema  ó   ÿz-AntiDraft6LeakMixin.test_True_is_not_a_schemac                 C   rž  )NFzFalse is not of typerŸ  rš   r   r   r   Útest_False_is_not_a_schema  r¡  z.AntiDraft6LeakMixin.test_False_is_not_a_schemai  c                 C   ó^   t  di ¡}|  t¡�}| jd|d� d¡ W d   ƒ n1 s w   Y  |  |jtj	¡ d S )NrI   TrK  rc   ©
r   rN  r‘   Ú	Exceptionr!   rÆ   ÚassertNotIsInstancer“   r
   r   ©r#   rL  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£  )NrI   FrK  rc   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)r@   ry   rz   Ú__doc__r   r¢  r›  Úskipr   r¨  rª  r   r   r   r   r�  ü  s    
r�  c                   @   sF   e Zd ZejZi i fZddidfZdd„ Zdd„ Z	dd	„ Z
d
d„ ZdS )ÚTestDraft3Validatorr[   rb   r*   c                 C   s   |   ddi¡}| tƒ ¡ d S ©Nr[   Úany)r!   rÆ   rf   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   rN   *  r“  zBTestDraft3Validator.test_any_type_is_redefinable.<locals>.<lambda>r}  r[   rc   r*   N)	r   rn   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"   |   |  i ¡ tƒ ddi¡¡ d S r®  )rh   r!   rƒ   rf   r"   r   r   r   Ú!test_is_type_is_true_for_any_type2  s   "z5TestDraft3Validator.test_is_type_is_true_for_any_typec                 C   s8   |   |  i ¡ dd¡¡ |   |  i ¡ dddi¡¡ d S )NTra   r[   r¯  )rh   r!   r\   rƒ   r"   r   r   r   Ú6test_is_type_does_not_evade_bool_if_it_is_being_tested5  s    zJTestDraft3Validator.test_is_type_does_not_evade_bool_if_it_is_being_testedN)r@   ry   rz   r   r¦   r!   r]  ra  r°  r±  r²  r³  r   r   r   r   r­    s    r­  c                   @   ó&   e Zd ZejZi i fZddidfZdS )ÚTestDraft4Validatorr[   rb   r*   N)r@   ry   rz   r   r  r!   r]  ra  r   r   r   r   rµ  :  ó    rµ  c                   @   r´  )ÚTestDraft6Validatorr[   rb   r*   N)r@   ry   rz   r   r÷   r!   r]  ra  r   r   r   r   r·  @  r¶  r·  c                   @   r´  )ÚTestDraft7Validatorr[   rb   r*   N)r@   ry   rz   r   r‚   r!   r]  ra  r   r   r   r   r¸  F  r¶  r¸  c                   @   sl   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S )ÚTestValidatorForc                 C   ó<   ddi}|   t |¡tj¡ ddi}|   t |¡tj¡ d S )Nú$schemaú&http://json-schema.org/draft-03/schemaú'http://json-schema.org/draft-03/schema#)r  r   Úvalidator_forr¦   r+   r   r   r   Útest_draft_3M  ó   þþzTestValidatorFor.test_draft_3c                 C   rº  )Nr»  ú&http://json-schema.org/draft-04/schemaú'http://json-schema.org/draft-04/schema#)r  r   r¾  r  r+   r   r   r   Útest_draft_4Z  rÀ  zTestValidatorFor.test_draft_4c                 C   rº  )Nr»  ú&http://json-schema.org/draft-06/schemaú'http://json-schema.org/draft-06/schema#)r  r   r¾  r÷   r+   r   r   r   Útest_draft_6g  rÀ  zTestValidatorFor.test_draft_6c                 C   rº  )Nr»  ú&http://json-schema.org/draft-07/schemaú'http://json-schema.org/draft-07/schema#)r  r   r¾  r‚   r+   r   r   r   Útest_draft_7t  rÀ  zTestValidatorFor.test_draft_7c                 C   ó   |   t d¡tj¡ d S )NT©r  r   r¾  Ú_LATEST_VERSIONr"   r   r   r   Ú	test_True�  ó   þzTestValidatorFor.test_Truec                 C   rÊ  rý   rË  r"   r   r   r   Ú
test_False‡  rÎ  zTestValidatorFor.test_Falsec                 C   s6   t jddiddd„ d�}ddi}|  t  |¡|¡ d S )NrC   rF   Ú12c                 S   rG   rH   rJ   rL   r   r   r   rN   ‘  rO   z8TestValidatorFor.test_custom_validator.<locals>.<lambda>rP   r»  ©r   r    r  r¾  ©r#   r!   r   r   r   r   Útest_custom_validator�  s   ýþz&TestValidatorFor.test_custom_validatorc                 C   s0   t jddidd�}ddi}|  t  |¡|¡ d S )Nr   rX   Ú13r<   r»  rÑ  rÒ  r   r   r   Útest_custom_validator_draft6™  s   þþz-TestValidatorFor.test_custom_validator_draft6c                 C   s   |   t i ¡tj¡ d S r%   rË  r"   r   r   r   Ú%test_validator_for_jsonschema_default¤  s   z6TestValidatorFor.test_validator_for_jsonschema_defaultc                 C   s   |   tji d d�d ¡ d S )N)Údefault)r  r   r¾  r"   r   r   r   Ú!test_validator_for_custom_default§  s   z2TestValidatorFor.test_validator_for_custom_defaultc                 C   s,   | j tdtj| j j jtjddii d� d S )Nz‚The metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future.r»  ÚunknownSchema)r‡   r   rˆ   r‰   r   r×  )r‹   rŒ   r�   rŽ   ry   r�   r   r¾  r"   r   r   r   Ú1test_warns_if_meta_schema_specified_was_not_foundª  s   
ôzBTestValidatorFor.test_warns_if_meta_schema_specified_was_not_foundc                 C   s"   t ji i d�f |  |  ¡ ¡ d S )N)r   r×  )r   r¾  r�   r~   r"   r   r   r   Ú0test_does_not_warn_if_meta_schema_is_unspecifiedº  s   zATestValidatorFor.test_does_not_warn_if_meta_schema_is_unspecifiedN)r@   ry   rz   r¿  rÃ  rÆ  rÉ  rÍ  rÏ  rÓ  rÕ  rÖ  rØ  rÚ  rÛ  r   r   r   r   r¹  L  s    r¹  c                   @   sT   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚTestValidatec                 C   s2   g }|   |d|j¡ t i |¡ |  ||g¡ d S )NrT  )ÚpatchÚappendr   rÆ   r   )r#   r   r!   Úresultr   r   r   Ú
assertUsesÀ  s   zTestValidate.assertUsesc                 C   ó,   | j dditjd� | j dditjd� d S )Nr»  r½  ©r   r!   r¼  )rà  r   r¦   r"   r   r   r   Útest_draft3_validator_is_chosenÆ  ó   þ
þz,TestValidate.test_draft3_validator_is_chosenc                 C   rá  )Nr»  rÂ  râ  rÁ  )rà  r   r  r"   r   r   r   Útest_draft4_validator_is_chosenÑ  rä  z,TestValidate.test_draft4_validator_is_chosenc                 C   rá  )Nr»  rÅ  râ  rÄ  )rà  r   r÷   r"   r   r   r   Útest_draft6_validator_is_chosenÜ  rä  z,TestValidate.test_draft6_validator_is_chosenc                 C   rá  )Nr»  rÈ  râ  rÇ  ©rà  r   r‚   r"   r   r   r   Útest_draft7_validator_is_chosenç  rä  z,TestValidate.test_draft7_validator_is_chosenc                 C   s   | j i tjd� d S )Nrâ  rç  r"   r   r   r   Ú$test_draft7_validator_is_the_defaultò  rt   z1TestValidate.test_draft7_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 )Nrc   r[   rg   z3(?s)Failed validating u?'.*' in schema.*On instance)r‘   r
   r   r   rÆ   ÚassertRegexpMatchesr„   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 )Nrc   r[   z5(?s)Failed validating u?'.*' in metaschema.*On schema)r‘   r
   rS  r   rÆ   rê  r„   r“   rš   r   r   r   Útest_schema_error_messageý  rì  z&TestValidate.test_schema_error_messagec                 C   sb   dddiddigi}|   tj¡�}t d|¡ W d   ƒ n1 s!w   Y  |  dt|jƒ¡ d S )NÚoneOfr[   rg   r`   rc   z12 is not of type)r‘   r
   r   r   rÆ   rS   r„   r“   )r#   r   r•   r   r   r   Útest_it_uses_best_match  s
   ÿz$TestValidate.test_it_uses_best_matchN)r@   ry   rz   rà  rã  rå  ræ  rè  ré  rë  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#S )$ÚTestRefResolverrI   zfoo://storedÚstoredr   c                 C   s.   i | _ | j| ji| _t | j| j | j¡| _d S r%   )ÚreferrerÚ
stored_uriÚstored_schemarJ  r   rN  Úbase_urirL  r"   r   r   r   r$     s
   
ÿzTestRefResolver.setUpc                    sd   t jjd }ˆ  ˆ jd‡ fdd„¡ ˆ j |¡�}W d   ƒ n1 s#w   Y  ˆ  |t jj¡ d S )NrC   Úresolve_remotec                     s
   ˆ   d¡S )NzShould not have been called!)rŠ  )rÇ   rÈ   r"   r   r   rN     r“  zXTestRefResolver.test_it_does_not_retrieve_schema_urls_from_the_network.<locals>.<lambda>)r   r¦   r'   rÝ  rL  rl  r   ©r#   rO  Úresolvedr   r"   r   Ú6test_it_does_not_retrieve_schema_urls_from_the_network  s   
ýÿzFTestRefResolver.test_it_does_not_retrieve_schema_urls_from_the_networkc                 C   s\   d}dt ƒ i| jd< | j |¡�}|  || jd d ¡ W d   ƒ d S 1 s'w   Y  d S )Nz#/properties/foor*   r¹   )rf   rò  rL  rl  r   r÷  r   r   r   Útest_it_resolves_local_refs%  s
   "ÿz+TestRefResolver.test_it_resolves_local_refsc                 C   sœ   dddidœ}t jj|dd„ d�}| d¡�}|  ||d	 ¡ W d   ƒ n1 s)w   Y  | d
¡�}|  ||d	 ¡ W d   ƒ d S 1 sGw   Y  d S )Nzhttp://bar/schema#r*   r£   )rC   r¨   c                 S   rG   rH   rJ   rs   r   r   r   rN   /  rO   zETestRefResolver.test_it_resolves_local_refs_with_id.<locals>.<lambda>©rQ   z#/ar¨   zhttp://bar/schema#/a)r   rN  Úfrom_schemarl  r   ©r#   r   rL  rø  r   r   r   Ú#test_it_resolves_local_refs_with_id+  s   þÿ"ÿz3TestRefResolver.test_it_resolves_local_refs_with_idc                 C   sŠ   | j  | j¡�}|  || j¡ W d   ƒ n1 sw   Y  ddi| j jd< | j  d¡�}|  |d¡ W d   ƒ d S 1 s>w   Y  d S )Nr*   rc   Ú
cached_refzcached_ref#/foo)rL  rl  ró  r  rô  rJ  r   )r#   rø  r   r   r   Útest_it_retrieves_stored_refs6  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·   rc   Úrequestsú
http://bar)r�   rŽ   r   Ú__setitem__ÚReallyFakeRequestsrL  rl  r   )r#   rO  r   rø  r   r   r   Ú,test_it_retrieves_unstored_refs_via_requests>  s   
ÿ"ÿz<TestRefResolver.test_it_retrieves_unstored_refs_via_requestsc                    sž   d}ddi‰ dt jv rˆ t jjdt jd ¡ d t jd< t‡ ‡fdd„ƒ}ˆ ttdtj¡ |t_ˆj 	|¡�}W d   ƒ n1 sBw   Y  ˆ 
|d¡ d S )Nr  r·   rc   r  c                 3   s(   � ˆ  | d¡ tt ˆ ¡ d¡ƒV  d S )Nr  Úutf8)r   r   ÚjsonÚdumpsÚencode©Úurl©r   r#   r   r   Úfake_urlopenU  s   €zQTestRefResolver.test_it_retrieves_unstored_refs_via_urlopen.<locals>.fake_urlopenÚurlopen)r�   rŽ   r   r  r   Úsetattrr   r  rL  rl  r   )r#   rO  r  rø  r   r  r   Ú+test_it_retrieves_unstored_refs_via_urlopenK  s   
ÿ
ÿz;TestRefResolver.test_it_retrieves_unstored_refs_via_urlopenc                 C   sœ   t jddd��}|  tj|j¡ t ddi|¡ W d   ƒ n1 s"w   Y  d t	|jƒ¡}| j
 |¡�}|  |d¡ W d   ƒ d S 1 sGw   Y  d S )NFÚwt)ÚdeleteÚmoder*   r£   zfile://{}#foo)ÚtempfileÚNamedTemporaryFiler   ÚosÚremoverÕ   r  Údumpr   r   rL  rl  r   )r#   ÚtempfrO  rø  r   r   r   Ú(test_it_retrieves_local_refs_via_urlopena  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 s„w   Y  d S )	NrC   r*   c                 S   rG   rH   rJ   rs   r   r   r   rN   n  rO   zPTestRefResolver.test_it_can_construct_a_base_uri_from_a_schema.<locals>.<lambda>rû  rI   ú#zfoo#©r   rN  rü  r   rõ  Úresolution_scoperl  rý  r   r   r   Ú.test_it_can_construct_a_base_uri_from_a_schemaj  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 )NrI   r  r  rý  r   r   r   Ú9test_it_can_construct_a_base_uri_from_a_schema_without_id{  s   ÿ"ÿzITestRefResolver.test_it_can_construct_a_base_uri_from_a_schema_without_idc                    sl   ‡ ‡‡fdd„}ddi‰d‰ t jdi d|id�}| ˆ ¡�}ˆ |ˆ¡ W d   ƒ d S 1 s/w   Y  d S )Nc                    s   ˆ  | ˆ ¡ ˆS r%   rj  r  ©rO  r   r#   r   r   Úhandler†  s   z@TestRefResolver.test_custom_uri_scheme_handlers.<locals>.handlerr*   r£   ú	foo://barrI   ©Úhandlers)r   rN  rl  r   )r#   r"  rL  rø  r   r!  r   Útest_custom_uri_scheme_handlers…  s   "ÿz/TestRefResolver.test_custom_uri_scheme_handlersc                    sŠ   t ƒ g‰ ‡ ‡fdd„}d}tjdi dd|id�}| |¡� W d   ƒ n1 s(w   Y  | |¡�	 W d   ƒ d S 1 s>w   Y  d S )Nc                    ó*   zˆ   ¡ W S  ty   ˆ d¡ Y d S w )Nz#Response must not have been cached!©r?   Ú
IndexErrorrŠ  r  ©Úresponser#   r   r   r"  “  ó
   
ÿz5TestRefResolver.test_cache_remote_on.<locals>.handlerr#  rI   Tr*   ©Úcache_remoter%  ©rf   r   rN  rl  ©r#   r"  rO  rL  r   r*  r   Útest_cache_remote_on�  s   ÿÿ"ÿz$TestRefResolver.test_cache_remote_onc                    s`   t ƒ g‰ ‡ ‡fdd„}d}tjdi dd|id�}| |¡�	 W d   ƒ d S 1 s)w   Y  d S )Nc                    r'  )NzHandler called twice!r(  r  r*  r   r   r"  ¥  r,  z6TestRefResolver.test_cache_remote_off.<locals>.handlerr#  rI   Fr*   r-  r/  r0  r   r*  r   Útest_cache_remote_off¢  s   ÿ"ÿz%TestRefResolver.test_cache_remote_offc              	      s¤   t dƒ‰ ‡ fdd„}d}tjdi d|id�}|  tj¡�"}| |¡� |  d¡ W d   ƒ n1 s2w   Y  W d   ƒ n1 sAw   Y  |  |j	t ˆ ¡¡ d S )	NzOh no! What's this?c                    s   ˆ ‚r%   r   r  ©r<  r   r   r"  µ  s   zTTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_error.<locals>.handlerr#  rI   r*   r$  zShouldn't get this far!)
r�  r   rN  r‘   r
   ÚRefResolutionErrorrl  rŠ  r   r“   )r#   r"  rO  rL  Úerrr   r3  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 )NrI   zFailed to pop the scope)	r   rN  Ú	pop_scoper‘   r
   r4  rS   r„   r“   )r#   rL  Úexcr   r   r   Ú.test_helpful_error_message_on_failed_pop_scope¿  s   
ÿz>TestRefResolver.test_helpful_error_message_on_failed_pop_scopeN)r@   ry   rz   rõ  ró  rô  r$   rù  rú  rþ  r   r  r  r  r  r   r&  r1  r2  r6  r9  r   r   r   r   rð    s&    	
rð  c                 C   s   dd„ }t | |d�S )Nc                 S   s    dd„ | j D ƒdd„ | jD ƒfS )Nc                 S   ó   g | ]}t |ƒ‘qS r   ©r„   r°   r   r   r   r~  Ê  ó    z.sorted_errors.<locals>.key.<locals>.<listcomp>c                 S   r:  r   r;  r°   r   r   r   r~  Ë  r<  )r  r1   r3  r   r   r   ÚkeyÈ  s   þzsorted_errors.<locals>.key)r=  )r±   )r7   r=  r   r   r   r  Ç  s   r  c                   @   ó   e Zd Ze ¡ Zdd„ ZdS )r  c                 C   s2   | j  |¡}|d u rtdt|ƒ ƒ‚tt |¡ƒS )NzUnknown URL: )Ú
_responsesrK   r�  ró   Ú_ReallyFakeJSONResponser  r	  )r#   r  r+  r   r   r   rK   Õ  s   zReallyFakeRequests.getN)r@   ry   rz   ÚattrÚibr?  rK   r   r   r   r   r  Ð  ó    r  c                   @   r>  )r@  c                 C   s   t  | j¡S r%   )r  ÚloadsÚ	_responser"   r   r   r   r  á  s   z_ReallyFakeJSONResponse.jsonN)r@   ry   rz   rA  rB  rE  r  r   r   r   r   r@  Ü  rC  r@  )0Úcollectionsr   Ú
contextlibr   Údecimalr   Úior   r›  r   r  r  r�   r  Útwisted.trial.unittestr   rA  Ú
jsonschemar   r	   r
   r   Újsonschema.compatr   r   Újsonschema.tests._helpersr   r   r   r{   r¥   rÃ   r  rf   rQ  r[  r�  r­  rµ  r·  r¸  r¹  rÜ  rð  r  rM   r  r@  r   r   r   r   Ú<module>   sX      ]" /   o  sN ;	