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   ZhelZhellor   Zgoodbye)r   r   r   validator_valueschema_path   r   )	r!   iter_errorslistr   r
   r   r   lenZ	_contents)r#   r   r0   errorsZ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   versionZ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 idr=   r6   c                 S      |  ddS Nr=    getsr   r   r   <lambda>c       zMTestCreateAndExtend.test_validates_registers_meta_schema_id.<locals>.<lambda>r   r8   id_ofr   r    r   r   r9   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   s<   d}d|i}t j|dd | t jj| | |t j d S )Nmeta schema $idr   r6   r7   rL   rN   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).0rS   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   rV   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   rc   )	r   r!   r&   r^   r   extendr   r'   r(   )r#   r>   rc   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__)rE   r!   ID_OFr   r"   r   r   rK         z3TestCreateAndExtend.test_extend_idof.<locals>.id_ofzthe://correct/id/zthe://wrong/id/)r   ri   )r   r   r   rK   N)r   r    r   r   rj   r'   rf   )r#   rK   Z
correct_idr   ZOriginalZDerivedr   r"   r   test_extend_idof   s   
z$TestCreateAndExtend.test_extend_idofN)r:   
__module____qualname__r$   r)   r,   r4   r<   r?   rO   rQ   rb   rh   rm   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   rR   >   r\   rX   r]   r^   r_   rY   rZ   )r   r    r   setDEFAULT_TYPESflushWarningsr;   r   r   r   rb      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   rR   rc   rd   r   messagere   )r   r    r   r&   r^   rf   r   r'   r(   rr   rs   )r#   r!   r>   rc   rg   r   r   r   rh      s2   


z"TestLegacyTypeChecking.test_extendc                 C   sP   ddi}|  t|d tj|dttfid}| |d |   d S )NrS   r_   r[   )types)assertFalser   Draft7Validatoris_validstrintr`   rs   )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*   )categoryrt   filenamefr   r   default_types)	assertWarnsDeprecationWarningsysmodulesrn   __file__r   r    r^   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	   assertRaisesZ_DontDoThatrr   rM   ry   	exceptionrv   rs   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	   rv   rs   r;   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 )NrR   )r   r    rv   rs   r;   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    r^   r	   rM   ry   r   rv   rs   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 )NrX   )r   r   r   )r   r   zCannot extend a validator created with default_types with a type_checker. Update the validator to use a type_checker when created.)r   r    r1   r   r   rf   r	   rM   ry   r   rs   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    r`   rs   rf   rv   r;   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 NrR   zcThe DEFAULT_TYPES attribute is deprecated. See the type checker attached to this validator instead.rr   r   r    rv   rs   r   r   r   r   rn   r   getattrr;   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   r;   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 )NrR   zaThe types argument is deprecated. Provide a type_checker to jsonschema.validators.extend instead.bar)r|   rt   r}   r~   r   ru   )r   r    rv   rs   r   r   r   r   rn   r   r^   r;   r   r   r   "test_providing_types_to_init_warns{  s   
z9TestLegacyTypeChecking.test_providing_types_to_init_warnsN)r:   rn   ro   rb   rh   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rp      s    rp   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 )Nr/      rX   )abc)dr   r~      )disallowenumminItemsc                 s   s    | ]}|j V  qd S r%   )rt   rU   r   r   r   r   rW     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   r0   r   sorted)r#   r   r   ZgotZexpectedr   r   r   r4     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   r/      spamr*   r   bazquux
propertiesrS   r_   r   
   r            maximumr   r*   r   r   r   )r1   r   r0   r   r2   )r#   r   r   r3   r   r   r   0test_iter_errors_multiple_failures_one_validator  s   z?TestIterErrors.test_iter_errors_multiple_failures_one_validatorN)r:   rn   ro   r$   r4   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   rt   )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 Nr/   rS   r_   r   r   z1 is not of type %rr   r   r#   rt   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)r_   r^   r/   rS   r   z1 is not of type %r, %r)r   r1   r   )r#   ru   rt   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 )NrS   minimumr   r/   r   1 is less than the minimum of 3r   )r#   rS   rt   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 )NrS   ZFoor   )namer   r/   r   r   r   r#   r   rt   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 )Nr/   r   r   r   z1 is less than the minimum of 2r   r   r   r   r   test_minimum     z(TestValidationErrorMessages.test_minimumc                 C   r   )Nr/   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*   Zdependenciesr   r   r   r   r   z%r is a dependency of %rr   r   r   r   r#   ZdependZonr   rt   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   rw   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itemsZadditionalItemsr   z(2 was unexpected)r   rM   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)r/   r   r   Fr   r   z(1, 2, 3 were unexpected)r   r   r   r   r   &test_additionalItems_multiple_failures  s
   zBTestValidationErrorMessages.test_additionalItems_multiple_failuresc                 C   s4   d}ddi}| j |di|d}| d|f | d S )Nr*   additionalPropertiesFr   r   z(%r was unexpected)r   )r#   
