U
    kuf                     @   sZ   d dl mZ d dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
mZ G dd dZdS )    )	lru_cacheN)RegistryResource
exceptions)DRAFT202012)to_cached_resourcec                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestToCachedResourcec                    sp   ddi}t |g t  fdd}t|d}t|}|d}|j|ksRt|d}|j|jksltd S )N$schema,https://json-schema.org/draft/2020-12/schemac                    s      S Npopuristack D/tmp/pip-unpacked-wheel-g5oy8ly_/referencing/tests/test_retrieval.pyretrieve   s    zITestToCachedResource.test_it_caches_retrieved_resources.<locals>.retriever   urn:example:schema	jsondumpsr   r   r   from_contentsget_or_retrievevalueAssertionErrorselfcontentsr   registryexpectedgotZagainr   r   r   "test_it_caches_retrieved_resources   s    



z7TestToCachedResource.test_it_caches_retrieved_resourcesc                    s   ddi}t |d d d g tdd d fdd}t|d	}t|}|d
}|j|ksdt|d
}|j|jks~td S )Nr	   r
   c                 S   s   t | d d d S )Nr%   )r   loads)sr   r   r   <lambda>#       z9TestToCachedResource.test_custom_loader.<locals>.<lambda>)r&   c                    s      S r   r   r   r   r   r   r   #   s    z9TestToCachedResource.test_custom_loader.<locals>.retriever   r   r   r   r   r   r   test_custom_loader   s    



z'TestToCachedResource.test_custom_loaderc                    sr   i }t |g ttjd fdd}t|d}t|}|d}|j|ksTt|d}|j|jksntd S )N)r   c                    s      S r   r   r   r   r   r   r   6   s    z@TestToCachedResource.test_custom_from_contents.<locals>.retriever   r   )	r   r   r   r   Zcreate_resourcer   r   r   r   r   r   r   r   test_custom_from_contents2   s    




z.TestToCachedResource.test_custom_from_contentsc              	      sh  ddi}t |ddt |ddt |ddd dd	   D }ttdd
d fdd}t|d}|d}|j|d kst|dj|jkst|dj|jkst|d}|j|d kst|dj|jkst|dj|jkst|d}|j|d kst|dj|jks*t|dj|jksBtt	t
j |d W 5 Q R X d S )Nr	   r
      )Zfoo      )urn:example:1urn:example:2urn:example:3c                 S   s   i | ]\}}|t |qS r   )r   r   ).0r   r    r   r   r   
<dictcomp>M   s    z:TestToCachedResource.test_custom_cache.<locals>.<dictcomp>)maxsize)cachec                    s   t  | S r   )r   r   r   r   mappingr   r   r   R   s    z8TestToCachedResource.test_custom_cache.<locals>.retriever   r/   r0   r1   )dictitemsr   r   r   r   r   r   pytestZraisesr   ZUnretrievable)r   Zschema	resourcesr   r!   r#   r   r6   r   test_custom_cacheE   s2    






z&TestToCachedResource.test_custom_cacheN)__name__
__module____qualname__r$   r*   r+   r<   r   r   r   r   r      s   r   )	functoolsr   r   r:   Zreferencingr   r   r   Zreferencing.jsonschemar   Zreferencing.retrievalr   r   r   r   r   r   <module>   s   