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   zCannot 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 )NzThe 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 sw   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 ;	