additionalr   rt   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   fromkeysrM   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constr[   r*   r   r   z12 was expectedr   r   Draft6ValidatorrM   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   r[   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   rH   +  s    zQTestValidationErrorMessages.test_invalid_format_default_message.<locals>.<lambda>formatZbla)r   r   format_checkerzis not a)r   checksr   rM   r   )r#   checkerr   rt   r   r   r   #test_invalid_format_default_message)  s   
z?TestValidationErrorMessages.test_invalid_format_default_messagec              
   C   s   ddddiddidd}| j ddi|tjd	}| |d
tdtdtd | j ddd|tjd	}| |dtdtdtdtd d S )Nr^   FrS   r_   )^abc$^def$)rS   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 )Nr5   Fr   z'False schema does not allow 'something')r   r   rw   rM   r   r   r   r   test_False_schemaV  s   z-TestValidationErrorMessages.test_False_schemaN)r:   rn   ro   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      rS   r_   r/   r   r   )r   r   r   )r   r/   rS   )r   r   r1   r0   r   r2   r   r-   r   r   assertIsNoneparentpathr   relative_pathabsolute_pathr.   relative_schema_pathabsolute_schema_pathcontextsorted_errorsassertIsrv   r#   r   r   r   r3   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*   r/   rS   rZ   r^   r   r   rS   r   r   )rS   r   rS   )r/   r   r*   r   )rS   r/   r   r*   r   )r   r   r1   r0   r   r2   r   r-   r   r   r   r   r  r   r  r  r.   r  r  r  r  r  rv   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   r/   r   r   r   r   rS   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   r3   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 )Nr/   r   r   )r*   r   r   r_   r^   r   r   rX   requiredTr   )r   r   r  )rS   r   r   r   )r/   r   r   )r/   r   r   r*   rS   r   )r   r   r   rS   )r   r   r   r   r   r  )r   r   r   r   r   r   )r   r   r*   r   )
r   r   r0   r  r   r  r   r.   r1   r   )r#   r   r   r   r3   r
  r  r  r  Ze5Z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 )NZnoder   r^   r   childrenrS   r_   ^.*$$refz#/definitions/node)rS   r   )r   r  )rS   r  r   root)ZdefinitionsrS   r  r   r   ab)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   r0   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   rZ   r   rS   r   r*   rS   r   r   r   r0   r  r   r  r   r   r#   r   r   r   r3   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 )Nr/   r   r   r   rS   r_   r   r   r   r*   r  r  r   r   r   test_patternProperties  s   


z1TestValidationErrorDetails.test_patternPropertiesc                 C   s   ddg}g dddd}t |}||}t|\}}| |jtdg | |jtdg | |jd | |jd	 d S )
Nr*   r/   rZ   r   r  r   r   rS   r   r  r  r   r   r   test_additionalItems  s   

z/TestValidationErrorDetails.test_additionalItemsc                 C   s   g d}i gdddd}t |}||}t|\}}| |jtdg | |jtdg | |jd | |jd	 d S )
N)r*   r   r/   rZ   r   r  r   r/   r   rS   r   r  r  r   r   r   test_additionalItems_with_items  s   

z:TestValidationErrorDetails.test_additionalItems_with_itemsc                 C   s   ddi}ddddiii}t |}||\}| |jd | |jdddidf  | |jtg  | |jtddg d S )Nr*   r[   ZpropertyNamesnotr   z%r is not allowed for %r	r   rw   r0   r   r   rt   r  r   r.   )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   r[      )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   r[   r%  )r&  elser   r(  )r&  r,  r   r"  r)  r   r   r   test_if_else  r+  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 )NFr[   zFalse schema does not allow 12)r   rw   r0   r   rt   r   r-   r   r   r.   r   )r#   r   r#  r   r   r   test_boolean_schema_False  s$   
	z4TestValidationErrorDetails.test_boolean_schema_Falsec                 C   s   ddddii}}t jd|it jdi ||idd}|d	d
