U
    kuf-                  
   @   st  d dl Z d dlmZmZmZ d dlZe jddejj	fdejj
fdejjfdejjfdejjfd	ejjfgd
d Zdd Ze jddejj	fdejj
fdejjfdejjfdejjfdejjfgdd Ze jdejj	ejj
ejjejjge jdddgdd Ze jdejj	ejj
ejjejjge jdddgdd Ze jdejj	ejj
ejjejjge jdddgdd Ze jddejj	fdejj
fdejjfdejjfdejjfd	ejjfgdd Ze jddejjfd ejjfd!ejjfd"ejjfgd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z dS )9    N)RegistryResourceSpecificationzuri, expectedz,https://json-schema.org/draft/2020-12/schemaz,https://json-schema.org/draft/2019-09/schemaz'http://json-schema.org/draft-07/schema#z'http://json-schema.org/draft-06/schema#z'http://json-schema.org/draft-04/schema#z'http://json-schema.org/draft-03/schema#c                 C   s*   d| i}t |}|t ||dks&tdS )zE
    The $schema keyword in JSON Schema is a dialect identifier.
    $schema)contentsspecificationN)r   from_contentsAssertionError)uriexpectedr   resource r   E/tmp/pip-unpacked-wheel-g5oy8ly_/referencing/tests/test_jsonschema.py7test_schemas_with_explicit_schema_keywords_are_detected   s    !
r   c               	   C   s@   d} t tjj}td| i W 5 Q R X |jj| ks<t	d S )N1http://example.com/unknown-json-schema-dialect-idr   )
pytestraisesreferencing
jsonschemaUnknownDialectr   r   valuer
   r	   
dialect_idexcinfor   r   r   test_unknown_dialect-   s    r   zid, specification$ididc                 C   s   d}| | |i|kstd S )Nzhttp://example.com/some-schemaZid_ofr	   )r   r   r
   r   r   r   test_id_of_mapping4   s    r   r   r   TFc                 C   s   |  |d kstd S Nr   r   r   r   r   r   test_id_of_boolD   s    r!   c                 C   s   t | |g kstd S r   )listZ
anchors_inr	   r    r   r   r   test_anchors_in_boolR   s    r#   c                 C   s   t | |g kstd S r   )r"   Zsubresources_ofr	   r    r   r   r   test_subresources_of_bool`   s    r$   c                 C   s   t j| |kstd S r   r   r   specification_withr	   r
   r   r   r   r   test_specification_withn   s    r(   z&http://json-schema.org/draft-07/schemaz&http://json-schema.org/draft-06/schemaz&http://json-schema.org/draft-04/schemaz&http://json-schema.org/draft-03/schemac                 C   s   t j| |kstd S r   r%   r'   r   r   r   )test_specification_with_no_empty_fragment   s    r)   c               	   C   s>   d} t tjj}tj|  W 5 Q R X |jj| ks:td S )Nr   )	r   r   r   r   r   r&   r   r
   r	   r   r   r   r   'test_specification_with_unknown_dialect   s    r*   c                  C   s(   d} t jj| tjd}|tjks$td S )Nr   )default)r   r   r&   r   ZOPAQUEr	   )r   r   r   r   r   test_specification_with_default   s    r,   c                  C   sB   t jjddi} t d|  }|d}|j| jks>t	d S )N$dynamicAnchorfoohttp://example.comzhttp://example.com#foo)
r   r   DRAFT202012create_resourcer   with_resourceresolverlookupr   r	   )oner3   resolvedr   r   r   test_lookup_trivial_dynamic_ref   s    
r7   c               
   C   s   t jjd} t jjddddddddiddid}t d|fd| fd	|fg }|d}|jd
}|jdj}|d}|j|jkst	d S )NTr/   	fooAnchorr.   r-   barZbazr   r-   $defshttp://example.com/foo/http://example.com/foo/barfoo/r:   
#fooAnchor
r   r   r0   r1   r   with_resourcesr3   r4   r   r	   TRUErootr3   firstsecondfourthr   r   r   (test_multiple_lookup_trivial_dynamic_ref   s8     

rI   c               
   C   s   t jjddi} t jjddddddddiddid}t d|fd	| fd
|fg }|d}|jd}|jdj}|d}|j|jkst	d S )N$anchorr8   r/   r.   Tr-   r9   r;   r=   r>   r?   r:   r@   rA   )r5   twor3   rF   rG   rH   r   r   r   2test_multiple_lookup_dynamic_ref_to_nondynamic_ref   s<     

rL   c                  C   sR   t jjddi} t d|  }|d}t jj|jd}|j	| j	ksNt
d S )N$recursiveAnchorTr/   r3   )r   r   DRAFT201909r1   r   r2   r3   r4   lookup_recursive_refr   r	   )r5   r3   rF   r6   r   r   r   !test_lookup_trivial_recursive_ref  s    
rQ   c                  C   sD   t jjd} td| i}t jj|jddd}|j| jks@td S )NTr/   )Zbase_urirN   )	r   r   rO   r1   r   rP   r3   r   r	   )rD   registryr6   r   r   r   !test_lookup_recursive_ref_to_bool  s    
rS   c                  C   s   t jjd} t jjdddddddddddid}t d|fd| fd	|fg }|d}|jd
}|jdj}t jj|d}|j	|j	kst
d S )NTr/   r.   r8   rM   rJ   r9   r   rM   r<   r=   r>   r?   r:   rN   r   r   rO   r1   r   rB   r3   r4   rP   r   r	   rC   r   r   r   *test_multiple_lookup_recursive_ref_to_bool(  s8    
rW   c                  C   s   t jjddi} t jjdddddddddddid}t jjdd	i}t d|fd
|fd| fg }|d}|jd}|jdj}t jj|d}|j	|j	kst
d S )NrM   Tr/   r.   r8   rT   r9   rU   Fr=   r>   r?   r:   rN   rV   )r5   rK   Zthreer3   rF   rG   rH   r   r   r   8test_multiple_lookup_recursive_ref_with_nonrecursive_refP  sB    
rX   c                   C   s   t jjt kstd S r   )r   r   ZEMPTY_REGISTRYr   r	   r   r   r   r   test_empty_registry}  s    rY   )!r   r   r   r   r   Zreferencing.jsonschemamarkZparametrizer   r0   rO   ZDRAFT7ZDRAFT6ZDRAFT4ZDRAFT3r   r   r   r!   r#   r$   r(   r)   r*   r,   r7   rI   rL   rQ   rS   rW   rX   rY   r   r   r   r   <module>   s   
	






			

	')	(-