i\}| |j|j|j|j|j	|j
|jfdddd
td	gdditddgf d S )NZsomeRefr   rS   rZ   r  rC   storeresolverr*   ZnotAnIntegerz''notAnInteger' is not of type 'integer')r   rw   RefResolverr0   r   rt   r   r-   r   r  r   r.   r   )r#   refr   r   r#  r   r   r   test_ref-  s0   

z#TestValidationErrorDetails.test_refN)r:   rn   ro   r  r  r  r  r  r  r  r  r   r$  r*  r-  r.  r5  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_schemar^   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
   r8  r!   r9  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!   r9  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   r[   Nr=  r"   r   r   r   !test_enum_allows_non_unique_items^  s   z6MetaSchemaTestsMixin.test_enum_allows_non_unique_itemsN)r:   rn   ro   r:  r<  r>  r?  r   r   r   r   r6  K  s
    r6  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%   )validr`   r!   rx   r#   r   r   r   r   r   test_valid_instances_are_validh     
z1ValidatorTestMixin.test_valid_instances_are_validc                 C   rA  r%   )invalidrv   r!   rx   rC  r   r   r   $test_invalid_instances_are_not_validl  rE  z7ValidatorTestMixin.test_invalid_instances_are_not_validc                 C   s    |  t t ijt d d S )Nr   )r!   r^   r   r"   r   r   r   (test_non_existent_properties_are_ignoredp  s    z;ValidatorTestMixin.test_non_existent_properties_are_ignoredc                 C   s   |  | i jtj d S r%   )ZassertIsInstancer!   r2  r   r3  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 )NZsomeCoolRefrS   rZ   rC   r/  r  r1  )r   r3  r!   r   r
   r   r   )r#   r4  r   r2  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 refrS   rZ   r   )thisr4  r"   r   r   	resolving  s   zbValidatorTestMixin.test_it_delegates_to_a_legacy_ref_resolver.<locals>.LegacyRefResolver.resolvingN)r:   rn   ro   r   rO  r   r"   r   r   LegacyRefResolver  s    rP  r  rL  r1  N)r^   r   r
   r   r!   r   )r#   rP  r2  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*   r_   )r`   r!   rT   r"   r   r   r   #test_is_type_is_true_for_valid_type     z6ValidatorTestMixin.test_is_type_is_true_for_valid_typec                 C   rR  )Nr*   rX   rv   r!   rT   r"   r   r   r   &test_is_type_is_false_for_invalid_type  rT  z9ValidatorTestMixin.test_is_type_is_false_for_invalid_typec                 C   s4   |  | i dd |  | i dd d S )NTrZ   r]   rU  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 )NrS   r_   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*   NrX  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   rS   r]   c                 S   s   t |tttfot |t S r%   )
isinstancerz   floatr   boolr   r   r   r   r   rH     s    
zGValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<lambda>r   r/   g?r   r*   Tc                 S   s   g | ]}|j qS r   rH  )rU   r#  r   r   r   
<listcomp>  s    zIValidatorTestMixin.test_it_can_validate_with_decimals.<locals>.<listcomp>)	r   rf   r!   r(   redefiner   r   r   r0   )r#   r   r!   r   rF  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carrotr   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   re  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*   )Z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   ri  r#   r   r   check  s
   zTValidatorTestMixin.test_it_validates_formats_if_a_checker_is_provided.<locals>.checkr   rd  rh  ri  )r   
ValueErrorr   r!   r   r   r
   r   r  r   cause)r#   r   rl  r   cmr   rk  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 )NrS   c                 S   
   t |tS r%   r\  rz   r_  r   r   r   rH        
 z@ValidatorTestMixin.test_non_string_custom_type.<locals>.<lambda>r`  r   )r^   r   rf   r!   r(   rb  r   )r#   Znon_string_typer   Crazyr   r   r   test_non_string_custom_type  s   
z.ValidatorTestMixin.test_non_string_custom_typec                 C   st   t j| j| jjddd d}| tj}|ddid W d   n1 s*w   Y  | 	d	t
|j dS )
z
        A tuple instance properly formats validation errors for uniqueItems.

        See https://github.com/Julian/jsonschema/pull/224
        rX   c                 S   rq  r%   )r\  tupler_  r   r   r   rH     rs  zNValidatorTestMixin.test_it_properly_formats_tuples_in_errors.<locals>.<lambda>r`  ZuniqueItemsT)r/   r/   Nz(1, 1) has non-unique elements)r   rf   r!   r(   rb  r   r
   r   r   rM   ry   r   )r#   ZTupleValidatorr   r   r   r   )test_it_properly_formats_tuples_in_errors  s   z<ValidatorTestMixin.test_it_properly_formats_tuples_in_errorsN)r:   rn   ro   rD  rG  rI  rJ  rK  rQ  rS  rV  rW  unittestZskipIfr   rY  r[  rc  rf  rg  rp  ru  rw  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
   r8  r!   r9  rM   ry   r   r   r   r   r   test_True_is_not_a_schema     z-AntiDraft6LeakMixin.test_True_is_not_a_schemac                 C   rz  )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 )NrC   Tr1  r[   
r   r3  r   	Exceptionr!   r   ZassertNotIsInstancer   r
   r   r#   r2  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  )NrC   Fr1  r[   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:   rn   ro   __doc__r|  r~  rx  skipr   r  r  r   r   r   r   ry    s    
ry  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 )TestDraft3ValidatorrS   rZ   r*   c                 C   s   |  ddi}|t  d S NrS   any)r!   r   r^   re  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   rq  r%   rr  r_  r   r   r   rH   *  rs  zBTestDraft3Validator.test_any_type_is_redefinable.<locals>.<lambda>r`  rS   r[   r*   N)	r   rf   r!   r(   rb  r   r   r
   r   )r#   rt  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  )r`   r!   rx   r^   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 )NTrY   rS   r  )r`   r!   rT   rx   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:   rn   ro   r   r   r!   rB  rF  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 )TestDraft4ValidatorrS   rZ   r*   N)r:   rn   ro   r   r   r!   rB  rF  r   r   r   r   r  :      r  c                   @   r  )TestDraft6ValidatorrS   rZ   r*   N)r:   rn   ro   r   r   r!   rB  rF  r   r   r   r   r  @  r  r  c                   @   r  )TestDraft7ValidatorrS   rZ   r*   N)r:   rn   ro   r   rw   r!   rB  rF  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  rw   r+   r   r   r   test_draft_7t  r  zTestValidatorFor.test_draft_7c                 C      |  tdtj d S )NTr  r   r  Z_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 )Nr=   r@   Z12c                 S   rA   rB   rD   rF   r   r   r   rH     rI   z8TestValidatorFor.test_custom_validator.<locals>.<lambda>rJ   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   rP   Z13r7   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 )NzThe metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future.r  ZunknownSchema)r|   rt   r}   r~   r   r  )r   r   r   r   rn   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  rv   rs   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:   rn   ro   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 )Nr9  )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   rw   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  rl   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 )Nr[   rS   r_   z3(?s)Failed validating u?'.*' in schema.*On instance)r   r
   r   r   r   assertRegexpMatchesry   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 )Nr[   rS   z5(?s)Failed validating u?'.*' in metaschema.*On schema)r   r
   r8  r   r   r  ry   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 )NZoneOfrS   r_   rX   r[   z12 is not of type)r   r
   r   r   r   rM   ry   r   )r#   r   r   r   r   r   test_it_uses_best_match  s
   z$TestValidate.test_it_uses_best_matchN)r:   rn   ro   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 )$TestRefResolverrC   zfoo://storedZstoredr   c                 C   s.   i | _ | j| ji| _t| j| j | j| _d S r%   )referrer
stored_uristored_schemar0  r   r3  base_urir2  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 )Nr=   Zresolve_remotec                     s
     dS )NzShould not have been called!)rj  )r   r   r"   r   r   rH     rs  zXTestRefResolver.test_it_does_not_retrieve_schema_urls_from_the_network.<locals>.<lambda>)r   r   r'   r  r2  rO  r   r#   r4  resolvedr   r"   r   6test_it_does_not_retrieve_schema_urls_from_the_network  s   
zFTestRefResolver.test_it_does_not_retrieve_schema_urls_from_the_networkc                 C   s\   d}dt  i| jd< | j|}| || jd d  W d    d S 1 s'w   Y  d S )Nz#/properties/foor*   r   )r^   r  r2  rO  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   )r=   r   c                 S   rA   rB   rD   rk   r   r   r   rH   /  rI   zETestRefResolver.test_it_resolves_local_refs_with_id.<locals>.<lambda>rK   z#/ar   zhttp://bar/schema#/a)r   r3  from_schemarO  r   r#   r   r2  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*   r[   Z
cached_refzcached_ref#/foo)r2  rO  r  r  r  r0  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   r[   requests
http://bar)r   r   r   __setitem__ReallyFakeRequestsr2  rO  r   )r#   r4  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   r[   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  r2  rO  r   )r#   r4  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 )NFZwt)deletemoder*   r   zfile://{}#foo)tempfileZNamedTemporaryFiler   osremover   r  dumpr   r   r2  rO  r   )r#   Ztempfr4  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 sw   Y  d S )	Nr=   r*   c                 S   rA   rB   rD   rk   r   r   r   rH   n  rI   zPTestRefResolver.test_it_can_construct_a_base_uri_from_a_schema.<locals>.<lambda>r  rC   #zfoo#r   r3  r  r   r  Zresolution_scoperO  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 )NrC   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%   rM  r  r4  r   r#   r   r   handler  s   z@TestRefResolver.test_custom_uri_scheme_handlers.<locals>.handlerr*   r   	foo://barrC   handlers)r   r3  rO  r   )r#   r  r2  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!r9   
IndexErrorrj  r  responser#   r   r   r    
   
z5TestRefResolver.test_cache_remote_on.<locals>.handlerr  rC   Tr*   Zcache_remoter  r^   r   r3  rO  r#   r  r4  r2  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  rC   Fr*   r  r  r  r   r  r   test_cache_remote_off  s   "z%TestRefResolver.test_cache_remote_offc              	      s   t d  fdd}d}tjdi d|id}| tj"}|| | d W d    n1 s2w   Y  W d    n1 sAw   Y  | |j	t  d S )	NzOh no! What's this?c                    s    r%   r   r  r#  r   r   r    s   zTTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_error.<locals>.handlerr  rC   r*   r  zShouldn't get this far!)
rm  r   r3  r   r
   RefResolutionErrorrO  rj  r   r   )r#   r  r4  r2  errr   r  r   3test_if_you_give_it_junk_you_get_a_resolution_error  s   zCTestRefResolver.test_if_you_give_it_junk_you_get_a_resolution_errorc                 C   s^   t di }|  | tj}|  W d    n1 sw   Y  | dt|j d S )NrC   zFailed to pop the scope)	r   r3  Z	pop_scoper   r
   r  rM   ry   r   )r#   r2  excr   r   r   .test_helpful_error_message_on_failed_pop_scope  s   
z>TestRefResolver.test_helpful_error_message_on_failed_pop_scopeN)r:   rn   ro   r  r  r  r$   r  r  r  r  r  r  r  r  r  r  r  r   r  r  r   r   r   r   r    s&    	
r  c                 C   s   dd }t | |dS )Nc                 S   s    dd | j D dd | jD fS )Nc                 S      g | ]}t |qS r   ry   r   r   r   r   ra        z.sorted_errors.<locals>.key.<locals>.<listcomp>c                 S   r  r   r  r   r   r   r   ra    r	  )r  r.   r  r   r   r   key  s   zsorted_errors.<locals>.key)r
  )r   )r3   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: )
_responsesrE   rm  r   _ReallyFakeJSONResponser  r  )r#   r  r  r   r   r   rE     s   zReallyFakeRequests.getN)r:   rn   ro   attribr  rE   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:   rn   ro   r  r  r  r  r   r   r   r   r    r  r  )0collectionsr   
contextlibr   Zdecimalr   ior   rx  r   r  r  r   r  Ztwisted.trial.unittestr   r  Z
jsonschemar   r	   r
   r   Zjsonschema.compatr   r   Zjsonschema.tests._helpersr   r   r   rp   r   r   r   r^   r6  r@  ry  r  r  r  r  r  r  r  r  rG   r  r  r   r   r   r   <module>   sX      ]" /   o  sN ;	